$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;