Browse Source

Add behat announcement tests

Julio Montoya 5 years ago
parent
commit
436571f43d

+ 2 - 2
main/group/group.php

@@ -44,7 +44,7 @@ $nameTools = get_lang('GroupManagement');
 /*
  * Self-registration and un-registration
  */
-$my_group_id = isset($_GET['group_id']) ? intval($_GET['group_id']) : null;
+$my_group_id = isset($_GET['group_id']) ? (int) $_GET['group_id'] : null;
 $my_group = isset($_REQUEST['group']) ? Security::remove_XSS($_REQUEST['group']) : null;
 $my_get_id1 = isset($_GET['id1']) ? Security::remove_XSS($_GET['id1']) : null;
 $my_get_id2 = isset($_GET['id2']) ? Security::remove_XSS($_GET['id2']) : null;
@@ -246,7 +246,7 @@ if (api_get_setting('allow_group_categories') === 'true') {
         if (api_is_allowed_to_edit(false, true) && !empty($categoryId) && empty($sessionId)) {
             // Edit
             $actions .= '<a href="group_category.php?'.api_get_cidreq().'&id='.$categoryId.'" title="'.get_lang('Edit').'">'.
-                Display::return_icon('edit.png', get_lang('EditGroup'), '', ICON_SIZE_SMALL).'</a>';
+                Display::return_icon('edit.png', get_lang('EditCategory'), '', ICON_SIZE_SMALL).'</a>';
 
             // Delete
             $actions .= Display::url(

+ 4 - 4
main/group/group_category.php

@@ -53,10 +53,10 @@ function check_max_number_of_members($value)
  */
 function check_groups_per_user($value)
 {
-    $groups_per_user = $value['groups_per_user'];
+    $groups_per_user = (int) $value['groups_per_user'];
     if (isset($_POST['id']) &&
-        intval($groups_per_user) != GroupManager::GROUP_PER_MEMBER_NO_LIMIT &&
-        GroupManager::get_current_max_groups_per_user($_POST['id']) > intval($groups_per_user)) {
+        $groups_per_user != GroupManager::GROUP_PER_MEMBER_NO_LIMIT &&
+        GroupManager::get_current_max_groups_per_user($_POST['id']) > $groups_per_user) {
         return false;
     }
 
@@ -128,7 +128,7 @@ for ($i = 1; $i <= 10; $i++) {
 }
 $possible_values[GroupManager::GROUP_PER_MEMBER_NO_LIMIT] = get_lang('All');
 $group = [
-    $form->createElement('select', 'groups_per_user', null, $possible_values),
+    $form->createElement('select', 'groups_per_user', null, $possible_values, ['id' => 'groups_per_user']),
     $form->createElement('static', null, null, get_lang('QtyOfUserCanSubscribe_PartAfterNumber')),
 ];
 $form->addGroup($group, 'limit_group', get_lang('QtyOfUserCanSubscribe_PartBeforeNumber'), null, false);

+ 2 - 0
main/group/member_settings.php

@@ -209,6 +209,8 @@ if ($form->validate()) {
 
     // Returning to the group area (note: this is inconsistent with the rest of chamilo)
     $cat = GroupManager::get_category_from_group($current_group['iid']);
+    $max_member = $current_group['max_student'];
+
     if (isset($_POST['group_members']) &&
         count($_POST['group_members']) > $max_member &&
         $max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT

+ 2 - 2
main/inc/lib/groupmanager.lib.php

@@ -1814,11 +1814,11 @@ class GroupManager
         $course_id = empty($course_id) ? api_get_course_int_id() : (int) $course_id;
         $group_id = $groupInfo['id'];
 
-        $table = Database::get_course_table(TABLE_GROUP_USER);
         if (!empty($user_ids)) {
+            $table = Database::get_course_table(TABLE_GROUP_USER);
             foreach ($user_ids as $user_id) {
                 if (self::canUserSubscribe($user_id, $groupInfo)) {
-                    $user_id = intval($user_id);
+                    $user_id = (int) $user_id;
                     $sql = "INSERT INTO ".$table." (c_id, user_id, group_id)
                             VALUES ('$course_id', '".$user_id."', '".$group_id."')";
                     Database::query($sql);

+ 35 - 20
tests/behat/features/toolGroup.feature

@@ -127,6 +127,30 @@ Feature: Group tool
     Then I follow "Group 0001"
     Then I should see "Fiona"
 
+  Scenario: Add fapple to the Group 0003 not allowed because group category allows 1 user per group
+    Given I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
+    And I follow "Group 0003"
+    Then I should see "Group 0003"
+    Then I follow "Edit this group"
+    Then I should see "Group members"
+    Then wait for the page to be loaded
+    Then I follow "group_members_tab"
+    Then I select "Fiona Apple Maggart (fapple)" from "group_members"
+    Then I press "group_members_rightSelected"
+    Then I press "Save settings"
+    And wait for the page to be loaded
+    Then I should see "Group settings modified"
+    Then I follow "Group 0003"
+    Then I should not see "Fiona"
+
+  Scenario: Change Group category to allow multiple inscription of the user
+    Given I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
+    And I follow "Edit this category"
+    Then I should see "Edit group category: Group category 1"
+    Then I fill in select bootstrap static by text "#groups_per_user" select "10"
+    Then I press "Edit"
+    Then I should see "Group settings have been modified"
+
   Scenario: Add fapple to the Group 0003
     Given I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
     And I follow "Group 0003"
@@ -237,7 +261,7 @@ Feature: Group tool
     Then I press "submit"
     Then I should see "Announcement has been added"
 
-  Scenario: Check fapple access of announcements Group 0001 (fapple group)
+  Scenario: Check fapple/acostea access of announcements
     Given I am logged as "fapple"
     And I am on course "TEMP" homepage
     And I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
@@ -249,15 +273,13 @@ Feature: Group tool
     Then I should see "Announcement for user fapple inside Group 0001"
     Then I follow "Announcement for user fapple inside Group 0001 Group"
     Then I should see "Announcement description for user fapple inside Group 0001"
+    Then I save current URL with name "announcement_for_user_fapple_group_0001_public"
     Then I move backward one page
     Then wait for the page to be loaded
     Then I should see "Announcement for all users inside Group 0001"
     Then I follow "Announcement for all users inside Group 0001"
+    Then I save current URL with name "announcement_for_all_users_group_0001_public"
     Then I should see "Announcement description in Group 0001"
-
-  Scenario: Check fapple/acostea access of announcements
-    Given I am logged as "fapple"
-    And I am on course "TEMP" homepage
     And I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
     And I follow "Group 0003"
     Then I should see "Group 0003"
@@ -282,20 +304,13 @@ Feature: Group tool
     And I should see "Group 0002"
     And I should see "Group 0003"
     And I should see "Group 0004"
-    And I follow "Group 0001"
-    Then I should see "Group 0001"
-    Then I follow "Announcements"
-    And wait for the page to be loaded
-    Then I should see "Announcement for all users inside Group 0001"
-    Then I should not see "Announcement for user fapple inside Group 0001"
-    Then I follow "Announcement for all users inside Group 0001"
-    Then I should see "Announcement description in Group 0001"
-    Given I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
-    And I should see "Group 0003"
-    And I follow "Group 0003"
-    Then I should see "Group 0003"
-    Then I should not see "Announcements"
-    Then I visit URL saved with name "announcement_for_user_fapple_group_0003_private"
+
+    Then I visit URL saved with name "announcement_for_user_fapple_group_0001_public"
     Then I should see "Sorry, you are not allowed to access this page"
-    Then I visit URL saved with name "announcement_for_all_users_group_0003_private"
+    Then I visit URL saved with name "announcement_for_all_users_group_0001_public"
     Then I should see "Sorry, you are not allowed to access this page"
+
+    And I am on "/main/group/group.php?cidReq=TEMP&id_session=0"
+    And I should see "Group 0002"
+    And I follow "Group 0002"
+    Then I follow "Announcements"