aboutsummaryrefslogtreecommitdiffstats
path: root/apps/theming
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-01-20 07:43:04 +0100
committerFerdinand Thiessen <opensource@fthiessen.de>2024-05-21 20:36:21 +0200
commit0ef3147ea01dfe2c9b6c22080d765486199d02f8 (patch)
tree2dbdb3d8e85d379b898365849da8342559c55134 /apps/theming
parent282f1b1faba5c3d4a27fc6254badd9e75864e225 (diff)
downloadnextcloud-server-0ef3147ea01dfe2c9b6c22080d765486199d02f8.tar.gz
nextcloud-server-0ef3147ea01dfe2c9b6c22080d765486199d02f8.zip
fix(tests): Adjust theming test for new splitted background and primary colors
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps/theming')
-rw-r--r--apps/theming/css/default.css4
-rw-r--r--apps/theming/lib/Capabilities.php1
-rw-r--r--apps/theming/tests/CapabilitiesTest.php39
-rw-r--r--apps/theming/tests/Controller/ThemingControllerTest.php21
-rw-r--r--apps/theming/tests/ImageManagerTest.php7
-rw-r--r--apps/theming/tests/Themes/DarkHighContrastThemeTest.php8
-rw-r--r--apps/theming/tests/Themes/DarkThemeTest.php8
-rw-r--r--apps/theming/tests/Themes/DefaultThemeTest.php16
-rw-r--r--apps/theming/tests/Themes/DyslexiaFontTest.php10
-rw-r--r--apps/theming/tests/Themes/HighContrastThemeTest.php8
-rw-r--r--apps/theming/tests/ThemingDefaultsTest.php200
11 files changed, 200 insertions, 122 deletions
diff --git a/apps/theming/css/default.css b/apps/theming/css/default.css
index f1b85b80ab9..611017f6408 100644
--- a/apps/theming/css/default.css
+++ b/apps/theming/css/default.css
@@ -85,7 +85,7 @@
--color-primary-element-light-hover: #dbe4ea;
--color-primary-element-light-text: #00293f;
--gradient-primary-background: linear-gradient(40deg, var(--color-primary) 0%, var(--color-primary-hover) 100%);
- --image-background-default: url('/apps/theming/img/background/kamil-porembinski-clouds.jpg');
- --color-background-plain: #0082c9;
+ --color-background-plain: #00679e;
--color-background-plain-text: #ffffff;
+ --image-background-default: url('/apps/theming/img/background/kamil-porembinski-clouds.jpg');
}
diff --git a/apps/theming/lib/Capabilities.php b/apps/theming/lib/Capabilities.php
index 7131607e016..6a9d11a4e9b 100644
--- a/apps/theming/lib/Capabilities.php
+++ b/apps/theming/lib/Capabilities.php
@@ -85,6 +85,7 @@ class Capabilities implements IPublicCapability {
* color-element-dark: string,
* logo: string,
* background: string,
+ * background-text: string,
* background-plain: bool,
* background-default: bool,
* logoheader: string,
diff --git a/apps/theming/tests/CapabilitiesTest.php b/apps/theming/tests/CapabilitiesTest.php
index 566380b3237..db8ccb82391 100644
--- a/apps/theming/tests/CapabilitiesTest.php
+++ b/apps/theming/tests/CapabilitiesTest.php
@@ -37,6 +37,7 @@ use OCP\Files\IAppData;
use OCP\IConfig;
use OCP\IURLGenerator;
use OCP\IUserSession;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
/**
@@ -45,16 +46,16 @@ use Test\TestCase;
* @package OCA\Theming\Tests
*/
class CapabilitiesTest extends TestCase {
- /** @var ThemingDefaults|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var ThemingDefaults|MockObject */
protected $theming;
- /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IURLGenerator|MockObject */
protected $url;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IConfig|MockObject */
protected $config;
- /** @var Util|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var Util|MockObject */
protected $util;
protected IUserSession $userSession;
@@ -66,16 +67,22 @@ class CapabilitiesTest extends TestCase {
parent::setUp();
$this->theming = $this->createMock(ThemingDefaults::class);
- $this->url = $this->getMockBuilder(IURLGenerator::class)->getMock();
+ $this->url = $this->createMock(IURLGenerator::class);
$this->config = $this->createMock(IConfig::class);
$this->util = $this->createMock(Util::class);
$this->userSession = $this->createMock(IUserSession::class);
- $this->capabilities = new Capabilities($this->theming, $this->util, $this->url, $this->config, $this->userSession);
+ $this->capabilities = new Capabilities(
+ $this->theming,
+ $this->util,
+ $this->url,
+ $this->config,
+ $this->userSession,
+ );
}
public function dataGetCapabilities() {
return [
- ['name', 'url', 'slogan', '#FFFFFF', '#000000', 'logo', 'background', 'http://absolute/', true, [
+ ['name', 'url', 'slogan', '#FFFFFF', '#000000', 'logo', 'background', '#fff', '#000', 'http://absolute/', true, [
'name' => 'name',
'url' => 'url',
'slogan' => 'slogan',
@@ -86,12 +93,13 @@ class CapabilitiesTest extends TestCase {
'color-element-dark' => '#FFFFFF',
'logo' => 'http://absolute/logo',
'background' => 'http://absolute/background',
+ 'background-text' => '#000',
'background-plain' => false,
'background-default' => false,
'logoheader' => 'http://absolute/logo',
'favicon' => 'http://absolute/logo',
]],
- ['name1', 'url2', 'slogan3', '#01e4a0', '#ffffff', 'logo5', 'background6', 'http://localhost/', false, [
+ ['name1', 'url2', 'slogan3', '#01e4a0', '#ffffff', 'logo5', 'background6', '#fff', '#000', 'http://localhost/', false, [
'name' => 'name1',
'url' => 'url2',
'slogan' => 'slogan3',
@@ -102,12 +110,13 @@ class CapabilitiesTest extends TestCase {
'color-element-dark' => '#01e4a0',
'logo' => 'http://localhost/logo5',
'background' => 'http://localhost/background6',
+ 'background-text' => '#000',
'background-plain' => false,
'background-default' => true,
'logoheader' => 'http://localhost/logo5',
'favicon' => 'http://localhost/logo5',
]],
- ['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', 'http://localhost/', true, [
+ ['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', '#000000', '#ffffff', 'http://localhost/', true, [
'name' => 'name1',
'url' => 'url2',
'slogan' => 'slogan3',
@@ -118,12 +127,13 @@ class CapabilitiesTest extends TestCase {
'color-element-dark' => '#4d4d4d',
'logo' => 'http://localhost/logo5',
'background' => '#000000',
+ 'background-text' => '#ffffff',
'background-plain' => true,
'background-default' => false,
'logoheader' => 'http://localhost/logo5',
'favicon' => 'http://localhost/logo5',
]],
- ['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', 'http://localhost/', false, [
+ ['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', '#000000', '#ffffff', 'http://localhost/', false, [
'name' => 'name1',
'url' => 'url2',
'slogan' => 'slogan3',
@@ -134,6 +144,7 @@ class CapabilitiesTest extends TestCase {
'color-element-dark' => '#4d4d4d',
'logo' => 'http://localhost/logo5',
'background' => '#000000',
+ 'background-text' => '#ffffff',
'background-plain' => true,
'background-default' => true,
'logoheader' => 'http://localhost/logo5',
@@ -155,7 +166,7 @@ class CapabilitiesTest extends TestCase {
* @param bool $backgroundThemed
* @param string[] $expected
*/
- public function testGetCapabilities($name, $url, $slogan, $color, $textColor, $logo, $background, $baseUrl, $backgroundThemed, array $expected) {
+ public function testGetCapabilities($name, $url, $slogan, $color, $textColor, $logo, $background, $backgroundColor, $backgroundTextColor, $baseUrl, $backgroundThemed, array $expected) {
$this->config->expects($this->once())
->method('getAppValue')
->willReturn($background);
@@ -168,6 +179,12 @@ class CapabilitiesTest extends TestCase {
$this->theming->expects($this->once())
->method('getSlogan')
->willReturn($slogan);
+ $this->theming->expects($this->once())
+ ->method('getColorBackground')
+ ->willReturn($backgroundColor);
+ $this->theming->expects($this->once())
+ ->method('getTextColorBackground')
+ ->willReturn($backgroundTextColor);
$this->theming->expects($this->atLeast(1))
->method('getDefaultColorPrimary')
->willReturn($color);
diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php
index 5bc27069c6e..a3b12844ecb 100644
--- a/apps/theming/tests/Controller/ThemingControllerTest.php
+++ b/apps/theming/tests/Controller/ThemingControllerTest.php
@@ -42,13 +42,11 @@ use OCP\App\IAppManager;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
-use OCP\ITempManager;
use OCP\IURLGenerator;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
@@ -64,17 +62,13 @@ class ThemingControllerTest extends TestCase {
private $l10n;
/** @var ThemingController */
private $themingController;
- /** @var ITempManager */
- private $tempManager;
/** @var IAppManager|MockObject */
private $appManager;
- /** @var IAppData|MockObject */
- private $appData;
/** @var ImageManager|MockObject */
private $imageManager;
/** @var IURLGenerator|MockObject */
private $urlGenerator;
- /** @var ThemeService|MockObject */
+ /** @var ThemesService|MockObject */
private $themesService;
protected function setUp(): void {
@@ -82,9 +76,7 @@ class ThemingControllerTest extends TestCase {
$this->config = $this->createMock(IConfig::class);
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
$this->l10n = $this->createMock(L10N::class);
- $this->appData = $this->createMock(IAppData::class);
$this->appManager = $this->createMock(IAppManager::class);
- $this->tempManager = \OC::$server->getTempManager();
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->imageManager = $this->createMock(ImageManager::class);
$this->themesService = $this->createMock(ThemesService::class);
@@ -102,8 +94,6 @@ class ThemingControllerTest extends TestCase {
$this->config,
$this->themingDefaults,
$this->l10n,
- $this->tempManager,
- $this->appData,
$this->urlGenerator,
$this->appManager,
$this->imageManager,
@@ -164,9 +154,12 @@ class ThemingControllerTest extends TestCase {
['url', str_repeat('a', 501), 'The given web address is not a valid URL'],
['url', 'javascript:alert(1)', 'The given web address is not a valid URL'],
['slogan', str_repeat('a', 501), 'The given slogan is too long'],
- ['color', '0082C9', 'The given color is invalid'],
- ['color', '#0082Z9', 'The given color is invalid'],
- ['color', 'Nextcloud', 'The given color is invalid'],
+ ['primary_color', '0082C9', 'The given color is invalid'],
+ ['primary_color', '#0082Z9', 'The given color is invalid'],
+ ['primary_color', 'Nextcloud', 'The given color is invalid'],
+ ['background_color', '0082C9', 'The given color is invalid'],
+ ['background_color', '#0082Z9', 'The given color is invalid'],
+ ['background_color', 'Nextcloud', 'The given color is invalid'],
['imprintUrl', '0082C9', 'The given legal notice address is not a valid URL'],
['imprintUrl', '0082C9', 'The given legal notice address is not a valid URL'],
['imprintUrl', 'javascript:foo', 'The given legal notice address is not a valid URL'],
diff --git a/apps/theming/tests/ImageManagerTest.php b/apps/theming/tests/ImageManagerTest.php
index 8d42e892448..e8806ea0f6e 100644
--- a/apps/theming/tests/ImageManagerTest.php
+++ b/apps/theming/tests/ImageManagerTest.php
@@ -28,6 +28,7 @@
namespace OCA\Theming\Tests;
use OCA\Theming\ImageManager;
+use OCA\Theming\Service\BackgroundService;
use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
@@ -57,6 +58,8 @@ class ImageManagerTest extends TestCase {
private $tempManager;
/** @var ISimpleFolder|MockObject */
private $rootFolder;
+ /** @var BackgroundService|MockObject */
+ private $backgroundService;
protected function setUp(): void {
parent::setUp();
@@ -67,13 +70,15 @@ class ImageManagerTest extends TestCase {
$this->logger = $this->createMock(LoggerInterface::class);
$this->tempManager = $this->createMock(ITempManager::class);
$this->rootFolder = $this->createMock(ISimpleFolder::class);
+ $this->backgroundService = $this->createMock(BackgroundService::class);
$this->imageManager = new ImageManager(
$this->config,
$this->appData,
$this->urlGenerator,
$this->cacheFactory,
$this->logger,
- $this->tempManager
+ $this->tempManager,
+ $this->backgroundService,
);
$this->appData
->expects($this->any())
diff --git a/apps/theming/tests/Themes/DarkHighContrastThemeTest.php b/apps/theming/tests/Themes/DarkHighContrastThemeTest.php
index d3a357bcfe7..e92768f5f48 100644
--- a/apps/theming/tests/Themes/DarkHighContrastThemeTest.php
+++ b/apps/theming/tests/Themes/DarkHighContrastThemeTest.php
@@ -81,6 +81,14 @@ class DarkHighContrastThemeTest extends AccessibleThemeTestCase {
->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->themingDefaults
->expects($this->any())
diff --git a/apps/theming/tests/Themes/DarkThemeTest.php b/apps/theming/tests/Themes/DarkThemeTest.php
index 1a50e08d0f5..dced8c3fce6 100644
--- a/apps/theming/tests/Themes/DarkThemeTest.php
+++ b/apps/theming/tests/Themes/DarkThemeTest.php
@@ -78,6 +78,14 @@ class DarkThemeTest extends AccessibleThemeTestCase {
->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->themingDefaults
->expects($this->any())
diff --git a/apps/theming/tests/Themes/DefaultThemeTest.php b/apps/theming/tests/Themes/DefaultThemeTest.php
index 7e823cb4843..a4ca35cae25 100644
--- a/apps/theming/tests/Themes/DefaultThemeTest.php
+++ b/apps/theming/tests/Themes/DefaultThemeTest.php
@@ -69,15 +69,27 @@ class DefaultThemeTest extends AccessibleThemeTestCase {
$this->imageManager
);
+ $defaultBackground = BackgroundService::SHIPPED_BACKGROUNDS[BackgroundService::DEFAULT_BACKGROUND_IMAGE];
+
$this->themingDefaults
->expects($this->any())
->method('getColorPrimary')
- ->willReturn('#0082c9');
+ ->willReturn($defaultBackground['primary_color']);
+
+ $this->themingDefaults
+ ->expects($this->any())
+ ->method('getColorBackground')
+ ->willReturn($defaultBackground['background_color']);
$this->themingDefaults
->expects($this->any())
->method('getDefaultColorPrimary')
- ->willReturn('#0082c9');
+ ->willReturn($defaultBackground['primary_color']);
+
+ $this->themingDefaults
+ ->expects($this->any())
+ ->method('getDefaultColorBackground')
+ ->willReturn($defaultBackground['background_color']);
$this->themingDefaults
->expects($this->any())
diff --git a/apps/theming/tests/Themes/DyslexiaFontTest.php b/apps/theming/tests/Themes/DyslexiaFontTest.php
index 7a55d168fea..8040b8ec0fb 100644
--- a/apps/theming/tests/Themes/DyslexiaFontTest.php
+++ b/apps/theming/tests/Themes/DyslexiaFontTest.php
@@ -94,6 +94,16 @@ class DyslexiaFontTest extends TestCase {
->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')
diff --git a/apps/theming/tests/Themes/HighContrastThemeTest.php b/apps/theming/tests/Themes/HighContrastThemeTest.php
index 991f56512e3..19b37f40f83 100644
--- a/apps/theming/tests/Themes/HighContrastThemeTest.php
+++ b/apps/theming/tests/Themes/HighContrastThemeTest.php
@@ -81,6 +81,14 @@ class HighContrastThemeTest extends AccessibleThemeTestCase {
->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->themingDefaults
->expects($this->any())
diff --git a/apps/theming/tests/ThemingDefaultsTest.php b/apps/theming/tests/ThemingDefaultsTest.php
index cf6b6492c11..2011b62c3ea 100644
--- a/apps/theming/tests/ThemingDefaultsTest.php
+++ b/apps/theming/tests/ThemingDefaultsTest.php
@@ -78,6 +78,8 @@ class ThemingDefaultsTest extends TestCase {
private $imageManager;
/** @var INavigationManager|\PHPUnit\Framework\MockObject\MockObject */
private $navigationManager;
+ /** @var BackgroundService|\PHPUnit\Framework\MockObject\MockObject */
+ private $backgroundService;
protected function setUp(): void {
parent::setUp();
@@ -91,6 +93,7 @@ class ThemingDefaultsTest extends TestCase {
$this->imageManager = $this->createMock(ImageManager::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->navigationManager = $this->createMock(INavigationManager::class);
+ $this->backgroundService = $this->createMock(BackgroundService::class);
$this->defaults = new \OC_Defaults();
$this->urlGenerator
->expects($this->any())
@@ -105,7 +108,8 @@ class ThemingDefaultsTest extends TestCase {
$this->util,
$this->imageManager,
$this->appManager,
- $this->navigationManager
+ $this->navigationManager,
+ $this->backgroundService,
);
}
@@ -428,7 +432,7 @@ class ThemingDefaultsTest extends TestCase {
->method('getAppValue')
->willReturnMap([
['theming', 'disable-user-theming', 'no', 'no'],
- ['theming', 'color', '', $this->defaults->getColorPrimary()],
+ ['theming', 'primary_color', '', $this->defaults->getColorPrimary()],
]);
$this->assertEquals($this->defaults->getColorPrimary(), $this->template->getColorPrimary());
@@ -440,66 +444,101 @@ class ThemingDefaultsTest extends TestCase {
->method('getAppValue')
->willReturnMap([
['theming', 'disable-user-theming', 'no', 'no'],
- ['theming', 'color', '', '#fff'],
+ ['theming', 'primary_color', '', '#fff'],
]);
$this->assertEquals('#fff', $this->template->getColorPrimary());
}
- public function testGetColorPrimaryWithDefaultBackground() {
- $user = $this->createMock(IUser::class);
- $this->userSession->expects($this->any())
- ->method('getUser')
- ->willReturn($user);
- $user->expects($this->any())
- ->method('getUID')
- ->willReturn('user');
- $this->config
- ->expects($this->exactly(2))
- ->method('getAppValue')
- ->willReturnMap([
- ['theming', 'disable-user-theming', 'no', 'no'],
- ['theming', 'color', '', ''],
- ]);
- $this->config
- ->expects($this->once())
- ->method('getUserValue')
- ->with('user', 'theming', 'background_color')
- ->willReturn('');
-
- $this->assertEquals(BackgroundService::DEFAULT_COLOR, $this->template->getColorPrimary());
- }
-
- public function testGetColorPrimaryWithCustomBackground() {
- $backgroundIndex = 2;
- $background = array_values(BackgroundService::SHIPPED_BACKGROUNDS)[$backgroundIndex];
-
- $user = $this->createMock(IUser::class);
- $this->userSession->expects($this->any())
- ->method('getUser')
- ->willReturn($user);
- $user->expects($this->any())
- ->method('getUID')
- ->willReturn('user');
-
- $this->config
- ->expects($this->once())
- ->method('getUserValue')
- ->with('user', 'theming', 'background_color', '')
- ->willReturn($background['primary_color']);
-
- $this->config
- ->expects($this->exactly(2))
- ->method('getAppValue')
- ->willReturnMap([
- ['theming', 'color', '', ''],
- ['theming', 'disable-user-theming', 'no', 'no'],
- ]);
-
- $this->assertEquals($background['primary_color'], $this->template->getColorPrimary());
+ public function dataGetColorPrimary() {
+ return [
+ 'with fallback default' => [
+ 'disableTheming' => 'no',
+ 'primaryColor' => '',
+ 'backgroundColor' => '',
+ 'userBackgroundColor' => '',
+ 'userPrimaryColor' => '',
+ 'expected' => BackgroundService::DEFAULT_COLOR,
+ ],
+ 'with custom admin background' => [
+ 'disableTheming' => 'no',
+ 'primaryColor' => '',
+ 'backgroundColor' => '#123',
+ 'userBackgroundColor' => '',
+ 'userPrimaryColor' => '',
+ 'expected' => '#123',
+ ],
+ 'with custom invalid admin background' => [
+ 'disableTheming' => 'no',
+ 'primaryColor' => '',
+ 'backgroundColor' => 'invalid-name',
+ 'userBackgroundColor' => '',
+ 'userPrimaryColor' => '',
+ 'expected' => BackgroundService::DEFAULT_COLOR,
+ ],
+ 'with custom admin primary' => [
+ 'disableTheming' => 'no',
+ 'primaryColor' => '#aaa',
+ 'backgroundColor' => '',
+ 'userBackgroundColor' => '',
+ 'userPrimaryColor' => '',
+ 'expected' => '#aaa',
+ ],
+ 'with custom invalid admin primary' => [
+ 'disableTheming' => 'no',
+ 'primaryColor' => 'invalid',
+ 'backgroundColor' => '',
+ 'userBackgroundColor' => '',
+ 'userPrimaryColor' => '',
+ 'expected' => BackgroundService::DEFAULT_COLOR,
+ ],
+ 'with custom user background' => [
+ 'disableTheming' => 'no',
+ 'primaryColor' => '',
+ 'backgroundColor' => '',
+ 'userBackgroundColor' => '#456',
+ 'userPrimaryColor' => '#456',
+ 'expected' => '#456',
+ ],
+ 'with custom invalid user primary' => [
+ 'disableTheming' => 'no',
+ 'primaryColor' => '',
+ 'backgroundColor' => '',
+ 'userBackgroundColor' => '',
+ 'userPrimaryColor' => 'invalid-name',
+ 'expected' => BackgroundService::DEFAULT_COLOR,
+ ],
+ 'with custom user primary' => [
+ 'disableTheming' => 'no',
+ 'primaryColor' => '',
+ 'backgroundColor' => '',
+ 'userBackgroundColor' => '',
+ 'userPrimaryColor' => '#bbb',
+ 'expected' => '#bbb',
+ ],
+ 'with custom invalid user background' => [
+ 'disableTheming' => 'no',
+ 'primaryColor' => '',
+ 'backgroundColor' => '',
+ 'userBackgroundColor' => 'invalid-name',
+ 'userPrimaryColor' => '',
+ 'expected' => BackgroundService::DEFAULT_COLOR,
+ ],
+ 'with custom admin and user background' => [
+ 'disableTheming' => 'no',
+ 'primaryColor' => '',
+ 'backgroundColor' => '#123',
+ 'userBackgroundColor' => '#456',
+ 'userPrimaryColor' => '#456',
+ 'expected' => '#456',
+ ],
+ ];
}
- public function testGetColorPrimaryWithCustomBackgroundColor() {
+ /**
+ * @dataProvider dataGetColorPrimary
+ */
+ public function testGetColorPrimary(string $disableTheming, string $primaryColor, string $backgroundColor, string $userBackgroundColor, $userPrimaryColor, $expected) {
$user = $this->createMock(IUser::class);
$this->userSession->expects($this->any())
->method('getUser')
@@ -507,46 +546,23 @@ class ThemingDefaultsTest extends TestCase {
$user->expects($this->any())
->method('getUID')
->willReturn('user');
-
- $this->config
- ->expects($this->once())
- ->method('getUserValue')
- ->with('user', 'theming', 'background_color', '')
- ->willReturn('#fff');
$this->config
- ->expects($this->exactly(2))
+ ->expects($this->any())
->method('getAppValue')
->willReturnMap([
- ['theming', 'color', '', ''],
- ['theming', 'disable-user-theming', 'no', 'no'],
+ ['theming', 'disable-user-theming', 'no', $disableTheming],
+ ['theming', 'primary_color', '', $primaryColor],
+ ['theming', 'background_color', '', $backgroundColor],
]);
-
- $this->assertEquals('#fff', $this->template->getColorPrimary());
- }
-
- public function testGetColorPrimaryWithInvalidCustomBackgroundColor() {
- $user = $this->createMock(IUser::class);
- $this->userSession->expects($this->any())
- ->method('getUser')
- ->willReturn($user);
- $user->expects($this->any())
- ->method('getUID')
- ->willReturn('user');
-
$this->config
- ->expects($this->once())
+ ->expects($this->any())
->method('getUserValue')
- ->with('user', 'theming', 'background_color', '')
- ->willReturn('nextcloud');
- $this->config
- ->expects($this->exactly(3))
- ->method('getAppValue')
->willReturnMap([
- ['theming', 'color', '', ''],
- ['theming', 'disable-user-theming', 'no', 'no'],
+ ['user', 'theming', 'background_color', '', $userBackgroundColor],
+ ['user', 'theming', 'primary_color', $userBackgroundColor, $userPrimaryColor],
]);
- $this->assertEquals($this->template->getDefaultColorPrimary(), $this->template->getColorPrimary());
+ $this->assertEquals($expected, $this->template->getColorPrimary());
}
public function testSet() {
@@ -646,17 +662,17 @@ class ThemingDefaultsTest extends TestCase {
$this->assertSame($this->defaults->getSlogan(), $this->template->undo('slogan'));
}
- public function testUndoColor() {
+ public function testUndoPrimaryColor() {
$this->config
->expects($this->once())
->method('deleteAppValue')
- ->with('theming', 'color');
+ ->with('theming', 'primary_color');
$this->config
->expects($this->exactly(2))
->method('getAppValue')
->withConsecutive(
['theming', 'cachebuster', '0'],
- ['theming', 'color', null],
+ ['theming', 'primary_color', null],
)->willReturnOnConsecutiveCalls(
'15',
$this->defaults->getColorPrimary(),
@@ -666,7 +682,7 @@ class ThemingDefaultsTest extends TestCase {
->method('setAppValue')
->with('theming', 'cachebuster', 16);
- $this->assertSame($this->defaults->getColorPrimary(), $this->template->undo('color'));
+ $this->assertSame($this->defaults->getColorPrimary(), $this->template->undo('primary_color'));
}
public function testUndoDefaultAction() {
@@ -764,8 +780,8 @@ class ThemingDefaultsTest extends TestCase {
['theming', 'backgroundMime', '', 'jpeg'],
['theming', 'logoheaderMime', '', 'jpeg'],
['theming', 'faviconMime', '', 'jpeg'],
- ['theming', 'color', '', $this->defaults->getColorPrimary()],
- ['theming', 'color', $this->defaults->getColorPrimary(), $this->defaults->getColorPrimary()],
+ ['theming', 'primary_color', '', $this->defaults->getColorPrimary()],
+ ['theming', 'primary_color', $this->defaults->getColorPrimary(), $this->defaults->getColorPrimary()],
]);
$this->util->expects($this->any())->method('invertTextColor')->with($this->defaults->getColorPrimary())->willReturn(false);