Merge branch 'MDL-50704-master' of git://github.com/FMCorz/moodle
authorDan Poltawski <dan@moodle.com>
Tue, 10 May 2016 14:59:41 +0000 (15:59 +0100)
committerDan Poltawski <dan@moodle.com>
Tue, 10 May 2016 14:59:41 +0000 (15:59 +0100)
1  2 
user/tests/userlib_test.php

@@@ -37,43 -37,6 +37,43 @@@ require_once($CFG->dirroot.'/user/lib.p
   * @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.
       */
          $user->country = 'WW';
          $user->lang = 'xy';
          $user->theme = 'somewrongthemename';
-         $user->timezone = 'Paris';
+         $user->timezone = '30.5';
          $user->url = 'wwww.somewrong@#$url.com.aus';
          $debugmessages = $this->getDebuggingMessages();
          user_update_user($user, true, false);
          $user['country'] = 'WW';
          $user['lang'] = 'xy';
          $user['theme'] = 'somewrongthemename';
-         $user['timezone'] = 'Paris';
+         $user['timezone'] = '-30.5';
          $user['url'] = 'wwww.somewrong@#$url.com.aus';
          $debugmessages = $this->getDebuggingMessages();
          $user['id'] = user_create_user($user, true, false);
          $dbuser = $DB->get_record('user', array('id' => $user['id']));
          $this->assertEquals($dbuser->country, 0);
          $this->assertEquals($dbuser->lang, 'en');
-         $this->assertEquals($dbuser->timezone, 'Australia/Perth');
+         $this->assertEquals($dbuser->timezone, '');
  
          // Now, with valid user data.
          $user['username'] = 'johndoe321';