Internal - Fix group behat tests

pull/3464/head
Julio Montoya 4 years ago
parent e2dad135f3
commit 58acb18710
  1. 4
      public/main/inc/lib/api.lib.php
  2. 10
      public/main/inc/lib/course.lib.php
  3. 13
      public/main/inc/lib/groupmanager.lib.php
  4. 28
      public/main/user/user.php
  5. 12
      tests/behat/features/toolGroup.feature

@ -7657,10 +7657,6 @@ function api_can_login_as($loginAsUserId, $userId = null)
return false; return false;
} }
if (empty($loginAsUserId)) {
return false;
}
// Check if the user to login is an admin // Check if the user to login is an admin
if (api_is_platform_admin_by_id($loginAsUserId)) { if (api_is_platform_admin_by_id($loginAsUserId)) {
// Only super admins can login to admin accounts // Only super admins can login to admin accounts

@ -6185,7 +6185,8 @@ class CourseManager
public static function addGroupMultiSelect($form, $groupInfo, $to = []) public static function addGroupMultiSelect($form, $groupInfo, $to = [])
{ {
$groupUsers = GroupManager::get_subscribed_users($groupInfo); $groupUsers = GroupManager::get_subscribed_users($groupInfo);
$array = self::buildSelectOptions([$groupInfo], $groupUsers, $to); $groupEntity = api_get_group_entity($groupInfo['iid']);
$array = self::buildSelectOptions([$groupEntity], $groupUsers, $to);
$result = []; $result = [];
foreach ($array as $content) { foreach ($array as $content) {
@ -6204,11 +6205,8 @@ class CourseManager
* *
* @return array * @return array
*/ */
public static function buildSelectOptions( public static function buildSelectOptions($groupList = [], $userList = [], $alreadySelected = [])
$groupList = [], {
$userList = [],
$alreadySelected = []
) {
if (empty($alreadySelected)) { if (empty($alreadySelected)) {
$alreadySelected = []; $alreadySelected = [];
} }

@ -475,7 +475,6 @@ class GroupManager
$groupInfo = self::get_group_properties($groupInfo['iid'], true); $groupInfo = self::get_group_properties($groupInfo['iid'], true);
if ($groupInfo) { if ($groupInfo) {
$groupIid = $groupInfo['iid']; $groupIid = $groupInfo['iid'];
$groupId = $groupInfo['id'];
// Unsubscribe all users // Unsubscribe all users
self::unsubscribe_all_users($groupInfo); self::unsubscribe_all_users($groupInfo);
self::unsubscribe_all_tutors($groupInfo); self::unsubscribe_all_tutors($groupInfo);
@ -509,7 +508,7 @@ class GroupManager
->createQuery( ->createQuery(
'DELETE FROM ChamiloCourseBundle:CForumForum f WHERE f.forumOfGroup = :group' 'DELETE FROM ChamiloCourseBundle:CForumForum f WHERE f.forumOfGroup = :group'
) )
->execute(['group' => $groupId]); ->execute(['group' => $groupIid]);
// Delete item properties of this group. // Delete item properties of this group.
// to_group_id is related to c_group_info.iid // to_group_id is related to c_group_info.iid
@ -520,11 +519,17 @@ class GroupManager
->execute(['course' => $course_id, 'group' => $groupId]); ->execute(['course' => $course_id, 'group' => $groupId]);
*/ */
// delete the groups // delete the groups
$em $repo = Container::getGroupRepository();
$group = $repo->find($groupIid);
if ($group) {
$em->remove($group);
$em->flush();
}
/*$em
->createQuery( ->createQuery(
'DELETE FROM ChamiloCourseBundle:CGroup g WHERE g.course = :course AND g.iid = :id' 'DELETE FROM ChamiloCourseBundle:CGroup g WHERE g.course = :course AND g.iid = :id'
) )
->execute(['course' => $course_id, 'id' => $groupIid]); ->execute(['course' => $course_id, 'id' => $groupIid]);*/
} }
return true; return true;

@ -1006,22 +1006,22 @@ function active_filter($active, $urlParams, $row)
*/ */
function modify_filter($user_id, $row, $data) function modify_filter($user_id, $row, $data)
{ {
global $charset;
$canEditUsers = 'true' == api_get_setting('allow_user_course_subscription_by_course_admin') || api_is_platform_admin(); $canEditUsers = 'true' == api_get_setting('allow_user_course_subscription_by_course_admin') || api_is_platform_admin();
$is_allowed_to_track = api_is_allowed_to_edit(true, true); $is_allowed_to_track = api_is_allowed_to_edit(true, true);
$user_id = $data[0]; $user_id = $data[0];
$userInfo = api_get_user_info($user_id); $userInfo = api_get_user_info($user_id);
$isInvitee = INVITEE == $userInfo['status'] ? true : false; $isInvitee = INVITEE == $userInfo['status'] ? true : false;
$course_info = $_course = api_get_course_info(); $course_info = $_course = api_get_course_info();
$current_user_id = api_get_user_id(); $current_user_id = api_get_user_id();
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
$courseId = $_course['id'];
$type = isset($_REQUEST['type']) ? intval($_REQUEST['type']) : STUDENT; $type = isset($_REQUEST['type']) ? intval($_REQUEST['type']) : STUDENT;
$result = ''; $result = '';
if ($is_allowed_to_track) { if ($is_allowed_to_track) {
$result .= '<a href="../mySpace/myStudents.php?'.api_get_cidreq().'&student='.$user_id.'&details=true&course='.$_course['id'].'&origin=user_course&id_session='.api_get_session_id().'" title="'.get_lang('Reporting').'"> $result .= '<a href="../mySpace/myStudents.php?'.api_get_cidreq().'&student='.$user_id.'&details=true&course='.$courseId.'&origin=user_course&id_session='.api_get_session_id().'"
title="'.get_lang('Reporting').'">
'.Display::return_icon('statistics.png', get_lang('Reporting')).' '.Display::return_icon('statistics.png', get_lang('Reporting')).'
</a>'; </a>';
} }
@ -1029,18 +1029,19 @@ function modify_filter($user_id, $row, $data)
// If platform admin, show the login_as icon (this drastically shortens // If platform admin, show the login_as icon (this drastically shortens
// time taken by support to test things out) // time taken by support to test things out)
if (api_is_platform_admin()) { if (api_is_platform_admin()) {
$result .= ' <a href="'.api_get_path(WEB_CODE_PATH).'admin/user_list.php?action=login_as&user_id='.$user_id.'&sec_token='.Security::getTokenFromSession().'">'. $result .= ' <a
href="'.api_get_path(WEB_CODE_PATH).'admin/user_list.php?action=login_as&user_id='.$user_id.'&sec_token='.Security::getTokenFromSession().'">'.
Display::return_icon('login_as.png', get_lang('Login as')).'</a>&nbsp;&nbsp;'; Display::return_icon('login_as.png', get_lang('Login as')).'</a>&nbsp;&nbsp;';
} }
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
if (empty($sessionId)) { if (empty($sessionId)) {
$isTutor = isset($data['is_tutor']) ? intval($data['is_tutor']) : 0; $isTutor = isset($data['is_tutor']) ? (int) $data['is_tutor'] : 0;
$isTutor = empty($isTutor) ? 1 : 0; $isTutor = empty($isTutor) ? 1 : 0;
$text = get_lang('RemoveCoachStatus'); $text = get_lang('Remove assistant role');
if ($isTutor) { if ($isTutor) {
$text = get_lang('SetCoach'); $text = get_lang('Convert to assistant');
} }
if ($isInvitee) { if ($isInvitee) {
@ -1052,7 +1053,8 @@ function modify_filter($user_id, $row, $data)
$allow = api_get_configuration_value('extra'); $allow = api_get_configuration_value('extra');
if ($allow) { if ($allow) {
$result .= '<a href="'. $result .= '<a href="'.
api_get_path(WEB_CODE_PATH).'extra/userInfo.php?'.api_get_cidreq().'&editMainUserInfo='.$user_id.'" title="'.get_lang('Edit').'" >'. api_get_path(WEB_CODE_PATH).'extra/userInfo.php?'.api_get_cidreq().'&editMainUserInfo='.$user_id.'"
title="'.get_lang('Edit').'" >'.
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL). Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).
'</a>&nbsp;'; '</a>&nbsp;';
} }
@ -1070,7 +1072,10 @@ function modify_filter($user_id, $row, $data)
if ($canEditUsers) { if ($canEditUsers) {
// unregister // unregister
if ($user_id != $current_user_id || api_is_platform_admin()) { if ($user_id != $current_user_id || api_is_platform_admin()) {
$result .= '<a class="btn btn-sm btn-danger delete-swal" href="'.api_get_self().'?'.api_get_cidreq().'&type='.$type.'&unregister=yes&user_id='.$user_id.'" title="'.addslashes(api_htmlentities(get_lang('Unsubscribe'))).' " >'. $result .= '<a
class="btn btn-sm btn-danger delete-swal"
href="'.api_get_self().'?'.api_get_cidreq().'&type='.$type.'&unregister=yes&user_id='.$user_id.'"
title="'.addslashes(api_htmlentities(get_lang('Unsubscribe'))).' " >'.
get_lang('Unsubscribe').'</a>&nbsp;'; get_lang('Unsubscribe').'</a>&nbsp;';
} }
} }
@ -1078,7 +1083,10 @@ function modify_filter($user_id, $row, $data)
// Show buttons for unsubscribe // Show buttons for unsubscribe
if (1 == $course_info['unsubscribe']) { if (1 == $course_info['unsubscribe']) {
if ($user_id == $current_user_id) { if ($user_id == $current_user_id) {
$result .= '<a class="btn btn-sm btn-danger delete-swal" href="'.api_get_self().'?'.api_get_cidreq().'&type='.$type.'&unregister=yes&user_id='.$user_id.'" title="'.addslashes(api_htmlentities(get_lang('Unsubscribe'))).' >'. $result .= '<a
class="btn btn-sm btn-danger delete-swal"
href="'.api_get_self().'?'.api_get_cidreq().'&type='.$type.'&unregister=yes&user_id='.$user_id.'"
title="'.addslashes(api_htmlentities(get_lang('Unsubscribe'))).' >'.
get_lang('Unsubscribe').'</a>&nbsp;'; get_lang('Unsubscribe').'</a>&nbsp;';
} }
} }

@ -244,8 +244,8 @@ Feature: Group tool
And I follow "Announcements" And I follow "Announcements"
Then I should see "Announcements" Then I should see "Announcements"
Then I follow "Add an announcement" Then I follow "Add an announcement"
And wait for the page to be loaded
Then I should see "Add an announcement" Then I should see "Add an announcement"
Then wait for the page to be loaded
Then I fill in the following: Then I fill in the following:
| title | Announcement for all users inside Group 0001 | | title | Announcement for all users inside Group 0001 |
And I fill in ckeditor field "content" with "Announcement description in Group 0001" And I fill in ckeditor field "content" with "Announcement description in Group 0001"
@ -286,8 +286,8 @@ Feature: Group tool
Then wait for the page to be loaded Then wait for the page to be loaded
Then I should see "Announcements" Then I should see "Announcements"
Then I follow "Add an announcement" Then I follow "Add an announcement"
And wait for the page to be loaded
Then I should see "Add an announcement" Then I should see "Add an announcement"
Then wait for the page to be loaded
Then I fill in the following: Then I fill in the following:
| title | Announcement for all users inside Group 0003 | | title | Announcement for all users inside Group 0003 |
And I fill in ckeditor field "content" with "Announcement description in Group 0003" And I fill in ckeditor field "content" with "Announcement description in Group 0003"
@ -305,6 +305,7 @@ Feature: Group tool
And I follow "Announcements" And I follow "Announcements"
Then I should see "Announcements" Then I should see "Announcements"
Then I follow "Add an announcement" Then I follow "Add an announcement"
Then wait for the page to be loaded
Then I should see "Add an announcement" Then I should see "Add an announcement"
Then wait for the page to be loaded Then wait for the page to be loaded
Then I press "choose_recipients" Then I press "choose_recipients"
@ -320,15 +321,17 @@ Feature: Group tool
Then I should see "Announcement has been added" Then I should see "Announcement has been added"
Scenario: Create an announcement as acostea and send only to fapple Scenario: Create an announcement as acostea and send only to fapple
Given I am not logged
Given I am logged as "acostea" Given I am logged as "acostea"
Given I am on "/main/group/group.php?cid=1&sid=0" Given I am on "/main/group/group.php?cid=1&sid=0"
And I follow "Group 0005" And I follow "Group 0005"
Then I should see "Group 0005" Then I should see "Group 0005"
And I follow "Announcements" And I follow "Announcements"
Then wait the page to be loaded when ready
Then I should see "Announcements" Then I should see "Announcements"
Then I follow "Add an announcement" Then I follow "Add an announcement"
Then I should see "Add an announcement"
Then wait for the page to be loaded Then wait for the page to be loaded
Then I should see "Add an announcement"
Then I press "choose_recipients" Then I press "choose_recipients"
Then I select "Fiona Apple Maggart" from "users" Then I select "Fiona Apple Maggart" from "users"
Then I press "users_rightSelected" Then I press "users_rightSelected"
@ -342,6 +345,7 @@ Feature: Group tool
Then I should see "Announcement has been added" Then I should see "Announcement has been added"
Scenario: Check fapple/acostea access of announcements Scenario: Check fapple/acostea access of announcements
Given I am not logged
Given I am logged as "fapple" Given I am logged as "fapple"
And I am on course "TEMP" homepage And I am on course "TEMP" homepage
And I am on "/main/group/group.php?cid=1&sid=0" And I am on "/main/group/group.php?cid=1&sid=0"
@ -386,6 +390,7 @@ Feature: Group tool
Then I save current URL with name "announcement_only_for_fapple_private" Then I save current URL with name "announcement_only_for_fapple_private"
## Finish tests with fapple now check access with acostea ## ## Finish tests with fapple now check access with acostea ##
Given I am not logged
Given I am logged as "acostea" Given I am logged as "acostea"
And I am on course "TEMP" homepage And I am on course "TEMP" homepage
Given I am on "/main/group/group.php?cid=1&sid=0" Given I am on "/main/group/group.php?cid=1&sid=0"
@ -400,6 +405,7 @@ Feature: Group tool
Then I visit URL saved with name "announcement_only_for_fapple_private" Then I visit URL saved with name "announcement_only_for_fapple_private"
Then I should see "Sorry, you are not allowed to access this page" Then I should see "Sorry, you are not allowed to access this page"
Given I am not logged
Given I am logged as "acostea" Given I am logged as "acostea"
And I am on course "TEMP" homepage And I am on course "TEMP" homepage
Given I am on "/main/group/group.php?cid=1&sid=0" Given I am on "/main/group/group.php?cid=1&sid=0"

Loading…
Cancel
Save