Skip to content

Commit

Permalink
MDL-54042 user: Add unit test to cover change
Browse files Browse the repository at this point in the history
  • Loading branch information
Damyon Wiese committed May 6, 2016
1 parent f808005 commit 845f0cf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion enrol/tests/enrollib_test.php
Expand Up @@ -136,7 +136,7 @@ public function test_enrol_get_all_users_courses() {
// Make sure sorting and columns work.

$basefields = array('id', 'category', 'sortorder', 'shortname', 'fullname', 'idnumber',
'startdate', 'visible', 'groupmode', 'groupmodeforce');
'startdate', 'visible', 'groupmode', 'groupmodeforce', 'defaultgroupingid');

$courses = enrol_get_all_users_courses($user2->id, true);
$course = reset($courses);
Expand Down
37 changes: 37 additions & 0 deletions user/tests/userlib_test.php
Expand Up @@ -37,6 +37,43 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_userliblib_testcase extends advanced_testcase {
/**
* Test user_get_user_details_courses
*/
public function test_user_get_user_details_courses() {
global $DB;

$this->resetAfterTest();

// Create user and modify user profile.
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();

$course1 = $this->getDataGenerator()->create_course();
$coursecontext = context_course::instance($course1->id);
$teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
$this->getDataGenerator()->enrol_user($user1->id, $course1->id);
$this->getDataGenerator()->enrol_user($user2->id, $course1->id);
role_assign($teacherrole->id, $user1->id, $coursecontext->id);
role_assign($teacherrole->id, $user2->id, $coursecontext->id);

accesslib_clear_all_caches_for_unit_testing();

// Get user2 details as a user with super system capabilities.
$result = user_get_user_details_courses($user2);
$this->assertEquals($user2->id, $result['id']);
$this->assertEquals(fullname($user2), $result['fullname']);
$this->assertEquals($course1->id, $result['enrolledcourses'][0]['id']);

$this->setUser($user1);
// Get user2 details as a user who can only see this user in a course.
$result = user_get_user_details_courses($user2);
$this->assertEquals($user2->id, $result['id']);
$this->assertEquals(fullname($user2), $result['fullname']);
$this->assertEquals($course1->id, $result['enrolledcourses'][0]['id']);

}

/**
* Test user_update_user.
*/
Expand Down

0 comments on commit 845f0cf

Please sign in to comment.