|
|
|
|
@ -14,50 +14,69 @@ use OC\TemplateLayout;
|
|
|
|
|
use OCP\App\IAppManager;
|
|
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
|
|
|
use OCP\IConfig;
|
|
|
|
|
use OCP\INavigationManager;
|
|
|
|
|
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 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @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,
|
|
|
|
|
])
|
|
|
|
|
->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 +84,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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|