aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-03-06 11:13:29 +0100
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2024-03-07 22:40:31 +0100
commit876e2d6198040553cdf0b184fb585b3b63048a7d (patch)
treebccdffb7f66222df0f5261c26a38c845a640abe7 /tests
parent26728846b40bb1819ad4de507f397b944d15877b (diff)
downloadnextcloud-server-876e2d6198040553cdf0b184fb585b3b63048a7d.tar.gz
nextcloud-server-876e2d6198040553cdf0b184fb585b3b63048a7d.zip
feat(AppManager): Provide `getAppIcon` function
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/App/AppManagerTest.php129
-rw-r--r--tests/lib/AppTest.php6
-rw-r--r--tests/lib/NavigationManagerTest.php23
3 files changed, 135 insertions, 23 deletions
diff --git a/tests/lib/App/AppManagerTest.php b/tests/lib/App/AppManagerTest.php
index 3733d6cd2e9..09a64f84469 100644
--- a/tests/lib/App/AppManagerTest.php
+++ b/tests/lib/App/AppManagerTest.php
@@ -23,6 +23,7 @@ use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
+use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
use PHPUnit\Framework\MockObject\MockObject;
@@ -98,6 +99,8 @@ class AppManagerTest extends TestCase {
/** @var LoggerInterface|MockObject */
protected $logger;
+ protected IURLGenerator|MockObject $urlGenerator;
+
/** @var IAppManager */
protected $manager;
@@ -112,6 +115,7 @@ class AppManagerTest extends TestCase {
$this->cache = $this->createMock(ICache::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->logger = $this->createMock(LoggerInterface::class);
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->cacheFactory->expects($this->any())
->method('createDistributed')
->with('settings')
@@ -123,10 +127,74 @@ class AppManagerTest extends TestCase {
$this->groupManager,
$this->cacheFactory,
$this->eventDispatcher,
- $this->logger
+ $this->logger,
+ $this->urlGenerator,
);
}
+ /**
+ * @dataProvider dataGetAppIcon
+ */
+ public function testGetAppIcon($callback, string|null $expected) {
+ $this->urlGenerator->expects($this->atLeastOnce())
+ ->method('imagePath')
+ ->willReturnCallback($callback);
+
+ $this->assertEquals($expected, $this->manager->getAppIcon('test'));
+ }
+
+ public function dataGetAppIcon(): array {
+ $nothing = function ($appId) {
+ $this->assertEquals('test', $appId);
+ throw new \RuntimeException();
+ };
+
+ $createCallback = function ($workingIcons) {
+ return function ($appId, $icon) use ($workingIcons) {
+ $this->assertEquals('test', $appId);
+ if (in_array($icon, $workingIcons)) {
+ return '/path/' . $icon;
+ }
+ throw new \RuntimeException();
+ };
+ };
+
+ return [
+ 'does not find anything' => [
+ $nothing,
+ null,
+ ],
+ 'only app.svg' => [
+ $createCallback(['app.svg']),
+ '/path/app.svg',
+ ],
+ 'only app-dark.svg' => [
+ $createCallback(['app-dark.svg']),
+ '/path/app-dark.svg',
+ ],
+ 'only appname -dark.svg' => [
+ $createCallback(['test-dark.svg']),
+ '/path/test-dark.svg',
+ ],
+ 'only appname.svg' => [
+ $createCallback(['test.svg']),
+ '/path/test.svg',
+ ],
+ 'priotize custom over default' => [
+ $createCallback(['app.svg', 'test.svg']),
+ '/path/test.svg',
+ ],
+ 'priotize default over dark' => [
+ $createCallback(['test-dark.svg', 'app-dark.svg', 'app.svg']),
+ '/path/app.svg',
+ ],
+ 'priotize custom over default' => [
+ $createCallback(['test.svg', 'test-dark.svg', 'app-dark.svg']),
+ '/path/test.svg',
+ ],
+ ];
+ }
+
public function testEnableApp() {
// making sure "files_trashbin" is disabled
if ($this->manager->isEnabledForUser('files_trashbin')) {
@@ -170,9 +238,16 @@ 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->eventDispatcher,
+ $this->logger,
+ $this->urlGenerator,
])
- ->setMethods([
+ ->onlyMethods([
'getAppPath',
])
->getMock();
@@ -218,9 +293,16 @@ 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->eventDispatcher,
+ $this->logger,
+ $this->urlGenerator,
])
- ->setMethods([
+ ->onlyMethods([
'getAppPath',
'getAppInfo',
])
@@ -274,9 +356,16 @@ 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->eventDispatcher,
+ $this->logger,
+ $this->urlGenerator,
])
- ->setMethods([
+ ->onlyMethods([
'getAppPath',
'getAppInfo',
])
@@ -470,8 +559,17 @@ 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])
- ->setMethods(['getAppInfo'])
+ ->setConstructorArgs([
+ $this->userSession,
+ $this->config,
+ $this->appConfig,
+ $this->groupManager,
+ $this->cacheFactory,
+ $this->eventDispatcher,
+ $this->logger,
+ $this->urlGenerator,
+ ])
+ ->onlyMethods(['getAppInfo'])
->getMock();
$appInfos = [
@@ -521,8 +619,17 @@ 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])
- ->setMethods(['getAppInfo'])
+ ->setConstructorArgs([
+ $this->userSession,
+ $this->config,
+ $this->appConfig,
+ $this->groupManager,
+ $this->cacheFactory,
+ $this->eventDispatcher,
+ $this->logger,
+ $this->urlGenerator,
+ ])
+ ->onlyMethods(['getAppInfo'])
->getMock();
$appInfos = [
diff --git a/tests/lib/AppTest.php b/tests/lib/AppTest.php
index 12fbdb011d9..4e723e5d2f1 100644
--- a/tests/lib/AppTest.php
+++ b/tests/lib/AppTest.php
@@ -14,6 +14,8 @@ use OC\App\InfoParser;
use OC\AppConfig;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAppConfig;
+use OCP\IURLGenerator;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
/**
@@ -537,6 +539,7 @@ class AppTest extends \Test\TestCase {
private function setupAppConfigMock() {
+ /** @var AppConfig|MockObject */
$appConfig = $this->getMockBuilder(AppConfig::class)
->setMethods(['getValues'])
->setConstructorArgs([\OC::$server->getDatabaseConnection()])
@@ -561,7 +564,8 @@ class AppTest extends \Test\TestCase {
\OC::$server->getGroupManager(),
\OC::$server->getMemCacheFactory(),
\OC::$server->get(IEventDispatcher::class),
- \OC::$server->get(LoggerInterface::class)
+ \OC::$server->get(LoggerInterface::class),
+ \OC::$server->get(IURLGenerator::class),
));
}
diff --git a/tests/lib/NavigationManagerTest.php b/tests/lib/NavigationManagerTest.php
index 63160e78de7..beefc2353d6 100644
--- a/tests/lib/NavigationManagerTest.php
+++ b/tests/lib/NavigationManagerTest.php
@@ -224,19 +224,19 @@ class NavigationManagerTest extends TestCase {
->method('isEnabledForUser')
->with('theming')
->willReturn(true);
- $this->appManager->expects($this->once())->method('getAppInfo')->with('test')->willReturn($navigation);
- /*
+ $this->appManager->expects($this->once())
+ ->method('getAppInfo')
+ ->with('test')
+ ->willReturn($navigation);
+ $this->urlGenerator->expects($this->any())
+ ->method('imagePath')
+ ->willReturnCallback(function ($appName, $file) {
+ return "/apps/$appName/img/$file";
+ });
$this->appManager->expects($this->any())
- ->method('getAppInfo')
- ->will($this->returnValueMap([
- ['test', null, null, $navigation],
- ['theming', null, null, null],
- ]));
- */
+ ->method('getAppIcon')
+ ->willReturnCallback(fn (string $appName) => "/apps/$appName/img/app.svg");
$this->l10nFac->expects($this->any())->method('get')->willReturn($l);
- $this->urlGenerator->expects($this->any())->method('imagePath')->willReturnCallback(function ($appName, $file) {
- return "/apps/$appName/img/$file";
- });
$this->urlGenerator->expects($this->any())->method('linkToRoute')->willReturnCallback(function ($route) {
if ($route === 'core.login.logout') {
return 'https://example.com/logout';
@@ -534,6 +534,7 @@ class NavigationManagerTest extends TestCase {
->with('theming')
->willReturn(true);
$this->appManager->expects($this->once())->method('getAppInfo')->with('test')->willReturn($navigation);
+ $this->appManager->expects($this->once())->method('getAppIcon')->with('test')->willReturn('/apps/test/img/app.svg');
$this->l10nFac->expects($this->any())->method('get')->willReturn($l);
$this->urlGenerator->expects($this->any())->method('imagePath')->willReturnCallback(function ($appName, $file) {
return "/apps/$appName/img/$file";