diff options
author | Thomas Citharel <tcit@tcit.fr> | 2022-12-08 10:55:19 +0100 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2023-03-13 11:52:57 +0100 |
commit | f1751c44286930ea4ef41b046cdc4570330ee301 (patch) | |
tree | d5e403dfc0ab94bcf73a0490edba8de0e5365150 /tests | |
parent | ade49e0b15e408bf00dd24f5641bd9a29a18f05c (diff) | |
download | nextcloud-server-f1751c44286930ea4ef41b046cdc4570330ee301.tar.gz nextcloud-server-f1751c44286930ea4ef41b046cdc4570330ee301.zip |
Introduced app enable/disable/update typed events
OCP\App\ManagerEvent is depreciated since 22 without a replacement
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/App/AppManagerTest.php | 28 | ||||
-rw-r--r-- | tests/lib/AppTest.php | 4 |
2 files changed, 25 insertions, 7 deletions
diff --git a/tests/lib/App/AppManagerTest.php b/tests/lib/App/AppManagerTest.php index de515837406..bf9592ac6a6 100644 --- a/tests/lib/App/AppManagerTest.php +++ b/tests/lib/App/AppManagerTest.php @@ -14,7 +14,10 @@ namespace Test\App; use OC\App\AppManager; use OC\AppConfig; use OCP\App\AppPathNotFoundException; +use OCP\App\Events\AppDisableEvent; +use OCP\App\Events\AppEnableEvent; use OCP\App\IAppManager; +use OCP\EventDispatcher\IEventDispatcher; use OCP\ICache; use OCP\ICacheFactory; use OCP\IConfig; @@ -91,6 +94,9 @@ class AppManagerTest extends TestCase { protected $cacheFactory; /** @var EventDispatcherInterface|MockObject */ + protected $legacyEventDispatcher; + + /** @var IEventDispatcher|MockObject */ protected $eventDispatcher; /** @var LoggerInterface|MockObject */ @@ -108,7 +114,8 @@ class AppManagerTest extends TestCase { $this->appConfig = $this->getAppConfig(); $this->cacheFactory = $this->createMock(ICacheFactory::class); $this->cache = $this->createMock(ICache::class); - $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); + $this->legacyEventDispatcher = $this->createMock(EventDispatcherInterface::class); + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); $this->logger = $this->createMock(LoggerInterface::class); $this->cacheFactory->expects($this->any()) ->method('createDistributed') @@ -120,6 +127,7 @@ class AppManagerTest extends TestCase { $this->appConfig, $this->groupManager, $this->cacheFactory, + $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger ); @@ -137,12 +145,14 @@ class AppManagerTest extends TestCase { if ($this->manager->isEnabledForUser('files_trashbin')) { $this->manager->disableApp('files_trashbin'); } + $this->eventDispatcher->expects($this->once())->method('dispatchTyped')->with(new AppEnableEvent('files_trashbin')); $this->manager->enableApp('files_trashbin'); $this->assertEquals('yes', $this->appConfig->getValue('files_trashbin', 'enabled', 'no')); } public function testDisableApp() { $this->expectClearCache(); + $this->eventDispatcher->expects($this->once())->method('dispatchTyped')->with(new AppDisableEvent('files_trashbin')); $this->manager->disableApp('files_trashbin'); $this->assertEquals('no', $this->appConfig->getValue('files_trashbin', 'enabled', 'no')); } @@ -175,7 +185,7 @@ class AppManagerTest extends TestCase { /** @var AppManager|MockObject $manager */ $manager = $this->getMockBuilder(AppManager::class) ->setConstructorArgs([ - $this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger + $this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger ]) ->setMethods([ 'getAppPath', @@ -187,6 +197,8 @@ class AppManagerTest extends TestCase { ->with('test') ->willReturn('apps/test'); + $this->eventDispatcher->expects($this->once())->method('dispatchTyped')->with(new AppEnableEvent('test', ['group1', 'group2'])); + $manager->enableAppForGroups('test', $groups); $this->assertEquals('["group1","group2"]', $this->appConfig->getValue('test', 'enabled', 'no')); } @@ -222,7 +234,7 @@ class AppManagerTest extends TestCase { /** @var AppManager|MockObject $manager */ $manager = $this->getMockBuilder(AppManager::class) ->setConstructorArgs([ - $this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger + $this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger ]) ->setMethods([ 'getAppPath', @@ -240,6 +252,8 @@ class AppManagerTest extends TestCase { ->with('test') ->willReturn($appInfo); + $this->eventDispatcher->expects($this->once())->method('dispatchTyped')->with(new AppEnableEvent('test', ['group1', 'group2'])); + $manager->enableAppForGroups('test', $groups); $this->assertEquals('["group1","group2"]', $this->appConfig->getValue('test', 'enabled', 'no')); } @@ -276,7 +290,7 @@ class AppManagerTest extends TestCase { /** @var AppManager|MockObject $manager */ $manager = $this->getMockBuilder(AppManager::class) ->setConstructorArgs([ - $this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger + $this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger ]) ->setMethods([ 'getAppPath', @@ -296,6 +310,8 @@ class AppManagerTest extends TestCase { 'types' => [$type], ]); + $this->eventDispatcher->expects($this->never())->method('dispatchTyped')->with(new AppEnableEvent('test', ['group1', 'group2'])); + $manager->enableAppForGroups('test', $groups); } @@ -470,7 +486,7 @@ class AppManagerTest extends TestCase { public function testGetAppsNeedingUpgrade() { /** @var AppManager|MockObject $manager */ $manager = $this->getMockBuilder(AppManager::class) - ->setConstructorArgs([$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger]) + ->setConstructorArgs([$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger]) ->setMethods(['getAppInfo']) ->getMock(); @@ -521,7 +537,7 @@ class AppManagerTest extends TestCase { public function testGetIncompatibleApps() { /** @var AppManager|MockObject $manager */ $manager = $this->getMockBuilder(AppManager::class) - ->setConstructorArgs([$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher, $this->logger]) + ->setConstructorArgs([$this->userSession, $this->config, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->legacyEventDispatcher, $this->eventDispatcher, $this->logger]) ->setMethods(['getAppInfo']) ->getMock(); diff --git a/tests/lib/AppTest.php b/tests/lib/AppTest.php index 4b2619a3761..5cdee5e1200 100644 --- a/tests/lib/AppTest.php +++ b/tests/lib/AppTest.php @@ -12,6 +12,7 @@ namespace Test; use OC\App\AppManager; use OC\App\InfoParser; use OC\AppConfig; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IAppConfig; use Psr\Log\LoggerInterface; @@ -553,13 +554,14 @@ class AppTest extends \Test\TestCase { */ private function registerAppConfig(AppConfig $appConfig) { $this->overwriteService(AppConfig::class, $appConfig); - $this->overwriteService(AppManager::class, new \OC\App\AppManager( + $this->overwriteService(AppManager::class, new AppManager( \OC::$server->getUserSession(), \OC::$server->getConfig(), $appConfig, \OC::$server->getGroupManager(), \OC::$server->getMemCacheFactory(), \OC::$server->getEventDispatcher(), + \OC::$server->get(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class) )); } |