Merge branch 'MDL-43639_updatePassEveryLogin' of https://github.com/moodlerooms/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 1 Sep 2014 23:07:36 +0000 (01:07 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 1 Sep 2014 23:07:36 +0000 (01:07 +0200)
1  2 
lib/moodlelib.php
lib/tests/moodlelib_test.php

Simple merge
@@@ -2262,15 -2262,41 +2262,48 @@@ class core_moodlelib_testcase extends a
          $this->assertSame($user->id, $event->relateduserid);
          $this->assertEquals(context_user::instance($user->id), $event->get_context());
          $this->assertEventContextNotUsed($event);
 +
 +        // Verify recovery of property 'auth'.
 +        unset($user->auth);
 +        update_internal_user_password($user, 'newpassword');
 +        $this->assertDebuggingCalled('User record in update_internal_user_password() must include field auth',
 +                DEBUG_DEVELOPER);
 +        $this->assertEquals('manual', $user->auth);
      }
  
+     /**
+      * Testing that if the password is not cached, that it does not update
+      * the user table and fire event.
+      */
+     public function test_update_internal_user_password_no_cache() {
+         $this->resetAfterTest();
+         $user = $this->getDataGenerator()->create_user(array('auth' => 'cas'));
+         $this->assertEquals(AUTH_PASSWORD_NOT_CACHED, $user->password);
+         $sink = $this->redirectEvents();
+         update_internal_user_password($user, 'wonkawonka');
+         $this->assertEquals(0, $sink->count(), 'User updated event should not fire');
+     }
+     /**
+      * Test if the user has a password hash, but now their auth method
+      * says not to cache it.  Then it should update.
+      */
+     public function test_update_internal_user_password_update_no_cache() {
+         $this->resetAfterTest();
+         $user = $this->getDataGenerator()->create_user(array('password' => 'test'));
+         $this->assertNotEquals(AUTH_PASSWORD_NOT_CACHED, $user->password);
+         $user->auth = 'cas'; // Change to a auth that does not store passwords.
+         $sink = $this->redirectEvents();
+         update_internal_user_password($user, 'wonkawonka');
+         $this->assertGreaterThanOrEqual(1, $sink->count(), 'User updated event should fire');
+         $this->assertEquals(AUTH_PASSWORD_NOT_CACHED, $user->password);
+     }
      public function test_fullname() {
          global $CFG;