@@ -547,6 +547,41 @@ public function test_update_refuse_duplicate_username(): void {
547547 $ this ->auth ->get_login_url ($ originaluser );
548548 }
549549
550+ /**
551+ * Test that a user can be updated without providing any other fields than the mappingfield.
552+ * (Only auth field should be updated).
553+ */
554+ public function test_update_allow_unset_fields (): void {
555+ global $ DB ;
556+ set_config ('updateuser ' , true , 'auth_userkey ' );
557+ set_config ('mappingfield ' , 'id ' , 'auth_userkey ' );
558+ $ this ->auth = new auth_plugin_userkey ();
559+
560+ $ userkeymanager = new fake_userkey_manager ();
561+ $ this ->auth ->set_userkey_manager ($ userkeymanager );
562+
563+ $ originaluser = new stdClass ();
564+ $ originaluser ->username = 'username ' ;
565+ $ originaluser->
email =
'[email protected] ' ;
566+ $ originaluser ->firstname = 'user ' ;
567+ $ originaluser ->lastname = 'name ' ;
568+
569+ $ user = self ::getDataGenerator ()->create_user ($ originaluser );
570+
571+ $ loginuser = new stdClass ();
572+ $ loginuser ->id = $ user ->id ;
573+
574+ $ key = $ this ->auth ->get_login_url ($ loginuser );
575+
576+ $ userrecord = $ DB ->get_record ('user ' , ['id ' => $ user ->id ]);
577+ $ this ->assertNotEmpty ($ key );
578+ $ this ->assertEquals ('userkey ' , $ userrecord ->auth );
579+ $ this ->assertEquals ('username ' , $ userrecord ->username );
580+ $ this ->
assertEquals (
'[email protected] ' ,
$ userrecord->
email );
581+ $ this ->assertEquals ('user ' , $ userrecord ->firstname );
582+ $ this ->assertEquals ('name ' , $ userrecord ->lastname );
583+ }
584+
550585 /**
551586 * Test that we can get login url if we do not use fake keymanager.
552587 */
0 commit comments