aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/TemplateLayoutTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/TemplateLayoutTest.php')
-rw-r--r--tests/lib/TemplateLayoutTest.php57
1 files changed, 40 insertions, 17 deletions
diff --git a/tests/lib/TemplateLayoutTest.php b/tests/lib/TemplateLayoutTest.php
index 405f1df7330..b3895525408 100644
--- a/tests/lib/TemplateLayoutTest.php
+++ b/tests/lib/TemplateLayoutTest.php
@@ -14,50 +14,73 @@ use OC\TemplateLayout;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
+use OCP\INavigationManager;
+use OCP\ServerVersion;
+use OCP\Template\ITemplateManager;
+use PHPUnit\Framework\MockObject\MockObject;
class TemplateLayoutTest extends \Test\TestCase {
-
+ private IConfig&MockObject $config;
+ private IAppManager&MockObject $appManager;
+ private InitialStateService&MockObject $initialState;
+ private INavigationManager&MockObject $navigationManager;
+ private ITemplateManager&MockObject $templateManager;
+ private ServerVersion&MockObject $serverVersion;
+
+ private TemplateLayout $templateLayout;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->config = $this->createMock(IConfig::class);
+ $this->appManager = $this->createMock(IAppManager::class);
+ $this->initialState = $this->createMock(InitialStateService::class);
+ $this->navigationManager = $this->createMock(INavigationManager::class);
+ $this->templateManager = $this->createMock(ITemplateManager::class);
+ $this->serverVersion = $this->createMock(ServerVersion::class);
+ }
/** @dataProvider dataVersionHash */
public function testVersionHash($path, $file, $installed, $debug, $expected): void {
- $appManager = $this->createMock(IAppManager::class);
- $appManager->expects(self::any())
+ $this->appManager->expects(self::any())
->method('getAppVersion')
->willReturnCallback(fn ($appId) => match ($appId) {
'shippedApp' => 'shipped_1',
'otherApp' => 'other_2',
default => "$appId",
});
- $appManager->expects(self::any())
+ $this->appManager->expects(self::any())
->method('isShipped')
->willReturnCallback(fn (string $app) => $app === 'shippedApp');
- $config = $this->createMock(IConfig::class);
- $config->expects(self::atLeastOnce())
+ $this->config->expects(self::atLeastOnce())
->method('getSystemValueBool')
->willReturnMap([
['installed', false, $installed],
['debug', false, $debug],
]);
- $config->expects(self::any())
+ $this->config->expects(self::any())
->method('getAppValue')
->with('theming', 'cachebuster', '0')
->willReturn('42');
- $initialState = $this->createMock(InitialStateService::class);
-
- $this->overwriteService(IConfig::class, $config);
- $this->overwriteService(IAppManager::class, $appManager);
- $this->overwriteService(InitialStateService::class, $initialState);
-
- $layout = $this->getMockBuilder(TemplateLayout::class)
+ $this->templateLayout = $this->getMockBuilder(TemplateLayout::class)
->onlyMethods(['getAppNamefromPath'])
- ->setConstructorArgs([TemplateResponse::RENDER_AS_ERROR])
+ ->setConstructorArgs([
+ $this->config,
+ $this->appManager,
+ $this->initialState,
+ $this->navigationManager,
+ $this->templateManager,
+ $this->serverVersion,
+ ])
->getMock();
+ $layout = $this->templateLayout->getPageTemplate(TemplateResponse::RENDER_AS_ERROR, '');
+
self::invokePrivate(TemplateLayout::class, 'versionHash', ['version_hash']);
- $layout->expects(self::any())
+ $this->templateLayout->expects(self::any())
->method('getAppNamefromPath')
->willReturnCallback(fn ($appName) => match($appName) {
'apps/shipped' => 'shippedApp',
@@ -65,7 +88,7 @@ class TemplateLayoutTest extends \Test\TestCase {
default => false,
});
- $hash = self::invokePrivate($layout, 'getVersionHashSuffix', [$path, $file]);
+ $hash = self::invokePrivate($this->templateLayout, 'getVersionHashSuffix', [$path, $file]);
self::assertEquals($expected, $hash);
}