themingDefaults = $this->createMock(ThemingDefaults::class); $this->userSession = $this->createMock(IUserSession::class); $this->imageManager = $this->createMock(ImageManager::class); $this->config = $this->createMock(IConfig::class); $this->l10n = $this->createMock(IL10N::class); $this->appManager = $this->createMock(IAppManager::class); $util = new Util( $this->createMock(ServerVersion::class), $this->config, $this->appManager, $this->createMock(IAppData::class), $this->imageManager ); $userSession = $this->createMock(IUserSession::class); $cacheFactory = $this->createMock(ICacheFactory::class); $request = $this->createMock(IRequest::class); $router = $this->createMock(Router::class); $this->urlGenerator = new URLGenerator( $this->config, $userSession, $cacheFactory, $request, $router ); $this->themingDefaults ->expects($this->any()) ->method('getColorPrimary') ->willReturn('#0082c9'); $this->themingDefaults ->expects($this->any()) ->method('getDefaultColorPrimary') ->willReturn('#0082c9'); $this->themingDefaults ->expects($this->any()) ->method('getColorBackground') ->willReturn('#0082c9'); $this->themingDefaults ->expects($this->any()) ->method('getDefaultColorBackground') ->willReturn('#0082c9'); $this->l10n ->expects($this->any()) ->method('t') ->willReturnCallback(function ($text, $parameters = []) { return vsprintf($text, $parameters); }); $this->dyslexiaFont = new DyslexiaFont( $util, $this->themingDefaults, $this->userSession, $this->urlGenerator, $this->imageManager, $this->config, $this->l10n, $this->appManager, null, ); parent::setUp(); } public function testGetId(): void { $this->assertEquals('opendyslexic', $this->dyslexiaFont->getId()); } public function testGetType(): void { $this->assertEquals(ITheme::TYPE_FONT, $this->dyslexiaFont->getType()); } public function testGetTitle(): void { $this->assertNotEmpty($this->dyslexiaFont->getTitle()); } public function testGetEnableLabel(): void { $this->assertNotEmpty($this->dyslexiaFont->getEnableLabel()); } public function testGetDescription(): void { $this->assertNotEmpty($this->dyslexiaFont->getDescription()); } public function testGetMediaQuery(): void { $this->assertEquals('', $this->dyslexiaFont->getMediaQuery()); } public function testGetCSSVariables(): void { $this->assertStringStartsWith('OpenDyslexic', $this->dyslexiaFont->getCSSVariables()['--font-face']); } public function dataTestGetCustomCss() { return [ ['', true], ['', false], ['/subfolder', true], ['/subfolder', false], ]; } /** * @dataProvider dataTestGetCustomCss * * Ensure the fonts are always loaded from the web root * despite having url rewriting enabled or not * * @param string $webRoot * @param bool $prettyUrlsEnabled */ public function testGetCustomCss($webRoot, $prettyUrlsEnabled): void { \OC::$WEBROOT = $webRoot; $this->config->expects($this->any()) ->method('getSystemValue') ->with('htaccess.IgnoreFrontController', false) ->willReturn($prettyUrlsEnabled); $this->assertStringContainsString("'$webRoot/apps/theming/fonts/OpenDyslexic-Regular.otf'", $this->dyslexiaFont->getCustomCss()); $this->assertStringNotContainsString('index.php', $this->dyslexiaFont->getCustomCss()); } }