@@ -998,23 +998,58 @@ public function testGetHomePathConfiguredNotAvailableNotAllowed() {
998998
999999 public function displayNameProvider () {
10001000 return [
1001- ['Roland Deschain ' , '' , 'Roland Deschain ' ],
1002- ['Roland Deschain ' , null , 'Roland Deschain ' ],
1003- [
'Roland Deschain ' ,
'[email protected] ' ,
'Roland Deschain ([email protected] ) ' ],
1001+ ['Roland Deschain ' , '' , 'Roland Deschain ' , false ],
1002+ ['Roland Deschain ' , '' , 'Roland Deschain ' , true ],
1003+ ['Roland Deschain ' , null , 'Roland Deschain ' , false ],
1004+ [
'Roland Deschain ' ,
'[email protected] ' ,
'Roland Deschain ([email protected] ) ' ,
false ],
1005+ [
'Roland Deschain ' ,
'[email protected] ' ,
'Roland Deschain ([email protected] ) ' ,
true ],
10041006 ];
10051007 }
10061008
10071009 /**
10081010 * @dataProvider displayNameProvider
10091011 */
1010- public function testComposeAndStoreDisplayName ($ part1 , $ part2 , $ expected ) {
1012+ public function testComposeAndStoreDisplayName ($ part1 , $ part2 , $ expected, $ expectTriggerChange ) {
10111013 $ this ->config ->expects ($ this ->once ())
10121014 ->method ('setUserValue ' );
1015+ $ oldName = $ expectTriggerChange ? 'xxGunslingerxx ' : null ;
1016+ $ this ->config ->expects ($ this ->once ())
1017+ ->method ('getUserValue ' )
1018+ ->with ($ this ->user ->getUsername (), 'user_ldap ' , 'displayName ' , null )
1019+ ->willReturn ($ oldName );
1020+
1021+ $ ncUserObj = $ this ->createMock (\OC \User \User::class);
1022+ if ($ expectTriggerChange ) {
1023+ $ ncUserObj ->expects ($ this ->once ())
1024+ ->method ('triggerChange ' )
1025+ ->with ('displayName ' , $ expected );
1026+ } else {
1027+ $ ncUserObj ->expects ($ this ->never ())
1028+ ->method ('triggerChange ' );
1029+ }
1030+ $ this ->userManager ->expects ($ this ->once ())
1031+ ->method ('get ' )
1032+ ->willReturn ($ ncUserObj );
10131033
10141034 $ displayName = $ this ->user ->composeAndStoreDisplayName ($ part1 , $ part2 );
10151035 $ this ->assertSame ($ expected , $ displayName );
10161036 }
10171037
1038+ public function testComposeAndStoreDisplayNameNoOverwrite () {
1039+ $ displayName = 'Randall Flagg ' ;
1040+ $ this ->config ->expects ($ this ->never ())
1041+ ->method ('setUserValue ' );
1042+ $ this ->config ->expects ($ this ->once ())
1043+ ->method ('getUserValue ' )
1044+ ->willReturn ($ displayName );
1045+
1046+ $ this ->userManager ->expects ($ this ->never ())
1047+ ->method ('get ' ); // Implicit: no triggerChange can be called
1048+
1049+ $ composedDisplayName = $ this ->user ->composeAndStoreDisplayName ($ displayName );
1050+ $ this ->assertSame ($ composedDisplayName , $ displayName );
1051+ }
1052+
10181053 public function testHandlePasswordExpiryWarningDefaultPolicy () {
10191054 $ this ->connection ->expects ($ this ->any ())
10201055 ->method ('__get ' )
0 commit comments