@@ -593,6 +593,107 @@ public function testDownloadAppSuccessful(): void {
593593 $ this ->assertEquals ('0.9 ' , \OC_App::getAppVersionByPath (__DIR__ . '/../../apps/testapp/ ' ));
594594 }
595595
596+ public function testIsUpdateAvailableLogsDebugForGitInstall (): void {
597+ $ tmpDir = sys_get_temp_dir () . '/nc_test_git_ ' . uniqid ();
598+ mkdir ($ tmpDir . '/.git ' , 0700 , true );
599+
600+ $ this ->appManager
601+ ->expects ($ this ->once ())
602+ ->method ('getAppPath ' )
603+ ->with ('myapp ' )
604+ ->willReturn ($ tmpDir );
605+ $ this ->logger
606+ ->expects ($ this ->once ())
607+ ->method ('debug ' )
608+ ->with (
609+ 'App {appId} is installed from git, skipping update check ' ,
610+ $ this ->callback (fn ($ ctx ) => $ ctx ['appId ' ] === 'myapp ' )
611+ );
612+
613+ $ installer = $ this ->getInstaller ();
614+ $ result = $ installer ->isUpdateAvailable ('myapp ' );
615+ $ this ->assertFalse ($ result );
616+
617+ rmdir ($ tmpDir . '/.git ' );
618+ rmdir ($ tmpDir );
619+ }
620+
621+ protected function getPartialInstaller (array $ onlyMethods ): Installer &\PHPUnit \Framework \MockObject \MockObject {
622+ return $ this ->getMockBuilder (Installer::class)
623+ ->setConstructorArgs ([
624+ $ this ->appFetcher ,
625+ $ this ->clientService ,
626+ $ this ->tempManager ,
627+ $ this ->logger ,
628+ $ this ->config ,
629+ $ this ->appManager ,
630+ $ this ->l10nFactory ,
631+ false ,
632+ ])
633+ ->onlyMethods ($ onlyMethods )
634+ ->getMock ();
635+ }
636+
637+ public function testUpdateAppstoreAppReEnablesDisabledIncompatibleApp (): void {
638+ $ installer = $ this ->getPartialInstaller (['isUpdateAvailable ' , 'downloadApp ' ]);
639+ $ installer ->method ('isUpdateAvailable ' )->willReturn ('1.0.0 ' );
640+ $ installer ->method ('downloadApp ' )->willReturn (null );
641+
642+ $ this ->appManager ->method ('isEnabledForAnyone ' )->with ('myapp ' )->willReturn (false );
643+ $ this ->appManager ->method ('getAppInfo ' )->with ('myapp ' )->willReturn (['id ' => 'myapp ' , 'version ' => '0.0.1 ' ]);
644+ $ this ->appManager ->method ('isAppCompatible ' )->willReturn (false );
645+ $ this ->appManager ->method ('upgradeApp ' )->with ('myapp ' )->willReturn (true );
646+ $ this ->appManager ->expects ($ this ->once ())->method ('enableApp ' )->with ('myapp ' );
647+
648+ $ result = $ installer ->updateAppstoreApp ('myapp ' );
649+ $ this ->assertTrue ($ result );
650+ }
651+
652+ public function testUpdateAppstoreAppDoesNotReEnableCompatibleButDisabledApp (): void {
653+ $ installer = $ this ->getPartialInstaller (['isUpdateAvailable ' , 'downloadApp ' ]);
654+ $ installer ->method ('isUpdateAvailable ' )->willReturn ('1.0.0 ' );
655+ $ installer ->method ('downloadApp ' )->willReturn (null );
656+
657+ $ this ->appManager ->method ('isEnabledForAnyone ' )->with ('myapp ' )->willReturn (false );
658+ $ this ->appManager ->method ('getAppInfo ' )->with ('myapp ' )->willReturn (['id ' => 'myapp ' , 'version ' => '1.0.0 ' ]);
659+ $ this ->appManager ->method ('isAppCompatible ' )->willReturn (true );
660+ $ this ->appManager ->method ('upgradeApp ' )->with ('myapp ' )->willReturn (true );
661+ $ this ->appManager ->expects ($ this ->never ())->method ('enableApp ' );
662+
663+ $ result = $ installer ->updateAppstoreApp ('myapp ' );
664+ $ this ->assertTrue ($ result );
665+ }
666+
667+ public function testUpdateAppstoreAppDoesNotReEnableAlreadyEnabledApp (): void {
668+ $ installer = $ this ->getPartialInstaller (['isUpdateAvailable ' , 'downloadApp ' ]);
669+ $ installer ->method ('isUpdateAvailable ' )->willReturn ('1.0.0 ' );
670+ $ installer ->method ('downloadApp ' )->willReturn (null );
671+
672+ $ this ->appManager ->method ('isEnabledForAnyone ' )->with ('myapp ' )->willReturn (true );
673+ $ this ->appManager ->method ('upgradeApp ' )->with ('myapp ' )->willReturn (true );
674+ $ this ->appManager ->expects ($ this ->never ())->method ('enableApp ' );
675+ $ this ->appManager ->expects ($ this ->never ())->method ('getAppInfo ' );
676+ $ this ->appManager ->expects ($ this ->never ())->method ('isAppCompatible ' );
677+
678+ $ result = $ installer ->updateAppstoreApp ('myapp ' );
679+ $ this ->assertTrue ($ result );
680+ }
681+
682+ public function testUpdateAppstoreAppDoesNotReEnableWhenUpgradeFails (): void {
683+ $ installer = $ this ->getPartialInstaller (['isUpdateAvailable ' , 'downloadApp ' ]);
684+ $ installer ->method ('isUpdateAvailable ' )->willReturn ('1.0.0 ' );
685+ $ installer ->method ('downloadApp ' )->willReturn (null );
686+
687+ $ this ->appManager ->method ('isEnabledForAnyone ' )->with ('myapp ' )->willReturn (false );
688+ $ this ->appManager ->method ('getAppInfo ' )->with ('myapp ' )->willReturn (['id ' => 'myapp ' , 'version ' => '0.0.1 ' ]);
689+ $ this ->appManager ->method ('isAppCompatible ' )->willReturn (false );
690+ $ this ->appManager ->method ('upgradeApp ' )->with ('myapp ' )->willReturn (false );
691+ $ this ->appManager ->expects ($ this ->never ())->method ('enableApp ' );
692+
693+ $ result = $ installer ->updateAppstoreApp ('myapp ' );
694+ $ this ->assertFalse ($ result );
695+ }
696+
596697 public function testDownloadAppWithDowngrade (): void {
597698 // Use previous test to download the application in version 0.9
598699 $ this ->testDownloadAppSuccessful ();
0 commit comments