Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon L <szaimen@e.mail.de>2022-04-22 17:30:56 +0300
committerGitHub <noreply@github.com>2022-04-22 17:30:56 +0300
commita40db94dff6832b96be8d157fcfbf5c9d3c3ba95 (patch)
treea68caa07615d284b826351bb9543047760229ddc
parentcfc1c21a80c90f8668846ed528f7b4355cbb6c24 (diff)
parentf7f4d36a372a7eb97debb0c2fd08615c754bd260 (diff)
Merge pull request #32073 from nextcloud/fix/DyslexiaFont-theme
Fix dyslexia font loading
-rw-r--r--apps/theming/lib/Themes/DyslexiaFont.php19
-rw-r--r--apps/theming/tests/Controller/UserThemeControllerTest.php13
-rw-r--r--apps/theming/tests/Service/ThemesServiceTest.php13
-rw-r--r--apps/theming/tests/Themes/DefaultThemeTest.php13
-rw-r--r--apps/theming/tests/Themes/DyslexiaFontTest.php162
5 files changed, 178 insertions, 42 deletions
diff --git a/apps/theming/lib/Themes/DyslexiaFont.php b/apps/theming/lib/Themes/DyslexiaFont.php
index 50284d33b9d..2629ac588c6 100644
--- a/apps/theming/lib/Themes/DyslexiaFont.php
+++ b/apps/theming/lib/Themes/DyslexiaFont.php
@@ -60,23 +60,30 @@ class DyslexiaFont extends DefaultTheme implements ITheme {
}
public function getCustomCss(): string {
+ $fontPathWoff = $this->urlGenerator->linkTo('theming', 'fonts/OpenDyslexic-Regular.woff');
+ $fontPathOtf = $this->urlGenerator->linkTo('theming', 'fonts/OpenDyslexic-Regular.otf');
+ $fontPathTtf = $this->urlGenerator->linkTo('theming', 'fonts/OpenDyslexic-Regular.ttf');
+ $boldFontPathWoff = $this->urlGenerator->linkTo('theming', 'fonts/OpenDyslexic-Bold.woff');
+ $boldFontPathOtf = $this->urlGenerator->linkTo('theming', 'fonts/OpenDyslexic-Bold.otf');
+ $boldFontPathTtf = $this->urlGenerator->linkTo('theming', 'fonts/OpenDyslexic-Bold.ttf');
+
return "
@font-face {
font-family: 'OpenDyslexic';
font-style: normal;
font-weight: 400;
- src: url('../fonts/OpenDyslexic-Regular.woff') format('woff'),
- url('../fonts/OpenDyslexic-Regular.otf') format('opentype'),
- url('../fonts/OpenDyslexic-Regular.ttf') format('truetype');
+ src: url('$fontPathWoff') format('woff'),
+ url('$fontPathOtf') format('opentype'),
+ url('$fontPathTtf') format('truetype');
}
@font-face {
font-family: 'OpenDyslexic';
font-style: normal;
font-weight: 700;
- src: url('../fonts/OpenDyslexic-Bold.woff') format('woff'),
- url('../fonts/OpenDyslexic-Bold.otf') format('opentype'),
- url('../fonts/OpenDyslexic-Bold.ttf') format('truetype');
+ src: url('$boldFontPathWoff') format('woff'),
+ url('$boldFontPathOtf') format('opentype'),
+ url('$boldFontPathTtf') format('truetype');
}
";
}
diff --git a/apps/theming/tests/Controller/UserThemeControllerTest.php b/apps/theming/tests/Controller/UserThemeControllerTest.php
index 99e36938e74..b925085bf41 100644
--- a/apps/theming/tests/Controller/UserThemeControllerTest.php
+++ b/apps/theming/tests/Controller/UserThemeControllerTest.php
@@ -1,19 +1,8 @@
<?php
/**
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
+ * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
*
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Daniel Calviño Sánchez <danxuliu@gmail.com>
- * @author Joas Schilling <coding@schilljs.com>
* @author John Molakvoæ <skjnldsv@protonmail.com>
- * @author Julius Haertl <jus@bitgrid.net>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Kyle Fazzari <kyrofa@ubuntu.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Michael Weimann <mail@michael-weimann.eu>
- * @author rakekniven <mark.ziegler@rakekniven.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
diff --git a/apps/theming/tests/Service/ThemesServiceTest.php b/apps/theming/tests/Service/ThemesServiceTest.php
index 2d0d313f9e4..56f96d29637 100644
--- a/apps/theming/tests/Service/ThemesServiceTest.php
+++ b/apps/theming/tests/Service/ThemesServiceTest.php
@@ -1,19 +1,8 @@
<?php
/**
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
+ * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
*
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Daniel Calviño Sánchez <danxuliu@gmail.com>
- * @author Joas Schilling <coding@schilljs.com>
* @author John Molakvoæ <skjnldsv@protonmail.com>
- * @author Julius Haertl <jus@bitgrid.net>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Kyle Fazzari <kyrofa@ubuntu.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Michael Weimann <mail@michael-weimann.eu>
- * @author rakekniven <mark.ziegler@rakekniven.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
diff --git a/apps/theming/tests/Themes/DefaultThemeTest.php b/apps/theming/tests/Themes/DefaultThemeTest.php
index d3494b1c304..486e7c7a1e5 100644
--- a/apps/theming/tests/Themes/DefaultThemeTest.php
+++ b/apps/theming/tests/Themes/DefaultThemeTest.php
@@ -1,19 +1,8 @@
<?php
/**
- * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
+ * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
*
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Daniel Calviño Sánchez <danxuliu@gmail.com>
- * @author Joas Schilling <coding@schilljs.com>
* @author John Molakvoæ <skjnldsv@protonmail.com>
- * @author Julius Haertl <jus@bitgrid.net>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Kyle Fazzari <kyrofa@ubuntu.com>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Michael Weimann <mail@michael-weimann.eu>
- * @author rakekniven <mark.ziegler@rakekniven.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
diff --git a/apps/theming/tests/Themes/DyslexiaFontTest.php b/apps/theming/tests/Themes/DyslexiaFontTest.php
new file mode 100644
index 00000000000..30472aeb6f2
--- /dev/null
+++ b/apps/theming/tests/Themes/DyslexiaFontTest.php
@@ -0,0 +1,162 @@
+<?php
+/**
+ * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OCA\Theming\Tests\Service;
+
+use OC\App\AppManager;
+use OC\Route\Router;
+use OCA\Theming\ImageManager;
+use OCA\Theming\ITheme;
+use OCA\Theming\Themes\DyslexiaFont;
+use OCA\Theming\ThemingDefaults;
+use OCA\Theming\Util;
+use OCP\Files\IAppData;
+use OCP\ICacheFactory;
+use OCP\IConfig;
+use OCP\IL10N;
+use OCP\IRequest;
+use OCP\IURLGenerator;
+use OCP\IUserSession;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+
+class DyslexiaFontTest extends TestCase {
+ /** @var ThemingDefaults|MockObject */
+ private $themingDefaults;
+ /** @var IURLGenerator|MockObject */
+ private $urlGenerator;
+ /** @var ImageManager|MockObject */
+ private $imageManager;
+ /** @var IConfig|MockObject */
+ private $config;
+ /** @var IL10N|MockObject */
+ private $l10n;
+
+ private DyslexiaFont $dyslexiaFont;
+
+ protected function setUp(): void {
+ $this->themingDefaults = $this->createMock(ThemingDefaults::class);
+ $this->imageManager = $this->createMock(ImageManager::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->l10n = $this->createMock(IL10N::class);
+
+ $util = new Util(
+ $this->config,
+ $this->createMock(AppManager::class),
+ $this->createMock(IAppData::class)
+ );
+
+ $userSession = $this->createMock(IUserSession::class);
+ $cacheFactory = $this->createMock(ICacheFactory::class);
+ $request = $this->createMock(IRequest::class);
+ $router = $this->createMock(Router::class);
+ $this->urlGenerator = new \OC\URLGenerator(
+ $this->config,
+ $userSession,
+ $cacheFactory,
+ $request,
+ $router
+ );
+
+ $this->themingDefaults
+ ->expects($this->any())
+ ->method('getColorPrimary')
+ ->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->urlGenerator,
+ $this->imageManager,
+ $this->config,
+ $this->l10n,
+ );
+
+ parent::setUp();
+ }
+
+
+ public function testGetId() {
+ $this->assertEquals('opendyslexic', $this->dyslexiaFont->getId());
+ }
+
+ public function testGetType() {
+ $this->assertEquals(ITheme::TYPE_FONT, $this->dyslexiaFont->getType());
+ }
+
+ public function testGetTitle() {
+ $this->assertNotEmpty($this->dyslexiaFont->getTitle());
+ }
+
+ public function testGetEnableLabel() {
+ $this->assertNotEmpty($this->dyslexiaFont->getEnableLabel());
+ }
+
+ public function testGetDescription() {
+ $this->assertNotEmpty($this->dyslexiaFont->getDescription());
+ }
+
+ public function testGetMediaQuery() {
+ $this->assertEquals('', $this->dyslexiaFont->getMediaQuery());
+ }
+
+ public function testGetCSSVariables() {
+ $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) {
+ \OC::$WEBROOT = $webRoot;
+ $this->config->expects($this->any())
+ ->method('getSystemValue')
+ ->with('htaccess.IgnoreFrontController', false)
+ ->willReturn($prettyUrlsEnabled);
+
+ $this->assertStringContainsString("'$webRoot/apps/theming/fonts/OpenDyslexic-Regular.woff'", $this->dyslexiaFont->getCustomCss());
+ $this->assertStringNotContainsString('index.php', $this->dyslexiaFont->getCustomCss());
+ }
+}