mirror of
https://github.com/nextcloud/server.git
synced 2026-11-26 16:15:53 +01:00
The header search is now always the unified search. The `unified_search.enabled` system config is removed and `enable_non-accessible_features => false` no longer falls back to the legacy search, as the unified search is keyboard accessible by now. The `core` app config keys `unified-search.limit-default` and `unified-search.live-search` were only read by the legacy search and have no effect anymore. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
170 lines
5.8 KiB
PHP
170 lines
5.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
namespace Test;
|
|
|
|
use OC\App\AppStore\AppStoreLinkVisibility;
|
|
use OC\InitialStateService;
|
|
use OC\TemplateLayout;
|
|
use OCP\App\IAppManager;
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
use OCP\IAppConfig;
|
|
use OCP\IConfig;
|
|
use OCP\INavigationManager;
|
|
use OCP\IRequest;
|
|
use OCP\IUserSession;
|
|
use OCP\ServerVersion;
|
|
use OCP\Template\ITemplate;
|
|
use OCP\Template\ITemplateManager;
|
|
use OCP\Util;
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
class TemplateLayoutTest extends \Test\TestCase {
|
|
private IConfig&MockObject $config;
|
|
private IAppConfig&MockObject $appConfig;
|
|
private IAppManager&MockObject $appManager;
|
|
private InitialStateService&MockObject $initialState;
|
|
private INavigationManager&MockObject $navigationManager;
|
|
private ITemplateManager&MockObject $templateManager;
|
|
private ServerVersion&MockObject $serverVersion;
|
|
private IRequest&MockObject $request;
|
|
|
|
private TemplateLayout $templateLayout;
|
|
|
|
#[\Override]
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
|
|
$this->config = $this->createMock(IConfig::class);
|
|
$this->appConfig = $this->createMock(IAppConfig::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);
|
|
$this->request = $this->createMock(IRequest::class);
|
|
}
|
|
|
|
#[\Override]
|
|
protected function tearDown(): void {
|
|
\OC_Util::$styles = [];
|
|
self::invokePrivate(Util::class, 'scripts', [[]]);
|
|
parent::tearDown();
|
|
}
|
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('dataVersionHash')]
|
|
public function testVersionHash(
|
|
string $path,
|
|
string $file,
|
|
bool $installed,
|
|
bool $debug,
|
|
string $expected,
|
|
): void {
|
|
$this->appManager->expects(self::any())
|
|
->method('getAppVersion')
|
|
->willReturnCallback(fn ($appId) => match ($appId) {
|
|
'shipped' => 'shipped_1',
|
|
'other' => 'other_2',
|
|
default => "$appId",
|
|
});
|
|
$this->appManager->expects(self::any())
|
|
->method('isShipped')
|
|
->willReturnCallback(fn (string $app) => $app === 'shipped');
|
|
|
|
$this->config->expects(self::atLeastOnce())
|
|
->method('getSystemValueBool')
|
|
->willReturnMap([
|
|
['installed', $installed],
|
|
['debug', $debug],
|
|
]);
|
|
$this->config->expects(self::any())
|
|
->method('getAppValue')
|
|
->with('theming', 'cachebuster', '0')
|
|
->willReturn('42');
|
|
|
|
$this->request->method('getPathInfo')
|
|
->willReturn('/' . $path);
|
|
|
|
$this->templateLayout = new TemplateLayout(
|
|
$this->config,
|
|
$this->appConfig,
|
|
$this->appManager,
|
|
$this->initialState,
|
|
$this->navigationManager,
|
|
$this->templateManager,
|
|
$this->serverVersion,
|
|
$this->request,
|
|
);
|
|
|
|
$layout = $this->templateLayout->getPageTemplate(TemplateResponse::RENDER_AS_ERROR, '');
|
|
|
|
self::invokePrivate($this->templateLayout, 'versionHash', ['version_hash']);
|
|
|
|
$hash = self::invokePrivate($this->templateLayout, 'getVersionHashSuffix', [$path, $file]);
|
|
self::assertEquals($expected, $hash);
|
|
}
|
|
|
|
public static function dataVersionHash() {
|
|
return [
|
|
'no hash if in debug mode' => ['apps/shipped', 'style.css', true, true, ''],
|
|
'only version hash if not installed' => ['apps/shipped', 'style.css', false, false, '?v=version_hash'],
|
|
'version hash with cache buster if neither path nor file provided' => ['', '', true, false, '?v=version_hash-42'],
|
|
'app version hash if external app' => ['apps/other', 'app.css', true, false, '?v=' . substr(md5('other_2'), 0, 8) . '-42'],
|
|
'app version and version hash if shipped app' => ['apps/shipped', 'style.css', true, false, '?v=' . substr(md5('shipped_1-version_hash'), 0, 8) . '-42'],
|
|
'prefer path over file' => ['apps/shipped', 'other/app.css', true, false, '?v=' . substr(md5('shipped_1-version_hash'), 0, 8) . '-42'],
|
|
];
|
|
}
|
|
|
|
public static function dataUserLayoutLoadsUnifiedSearch(): array {
|
|
return [
|
|
'default configuration' => [[]],
|
|
'non-accessible features disabled' => [['enable_non-accessible_features' => false]],
|
|
'removed legacy switch still set' => [['unified_search.enabled' => true]],
|
|
];
|
|
}
|
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('dataUserLayoutLoadsUnifiedSearch')]
|
|
public function testUserLayoutLoadsUnifiedSearch(array $systemConfig): void {
|
|
\OC_Util::$styles = [];
|
|
self::invokePrivate(Util::class, 'scripts', [[]]);
|
|
|
|
$this->overwriteService(AppStoreLinkVisibility::class, $this->createMock(AppStoreLinkVisibility::class));
|
|
$this->overwriteService(IUserSession::class, $this->createMock(IUserSession::class));
|
|
|
|
$this->config->method('getSystemValueBool')
|
|
->willReturnCallback(fn (string $key, bool $default) => $systemConfig[$key] ?? ($key === 'installed' ? false : $default));
|
|
$this->config->method('getSystemValueString')
|
|
->willReturnArgument(1);
|
|
$this->request->method('getPathInfo')
|
|
->willReturn('/apps/files/');
|
|
$this->navigationManager->method('getAll')
|
|
->willReturn([]);
|
|
$this->templateManager->method('getTemplate')
|
|
->willReturn($this->createMock(ITemplate::class));
|
|
|
|
$templateLayout = new TemplateLayout(
|
|
$this->config,
|
|
$this->appConfig,
|
|
$this->appManager,
|
|
$this->initialState,
|
|
$this->navigationManager,
|
|
$this->templateManager,
|
|
$this->serverVersion,
|
|
$this->request,
|
|
);
|
|
$templateLayout->getPageTemplate(TemplateResponse::RENDER_AS_USER, '');
|
|
|
|
$scripts = Util::getScripts();
|
|
self::assertContains('core/js/unified-search', $scripts);
|
|
self::assertNotContains('core/js/legacy-unified-search', $scripts);
|
|
self::assertContains('core/css/unified-search', \OC_Util::$styles);
|
|
self::assertNotContains('core/css/legacy-unified-search', \OC_Util::$styles);
|
|
}
|
|
}
|