From da03040b701de1fabe9084b71e7016f5d93831f2 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 16 Sep 2020 14:42:44 +0200 Subject: [PATCH] Internal - Add work behat test, fix queries --- .travis.yml | 2 +- public/main/inc/lib/groupmanager.lib.php | 5 +-- public/main/work/upload.php | 2 +- public/main/work/work.lib.php | 15 ++----- src/CoreBundle/Framework/Container.php | 45 ++++--------------- .../features/bootstrap/FeatureContext.php | 2 +- tests/behat/features/sessionAccess.feature | 2 + tests/behat/features/toolAgenda.feature | 2 + tests/behat/features/toolGroup.feature | 5 +++ tests/behat/features/toolWork.feature | 22 ++++----- 10 files changed, 38 insertions(+), 64 deletions(-) diff --git a/.travis.yml b/.travis.yml index 80bcf8074a..8120e6a3a6 100755 --- a/.travis.yml +++ b/.travis.yml @@ -133,7 +133,7 @@ script: - ../../vendor/behat/behat/bin/behat features/toolGroup.feature -vvv - ../../vendor/behat/behat/bin/behat features/toolLink.feature -v # - ../../vendor/behat/behat/bin/behat features/toolLp.feature -v -# - ../../vendor/behat/behat/bin/behat features/toolWork.feature -v + - ../../vendor/behat/behat/bin/behat features/toolWork.feature -v after_failure: - sudo cat /var/log/apache2/error.log diff --git a/public/main/inc/lib/groupmanager.lib.php b/public/main/inc/lib/groupmanager.lib.php index 7443e3167f..789a4b98ad 100644 --- a/public/main/inc/lib/groupmanager.lib.php +++ b/public/main/inc/lib/groupmanager.lib.php @@ -2292,11 +2292,10 @@ class GroupManager $sql = "SELECT DISTINCT g.* FROM $table_group g LEFT JOIN $table_group_user gu - ON (gu.group_id = g.iid AND g.c_id = gu.c_id) + ON (gu.group_id = g.iid) LEFT JOIN $table_tutor_user tu - ON (tu.group_id = g.iid AND g.c_id = tu.c_id) + ON (tu.group_id = g.iid) WHERE - g.c_id = $courseId AND (gu.user_id = $user_id OR tu.user_id = $user_id) "; if (null !== $sessionId) { diff --git a/public/main/work/upload.php b/public/main/work/upload.php index 4456ccc8a8..3b1933a6c7 100644 --- a/public/main/work/upload.php +++ b/public/main/work/upload.php @@ -54,7 +54,7 @@ if ($onlyOnePublication) { } } -$homework = get_work_assignment_by_id($workInfo['id']); +$homework = get_work_assignment_by_id($workInfo['iid']); $validationStatus = getWorkDateValidationStatus($homework); $interbreadcrumb[] = [ diff --git a/public/main/work/work.lib.php b/public/main/work/work.lib.php index e97ee2a87e..aee18f55f1 100644 --- a/public/main/work/work.lib.php +++ b/public/main/work/work.lib.php @@ -867,11 +867,11 @@ function deleteDirWork($id) // Deleting all contents inside the folder $sql = "UPDATE $table SET active = 2 - WHERE c_id = $course_id AND filetype = 'folder' AND id = $id"; + WHERE filetype = 'folder' AND iid = $id"; Database::query($sql); $sql = "UPDATE $table SET active = 2 - WHERE c_id = $course_id AND parent_id = $id"; + WHERE parent_id = $id"; Database::query($sql); /*$new_dir = $work_data_url.'_DELETED_'.$id; @@ -988,7 +988,7 @@ function updateWorkUrl($id, $new_path, $parent_id) $sql = "UPDATE $table SET url = '$new_url', parent_id = '$parent_id' - WHERE c_id = $course_id AND id = $id"; + WHERE iid = $id"; return Database::query($sql); } @@ -1021,7 +1021,6 @@ function updateDirName($work_data, $newPath) $sql = "UPDATE $table SET title = '".$originalNewPath."' WHERE - c_id = $course_id AND iid = $work_id"; Database::query($sql); } @@ -4721,15 +4720,10 @@ function updatePublicationAssignment($workId, $params, $courseInfo, $groupId) $my_last_id = Database::insert_id(); if ($my_last_id) { - $sql = "UPDATE $table SET - id = iid - WHERE iid = $my_last_id"; - Database::query($sql); - $sql = "UPDATE $workTable SET has_properties = $my_last_id, view_properties = 1 - WHERE c_id = $course_id AND id = $workId"; + WHERE iid = $workId"; Database::query($sql); } } else { @@ -4740,7 +4734,6 @@ function updatePublicationAssignment($workId, $params, $courseInfo, $groupId) enable_qualification = '".$qualification."' WHERE publication_id = $workId AND - c_id = $course_id AND iid = ".$data['iid']; Database::query($sql); } diff --git a/src/CoreBundle/Framework/Container.php b/src/CoreBundle/Framework/Container.php index cc43fe80d9..ffa7b18124 100644 --- a/src/CoreBundle/Framework/Container.php +++ b/src/CoreBundle/Framework/Container.php @@ -257,23 +257,12 @@ class Container return self::$container->get('Symfony\Component\Mailer\Mailer'); } - /** - * @return SettingsManager - */ - public static function getSettingsManager() + public static function getSettingsManager(): SettingsManager { return self::$container->get('chamilo.settings.manager'); } - /*public static function setSettingsManager($manager) - { - self::$settingsManager = $manager; - }*/ - - /** - * @return \Chamilo\CourseBundle\Manager\SettingsManager - */ - public static function getCourseSettingsManager() + public static function getCourseSettingsManager(): \Chamilo\CourseBundle\Manager\SettingsManager { return self::$container->get('Chamilo\CourseBundle\Manager\SettingsManager'); } @@ -291,50 +280,32 @@ class Container return self::$container->get(UserRepository::class); } - /** - * @return CAttendanceRepository - */ - public static function getAttendanceRepository() + public static function getAttendanceRepository(): CAttendanceRepository { return self::$container->get(CAttendanceRepository::class); } - /** - * @return CAnnouncementRepository - */ - public static function getAnnouncementRepository() + public static function getAnnouncementRepository(): CAnnouncementRepository { return self::$container->get(CAnnouncementRepository::class); } - /** - * @return AccessUrlRepository - */ - public static function getAccessUrlRepository() + public static function getAccessUrlRepository(): AccessUrlRepository { return self::$container->get(AccessUrlRepository::class); } - /** - * @return CAnnouncementAttachmentRepository - */ - public static function getAnnouncementAttachmentRepository() + public static function getAnnouncementAttachmentRepository(): CAnnouncementAttachmentRepository { return self::$container->get(CAnnouncementAttachmentRepository::class); } - /** - * @return CourseRepository - */ - public static function getCourseRepository() + public static function getCourseRepository(): CourseRepository { return self::$container->get(CourseRepository::class); } - /** - * @return SessionRepository - */ - public static function getSessionRepository() + public static function getSessionRepository(): SessionRepository { return self::$container->get(SessionRepository::class); } diff --git a/tests/behat/features/bootstrap/FeatureContext.php b/tests/behat/features/bootstrap/FeatureContext.php index 72d133eafd..7c72a67f37 100644 --- a/tests/behat/features/bootstrap/FeatureContext.php +++ b/tests/behat/features/bootstrap/FeatureContext.php @@ -414,7 +414,7 @@ class FeatureContext extends MinkContext } /** - * @When /^wait for the page to be loaded$/ + * @When /^(?:|I )wait for the page to be loaded$/ */ public function waitForThePageToBeLoaded() { diff --git a/tests/behat/features/sessionAccess.feature b/tests/behat/features/sessionAccess.feature index 27929d059e..641a2abcfa 100644 --- a/tests/behat/features/sessionAccess.feature +++ b/tests/behat/features/sessionAccess.feature @@ -14,6 +14,7 @@ Feature: Session access Then I select "TEMP_PRIVATE (TEMPPRIVATE)" from "NoSessionCoursesList[]" And I press "add_course" And I press "next" + And wait the page to be loaded when ready Then I should see "Update successful" Then I should see "Subscribe users to this session" Then I follow "Multiple registration" @@ -37,6 +38,7 @@ Feature: Session access Then I select "TEMP_PRIVATE (TEMPPRIVATE)" from "NoSessionCoursesList[]" And I press "add_course" And I press "next" + And wait the page to be loaded when ready Then I should see "Update successful" Then I should see "Subscribe users to this session" Then I follow "Multiple registration" diff --git a/tests/behat/features/toolAgenda.feature b/tests/behat/features/toolAgenda.feature index 836aed615f..a4c6050bce 100644 --- a/tests/behat/features/toolAgenda.feature +++ b/tests/behat/features/toolAgenda.feature @@ -14,6 +14,7 @@ Feature: Agenda tool And I focus "date_range" And I fill in "date_range" with "2017-03-07 12:15 / 2017-03-07 12:15" And I press "Add event" + And wait the page to be loaded when ready Then I should see "Event added" Scenario: Create an event inside course TEMP @@ -26,6 +27,7 @@ Feature: Agenda tool And I focus "date_range" And I fill in "date_range" with "2017-03-07 12:15 / 2017-03-07 12:15" And I press "Add event" + And wait the page to be loaded when ready Then I should see "Event added" diff --git a/tests/behat/features/toolGroup.feature b/tests/behat/features/toolGroup.feature index 8c1853e6d0..118353429c 100644 --- a/tests/behat/features/toolGroup.feature +++ b/tests/behat/features/toolGroup.feature @@ -11,6 +11,7 @@ Feature: Group tool Then I should see "Default groups" Then I follow "Delete" Then I confirm the popup + And wait the page to be loaded when ready Then I should see "The category has been deleted" Scenario: Create a group directory @@ -19,6 +20,7 @@ Feature: Group tool When I fill in the following: | title | Group category 1 | And I press "group_category_submit" + And wait the page to be loaded when ready Then I should see "Category created" Scenario: Create 4 groups @@ -39,6 +41,7 @@ Feature: Group tool And I fill in select bootstrap static by text "#category_3" select "Group category 1" And I fill in select bootstrap static by text "#category_4" select "Group category 1" And I press "submit" + And wait the page to be loaded when ready Then I should see "group(s) has (have) been added" Scenario: Create document folder in group @@ -52,6 +55,7 @@ Feature: Group tool Then I fill in the following: | dirname | My folder in group | And I press "create_dir_form_submit" + And wait the page to be loaded when ready Then I should see "Folder created" Scenario: Create document inside folder in group @@ -67,6 +71,7 @@ Feature: Group tool | title | html test | And I fill in ckeditor field "content" with "My first HTML!!" Then I press "create_document_submit" + And wait the page to be loaded when ready Then I should see "Item added" Scenario: Upload a document inside folder in group diff --git a/tests/behat/features/toolWork.feature b/tests/behat/features/toolWork.feature index c6fcfc7e8a..3390b29549 100644 --- a/tests/behat/features/toolWork.feature +++ b/tests/behat/features/toolWork.feature @@ -2,27 +2,29 @@ Feature: Work tool In order to use the work tool The teachers should be able to create works - Scenario: Create a work - Given I am a platform administrator - And I am on course "TEMP" homepage - And I am on "/main/work/work.php?action=create_dir&cid=1" - When I fill in the following: - | new_dir | Work 1 | - And I fill in ckeditor field "description" with "Work description" - And I press "submit" - Then I should see "Directory created" +# Scenario: Create a work +# Given I am a platform administrator +# And I am on course "TEMP" homepage +# And I am on "/main/work/work.php?action=create_dir&cid=1" +# When I fill in the following: +# | new_dir | Work 1 | +# And I fill in ckeditor field "description" with "Work description" +# And I press "submit" +# And I wait for the page to be loaded +# Then I should see "Directory created" Scenario: Edit a work Given I am a platform administrator And I am on course "TEMP" homepage And I am on "/main/work/work.php?cid=1" - And wait for the page to be loaded + And wait very long for the page to be loaded And I follow "Work 1" Then I should see "Work description" Then I follow "Edit" Then I should see "Assignment name" And wait for the page to be loaded And I press "Validate" + And I wait for the page to be loaded Then I should see "Update successful" Scenario: Send work as student