@@ -480,6 +480,53 @@ function (string $userId, string $appName, string $key, mixed $default = '') use
480480 $ this ->assertEquals ($ expected , $ entries );
481481 }
482482
483+ /**
484+ * Known apps get a default order, all other apps keep the order from their info.xml.
485+ */
486+ public function testDefaultAppOrder (): void {
487+ $ this ->userSession ->method ('isLoggedIn ' )->willReturn (false );
488+ $ this ->appManager ->method ('getEnabledApps ' )->willReturn ([]);
489+ $ this ->appManager ->method ('isEnabledForUser ' )->willReturn (true );
490+
491+ // order as shipped by the apps themselves
492+ $ apps = ['circles ' => 80 , 'activity ' => 1 , 'other ' => 2 , 'spreed ' => -5 , 'files ' => 0 , 'dashboard ' => -10 ];
493+ foreach ($ apps as $ id => $ order ) {
494+ $ this ->navigationManager ->add (['id ' => $ id , 'name ' => $ id , 'href ' => '/ ' , 'order ' => $ order ]);
495+ }
496+
497+ $ this ->assertSame (
498+ ['dashboard ' , 'files ' , 'spreed ' , 'circles ' , 'activity ' , 'other ' ],
499+ array_keys ($ this ->navigationManager ->getAll ()),
500+ );
501+ }
502+
503+ /**
504+ * Users that sorted the apps themselves keep their order, also for apps they never sorted.
505+ */
506+ public function testDefaultAppOrderIsSkippedForCustomOrder (): void {
507+ $ user = $ this ->createMock (IUser::class);
508+ $ user ->method ('getUID ' )->willReturn ('user001 ' );
509+ $ this ->userSession ->method ('getUser ' )->willReturn ($ user );
510+ $ this ->userSession ->method ('isLoggedIn ' )->willReturn (true );
511+ $ this ->appManager ->method ('getEnabledAppsForUser ' )->willReturn ([]);
512+ $ this ->appManager ->method ('isEnabledForUser ' )->willReturn (true );
513+ $ this ->config ->method ('getUserValue ' )
514+ ->willReturnCallback (static function (string $ userId , string $ appName , string $ key , mixed $ default = '' ) {
515+ return $ key === 'apporder ' ? json_encode (['other ' => ['app ' => 'other ' , 'order ' => 0 ]]) : $ default ;
516+ });
517+
518+ // `circles` is not part of the user order, so it keeps the order from its info.xml
519+ // instead of moving to the front of the user order
520+ foreach (['other ' => 2 , 'circles ' => 80 ] as $ id => $ order ) {
521+ $ this ->navigationManager ->add (['id ' => $ id , 'name ' => $ id , 'href ' => '/ ' , 'order ' => $ order ]);
522+ }
523+
524+ $ this ->assertSame (
525+ ['other ' , 'circles ' ],
526+ array_keys ($ this ->navigationManager ->getAll ()),
527+ );
528+ }
529+
483530 /**
484531 * Navigation entries of enabled apps that are not booted yet must not be resolved.
485532 */
0 commit comments