summaryrefslogtreecommitdiffstats
path: root/apps/theming
diff options
context:
space:
mode:
authorJulius Haertl <jus@bitgrid.net>2016-07-15 14:04:19 +0200
committerJulius Haertl <jus@bitgrid.net>2016-07-15 14:16:41 +0200
commit639be661c43c433b734f088c9ad123372f09e8d9 (patch)
tree4ede14ad4fd27fc33a9c897dca332fa6c5f394b9 /apps/theming
parent387550be88046bfe4f6098f7eaaba319b6a623b5 (diff)
downloadnextcloud-server-639be661c43c433b734f088c9ad123372f09e8d9.tar.gz
nextcloud-server-639be661c43c433b734f088c9ad123372f09e8d9.zip
Theming: Add tests for inverted colors
Diffstat (limited to 'apps/theming')
-rw-r--r--apps/theming/tests/lib/UtilTest.php66
-rw-r--r--apps/theming/tests/lib/controller/ThemingControllerTest.php67
2 files changed, 130 insertions, 3 deletions
diff --git a/apps/theming/tests/lib/UtilTest.php b/apps/theming/tests/lib/UtilTest.php
new file mode 100644
index 00000000000..266e6fc6c2d
--- /dev/null
+++ b/apps/theming/tests/lib/UtilTest.php
@@ -0,0 +1,66 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
+ *
+ * @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;
+
+use OCA\Theming\Util;
+use Test\TestCase;
+
+class UtilTest extends TestCase {
+
+ public function testInvertTextColorLight() {
+ $invert = Util::invertTextColor('#ffffff');
+ $this->assertEquals(true, $invert);
+ }
+
+ public function testInvertTextColorDark() {
+ $invert = Util::invertTextColor('#000000');
+ $this->assertEquals(false, $invert);
+ }
+
+ public function testCalculateLuminanceLight() {
+ $luminance = Util::calculateLuminance('#ffffff');
+ $this->assertEquals(1, $luminance);
+ }
+
+ public function testCalculateLuminanceDark() {
+ $luminance = Util::calculateLuminance('#000000');
+ $this->assertEquals(0, $luminance);
+ }
+
+ public function testCalculateLuminanceLightShorthand() {
+ $luminance = Util::calculateLuminance('#fff');
+ $this->assertEquals(1, $luminance);
+ }
+
+ public function testCalculateLuminanceDarkShorthand() {
+ $luminance = Util::calculateLuminance('#000');
+ $this->assertEquals(0, $luminance);
+ }
+ public function testInvertTextColorInvalid() {
+ $invert = Util::invertTextColor('aaabbbcccddd123');
+ $this->assertEquals(false, $invert);
+ }
+
+ public function testInvertTextColorEmpty() {
+ $invert = Util::invertTextColor('');
+ $this->assertEquals(false, $invert);
+ }
+}
diff --git a/apps/theming/tests/lib/controller/ThemingControllerTest.php b/apps/theming/tests/lib/controller/ThemingControllerTest.php
index d08ebce8663..0975fc1459e 100644
--- a/apps/theming/tests/lib/controller/ThemingControllerTest.php
+++ b/apps/theming/tests/lib/controller/ThemingControllerTest.php
@@ -311,6 +311,33 @@ class ThemingControllerTest extends TestCase {
->expects($this->at(1))
->method('getAppValue')
->with('theming', 'color', '')
+ ->willReturn('#000');
+ $this->config
+ ->expects($this->at(2))
+ ->method('getAppValue')
+ ->with('theming', 'logoMime', '')
+ ->willReturn('');
+ $this->config
+ ->expects($this->at(3))
+ ->method('getAppValue')
+ ->with('theming', 'backgroundMime', '')
+ ->willReturn('');
+
+ $expected = new Http\DataDownloadResponse('#body-user #header,#body-settings #header,#body-public #header {background-color: #000}', 'style', 'text/css');
+ $expected->cacheFor(3600);
+ @$this->assertEquals($expected, $this->themingController->getStylesheet());
+ }
+
+ public function testGetStylesheetWithOnlyColorInvert() {
+ $this->config
+ ->expects($this->at(0))
+ ->method('getAppValue')
+ ->with('theming', 'cachebuster', '0')
+ ->willReturn('0');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getAppValue')
+ ->with('theming', 'color', '')
->willReturn('#fff');
$this->config
->expects($this->at(2))
@@ -323,7 +350,7 @@ class ThemingControllerTest extends TestCase {
->with('theming', 'backgroundMime', '')
->willReturn('');
- $expected = new Http\DataDownloadResponse('#body-user #header,#body-settings #header,#body-public #header {background-color: #fff}', 'style', 'text/css');
+ $expected = new Http\DataDownloadResponse('#body-user #header,#body-settings #header,#body-public #header {background-color: #fff}#header .header-appname, #expandDisplayName { color: #000000; } #header .icon-caret { background-image: url(/core/img/actions/caret-dark.svg); } .searchbox input[type="search"] { background: transparent url(\'../../../core/img/actions/search.svg\') no-repeat 6px center; color: #000; }.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid { color: #000; border: 1px solid rgba(0, 0, 0, .5); }', 'style', 'text/css');
$expected->cacheFor(3600);
@$this->assertEquals($expected, $this->themingController->getStylesheet());
}
@@ -400,7 +427,7 @@ class ThemingControllerTest extends TestCase {
->expects($this->at(1))
->method('getAppValue')
->with('theming', 'color', '')
- ->willReturn('#abc');
+ ->willReturn('#000');
$this->config
->expects($this->at(2))
->method('getAppValue')
@@ -412,7 +439,7 @@ class ThemingControllerTest extends TestCase {
->with('theming', 'backgroundMime', '')
->willReturn('image/png');
- $expected = new Http\DataDownloadResponse('#body-user #header,#body-settings #header,#body-public #header {background-color: #abc}#header .logo {
+ $expected = new Http\DataDownloadResponse('#body-user #header,#body-settings #header,#body-public #header {background-color: #000}#header .logo {
background-image: url(\'./logo?v=0\');
}
#header .logo-icon {
@@ -424,5 +451,39 @@ class ThemingControllerTest extends TestCase {
$expected->cacheFor(3600);
@$this->assertEquals($expected, $this->themingController->getStylesheet());
}
+ public function testGetStylesheetWithAllCombinedInverted() {
+ $this->config
+ ->expects($this->at(0))
+ ->method('getAppValue')
+ ->with('theming', 'cachebuster', '0')
+ ->willReturn('0');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getAppValue')
+ ->with('theming', 'color', '')
+ ->willReturn('#fff');
+ $this->config
+ ->expects($this->at(2))
+ ->method('getAppValue')
+ ->with('theming', 'logoMime', '')
+ ->willReturn('text/svg');
+ $this->config
+ ->expects($this->at(3))
+ ->method('getAppValue')
+ ->with('theming', 'backgroundMime', '')
+ ->willReturn('image/png');
+
+ $expected = new Http\DataDownloadResponse('#body-user #header,#body-settings #header,#body-public #header {background-color: #fff}#header .logo {
+ background-image: url(\'./logo?v=0\');
+ }
+ #header .logo-icon {
+ background-image: url(\'./logo?v=0\');
+ background-size: 62px 34px;
+ }#body-login {
+ background-image: url(\'./loginbackground?v=0\');
+ }#header .header-appname, #expandDisplayName { color: #000000; } #header .icon-caret { background-image: url(/core/img/actions/caret-dark.svg); } .searchbox input[type="search"] { background: transparent url(\'../../../core/img/actions/search.svg\') no-repeat 6px center; color: #000; }.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid { color: #000; border: 1px solid rgba(0, 0, 0, .5); }', 'style', 'text/css');
+ $expected->cacheFor(3600);
+ @$this->assertEquals($expected, $this->themingController->getStylesheet());
+ }
}