diff --git a/core/Command/App/ListApps.php b/core/Command/App/ListApps.php index fd70288dbea36..a79bc0ffd70a7 100644 --- a/core/Command/App/ListApps.php +++ b/core/Command/App/ListApps.php @@ -83,7 +83,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int sort($enabledApps); foreach ($enabledApps as $app) { - $apps['enabled'][$app] = $versions[$app] ?? true; + $groups = $this->appManager->getAppRestriction($app); + if (!empty($groups)) { + $apps['enabled'][$app] = [ + 'version' => $versions[$app] ?? true, + 'groups' => $groups, + ]; + } else { + $apps['enabled'][$app] = $versions[$app] ?? true; + } } } diff --git a/tests/Core/Command/Apps/ListAppsTest.php b/tests/Core/Command/Apps/ListAppsTest.php new file mode 100644 index 0000000000000..03617c5e0b039 --- /dev/null +++ b/tests/Core/Command/Apps/ListAppsTest.php @@ -0,0 +1,67 @@ +appManager = Server::get(IAppManager::class); + $command = new ListApps($this->appManager); + $this->commandTester = new CommandTester($command); + + $this->appManager->disableApp('updatenotification'); + } + + #[\Override] + protected function tearDown(): void { + $this->appManager->disableApp('updatenotification'); + parent::tearDown(); + } + + public function testEnabledAppWithoutGroupRestrictionHasNoGroupsKey(): void { + $this->appManager->enableApp('updatenotification'); + + $this->commandTester->execute(['--output' => 'json']); + + $apps = json_decode($this->commandTester->getDisplay(), true); + + $this->assertArrayHasKey('updatenotification', $apps['enabled']); + $this->assertIsNotArray($apps['enabled']['updatenotification']); + } + + public function testEnabledAppWithGroupRestrictionShowsGroups(): void { + $this->appManager->enableAppForGroups('updatenotification', ['admin']); + + $this->commandTester->execute(['--output' => 'json']); + + $apps = json_decode($this->commandTester->getDisplay(), true); + + $this->assertArrayHasKey('updatenotification', $apps['enabled']); + $this->assertIsArray($apps['enabled']['updatenotification']); + $this->assertSame(['admin'], $apps['enabled']['updatenotification']['groups']); + } +}