diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-01-24 12:52:33 +0100 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-01-29 08:37:33 +0100 |
commit | ef015a99d20d90d5e52038634e7cb44cefcce621 (patch) | |
tree | 529da657c42f1c14248cf8f8d3142d9295276bb3 | |
parent | 6856af875fad0a0f1b5f2da43aa1cfd947bf1985 (diff) | |
download | nextcloud-server-ef015a99d20d90d5e52038634e7cb44cefcce621.tar.gz nextcloud-server-ef015a99d20d90d5e52038634e7cb44cefcce621.zip |
fix: Correctly return app id and app version for `core` styles and images
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r-- | lib/private/App/AppManager.php | 10 | ||||
-rw-r--r-- | lib/private/Server.php | 1 | ||||
-rw-r--r-- | lib/private/TemplateLayout.php | 2 | ||||
-rw-r--r-- | tests/lib/App/AppManagerTest.php | 111 |
4 files changed, 122 insertions, 2 deletions
diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index 2f129ca77fa..6fa7264cac2 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -27,6 +27,7 @@ use OCP\IGroupManager; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserSession; +use OCP\ServerVersion; use OCP\Settings\IManager as ISettingsManager; use Psr\Log\LoggerInterface; @@ -79,6 +80,7 @@ class AppManager implements IAppManager { private ICacheFactory $memCacheFactory, private IEventDispatcher $dispatcher, private LoggerInterface $logger, + private ServerVersion $serverVersion, ) { } @@ -736,8 +738,12 @@ class AppManager implements IAppManager { public function getAppVersion(string $appId, bool $useCache = true): string { if (!$useCache || !isset($this->appVersions[$appId])) { - $appInfo = $this->getAppInfo($appId); - $this->appVersions[$appId] = ($appInfo !== null && isset($appInfo['version'])) ? $appInfo['version'] : '0'; + if ($appId === 'core') { + $this->appVersions[$appId] = $this->serverVersion->getVersionString(); + } else { + $appInfo = $this->getAppInfo($appId); + $this->appVersions[$appId] = ($appInfo !== null && isset($appInfo['version'])) ? $appInfo['version'] : '0'; + } } return $this->appVersions[$appId]; } diff --git a/lib/private/Server.php b/lib/private/Server.php index 2ba8eed8aea..b0137d2dd69 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -861,6 +861,7 @@ class Server extends ServerContainer implements IServerContainer { $c->get(ICacheFactory::class), $c->get(IEventDispatcher::class), $c->get(LoggerInterface::class), + $c->get(ServerVersion::class), ); }); /** @deprecated 19.0.0 */ diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 8b97165aed7..127af988de7 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -376,6 +376,8 @@ class TemplateLayout extends \OC_Template { if ($pathParts[0] === 'css') { // This is a scss request return $pathParts[1]; + } elseif ($pathParts[0] === 'core') { + return 'core'; } return end($pathParts); } diff --git a/tests/lib/App/AppManagerTest.php b/tests/lib/App/AppManagerTest.php index 03c9d474c55..7546679dc9e 100644 --- a/tests/lib/App/AppManagerTest.php +++ b/tests/lib/App/AppManagerTest.php @@ -25,6 +25,7 @@ use OCP\IGroupManager; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserSession; +use OCP\ServerVersion; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use Test\TestCase; @@ -100,6 +101,8 @@ class AppManagerTest extends TestCase { protected IURLGenerator&MockObject $urlGenerator; + protected ServerVersion&MockObject $serverVersion; + /** @var IAppManager */ protected $manager; @@ -115,6 +118,7 @@ class AppManagerTest extends TestCase { $this->eventDispatcher = $this->createMock(IEventDispatcher::class); $this->logger = $this->createMock(LoggerInterface::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->serverVersion = $this->createMock(ServerVersion::class); $this->overwriteService(AppConfig::class, $this->appConfig); $this->overwriteService(IURLGenerator::class, $this->urlGenerator); @@ -136,9 +140,18 @@ class AppManagerTest extends TestCase { $this->cacheFactory, $this->eventDispatcher, $this->logger, + $this->serverVersion, ); } + protected function tearDown(): void { + parent::tearDown(); + + // Reset static OC_Util + $util = new \OC_Util(); + self::invokePrivate($util, 'versionCache', [null]); + } + /** * @dataProvider dataGetAppIcon */ @@ -278,6 +291,7 @@ class AppManagerTest extends TestCase { $this->cacheFactory, $this->eventDispatcher, $this->logger, + $this->serverVersion, ]) ->onlyMethods([ 'getAppPath', @@ -331,6 +345,7 @@ class AppManagerTest extends TestCase { $this->cacheFactory, $this->eventDispatcher, $this->logger, + $this->serverVersion, ]) ->onlyMethods([ 'getAppPath', @@ -392,6 +407,7 @@ class AppManagerTest extends TestCase { $this->cacheFactory, $this->eventDispatcher, $this->logger, + $this->serverVersion, ]) ->onlyMethods([ 'getAppPath', @@ -594,6 +610,7 @@ class AppManagerTest extends TestCase { $this->cacheFactory, $this->eventDispatcher, $this->logger, + $this->serverVersion, ]) ->onlyMethods(['getAppInfo']) ->getMock(); @@ -652,6 +669,7 @@ class AppManagerTest extends TestCase { $this->cacheFactory, $this->eventDispatcher, $this->logger, + $this->serverVersion, ]) ->onlyMethods(['getAppInfo']) ->getMock(); @@ -933,4 +951,97 @@ class AppManagerTest extends TestCase { $this->assertEquals($expected, $this->manager->isBackendRequired($backend)); } + + public function testGetAppVersion() { + $manager = $this->getMockBuilder(AppManager::class) + ->setConstructorArgs([ + $this->userSession, + $this->config, + $this->groupManager, + $this->cacheFactory, + $this->eventDispatcher, + $this->logger, + $this->serverVersion, + ]) + ->onlyMethods([ + 'getAppInfo', + ]) + ->getMock(); + + $manager->expects(self::once()) + ->method('getAppInfo') + ->with('myapp') + ->willReturn(['version' => '99.99.99-rc.99']); + + $this->serverVersion + ->expects(self::never()) + ->method('getVersionString'); + + $this->assertEquals( + '99.99.99-rc.99', + $manager->getAppVersion('myapp'), + ); + } + + public function testGetAppVersionCore() { + $manager = $this->getMockBuilder(AppManager::class) + ->setConstructorArgs([ + $this->userSession, + $this->config, + $this->groupManager, + $this->cacheFactory, + $this->eventDispatcher, + $this->logger, + $this->serverVersion, + ]) + ->onlyMethods([ + 'getAppInfo', + ]) + ->getMock(); + + $manager->expects(self::never()) + ->method('getAppInfo'); + + $this->serverVersion + ->expects(self::once()) + ->method('getVersionString') + ->willReturn('1.2.3-beta.4'); + + $this->assertEquals( + '1.2.3-beta.4', + $manager->getAppVersion('core'), + ); + } + + public function testGetAppVersionUnknown() { + $manager = $this->getMockBuilder(AppManager::class) + ->setConstructorArgs([ + $this->userSession, + $this->config, + $this->groupManager, + $this->cacheFactory, + $this->eventDispatcher, + $this->logger, + $this->serverVersion, + ]) + ->onlyMethods([ + 'getAppInfo', + ]) + ->getMock(); + + $manager->expects(self::once()) + ->method('getAppInfo') + ->with('unknown') + ->willReturn(null); + + $this->serverVersion + ->expects(self::never()) + ->method('getVersionString'); + + $this->assertEquals( + '0', + $manager->getAppVersion('unknown'), + ); + } + } |