fix(tests): Adjust theming test for new splitted background and primary colors

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
pull/42977/head
Ferdinand Thiessen 2024-01-20 07:43:04 +07:00
parent 282f1b1fab
commit 0ef3147ea0
No known key found for this signature in database
GPG Key ID: 45FAE7268762B400
11 changed files with 200 additions and 122 deletions

@ -85,7 +85,7 @@
--color-primary-element-light-hover: #dbe4ea; --color-primary-element-light-hover: #dbe4ea;
--color-primary-element-light-text: #00293f; --color-primary-element-light-text: #00293f;
--gradient-primary-background: linear-gradient(40deg, var(--color-primary) 0%, var(--color-primary-hover) 100%); --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: #00679e;
--color-background-plain: #0082c9;
--color-background-plain-text: #ffffff; --color-background-plain-text: #ffffff;
--image-background-default: url('/apps/theming/img/background/kamil-porembinski-clouds.jpg');
} }

@ -85,6 +85,7 @@ class Capabilities implements IPublicCapability {
* color-element-dark: string, * color-element-dark: string,
* logo: string, * logo: string,
* background: string, * background: string,
* background-text: string,
* background-plain: bool, * background-plain: bool,
* background-default: bool, * background-default: bool,
* logoheader: string, * logoheader: string,

@ -37,6 +37,7 @@ use OCP\Files\IAppData;
use OCP\IConfig; use OCP\IConfig;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUserSession; use OCP\IUserSession;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase; use Test\TestCase;
/** /**
@ -45,16 +46,16 @@ use Test\TestCase;
* @package OCA\Theming\Tests * @package OCA\Theming\Tests
*/ */
class CapabilitiesTest extends TestCase { class CapabilitiesTest extends TestCase {
/** @var ThemingDefaults|\PHPUnit\Framework\MockObject\MockObject */ /** @var ThemingDefaults|MockObject */
protected $theming; protected $theming;
/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */ /** @var IURLGenerator|MockObject */
protected $url; protected $url;
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ /** @var IConfig|MockObject */
protected $config; protected $config;
/** @var Util|\PHPUnit\Framework\MockObject\MockObject */ /** @var Util|MockObject */
protected $util; protected $util;
protected IUserSession $userSession; protected IUserSession $userSession;
@ -66,16 +67,22 @@ class CapabilitiesTest extends TestCase {
parent::setUp(); parent::setUp();
$this->theming = $this->createMock(ThemingDefaults::class); $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->config = $this->createMock(IConfig::class);
$this->util = $this->createMock(Util::class); $this->util = $this->createMock(Util::class);
$this->userSession = $this->createMock(IUserSession::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() { public function dataGetCapabilities() {
return [ 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', 'name' => 'name',
'url' => 'url', 'url' => 'url',
'slogan' => 'slogan', 'slogan' => 'slogan',
@ -86,12 +93,13 @@ class CapabilitiesTest extends TestCase {
'color-element-dark' => '#FFFFFF', 'color-element-dark' => '#FFFFFF',
'logo' => 'http://absolute/logo', 'logo' => 'http://absolute/logo',
'background' => 'http://absolute/background', 'background' => 'http://absolute/background',
'background-text' => '#000',
'background-plain' => false, 'background-plain' => false,
'background-default' => false, 'background-default' => false,
'logoheader' => 'http://absolute/logo', 'logoheader' => 'http://absolute/logo',
'favicon' => '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', 'name' => 'name1',
'url' => 'url2', 'url' => 'url2',
'slogan' => 'slogan3', 'slogan' => 'slogan3',
@ -102,12 +110,13 @@ class CapabilitiesTest extends TestCase {
'color-element-dark' => '#01e4a0', 'color-element-dark' => '#01e4a0',
'logo' => 'http://localhost/logo5', 'logo' => 'http://localhost/logo5',
'background' => 'http://localhost/background6', 'background' => 'http://localhost/background6',
'background-text' => '#000',
'background-plain' => false, 'background-plain' => false,
'background-default' => true, 'background-default' => true,
'logoheader' => 'http://localhost/logo5', 'logoheader' => 'http://localhost/logo5',
'favicon' => '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', 'name' => 'name1',
'url' => 'url2', 'url' => 'url2',
'slogan' => 'slogan3', 'slogan' => 'slogan3',
@ -118,12 +127,13 @@ class CapabilitiesTest extends TestCase {
'color-element-dark' => '#4d4d4d', 'color-element-dark' => '#4d4d4d',
'logo' => 'http://localhost/logo5', 'logo' => 'http://localhost/logo5',
'background' => '#000000', 'background' => '#000000',
'background-text' => '#ffffff',
'background-plain' => true, 'background-plain' => true,
'background-default' => false, 'background-default' => false,
'logoheader' => 'http://localhost/logo5', 'logoheader' => 'http://localhost/logo5',
'favicon' => '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', 'name' => 'name1',
'url' => 'url2', 'url' => 'url2',
'slogan' => 'slogan3', 'slogan' => 'slogan3',
@ -134,6 +144,7 @@ class CapabilitiesTest extends TestCase {
'color-element-dark' => '#4d4d4d', 'color-element-dark' => '#4d4d4d',
'logo' => 'http://localhost/logo5', 'logo' => 'http://localhost/logo5',
'background' => '#000000', 'background' => '#000000',
'background-text' => '#ffffff',
'background-plain' => true, 'background-plain' => true,
'background-default' => true, 'background-default' => true,
'logoheader' => 'http://localhost/logo5', 'logoheader' => 'http://localhost/logo5',
@ -155,7 +166,7 @@ class CapabilitiesTest extends TestCase {
* @param bool $backgroundThemed * @param bool $backgroundThemed
* @param string[] $expected * @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()) $this->config->expects($this->once())
->method('getAppValue') ->method('getAppValue')
->willReturn($background); ->willReturn($background);
@ -168,6 +179,12 @@ class CapabilitiesTest extends TestCase {
$this->theming->expects($this->once()) $this->theming->expects($this->once())
->method('getSlogan') ->method('getSlogan')
->willReturn($slogan); ->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)) $this->theming->expects($this->atLeast(1))
->method('getDefaultColorPrimary') ->method('getDefaultColorPrimary')
->willReturn($color); ->willReturn($color);

@ -42,13 +42,11 @@ use OCP\App\IAppManager;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile; use OCP\Files\SimpleFS\ISimpleFile;
use OCP\IConfig; use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\IRequest; use OCP\IRequest;
use OCP\ITempManager;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase; use Test\TestCase;
@ -64,17 +62,13 @@ class ThemingControllerTest extends TestCase {
private $l10n; private $l10n;
/** @var ThemingController */ /** @var ThemingController */
private $themingController; private $themingController;
/** @var ITempManager */
private $tempManager;
/** @var IAppManager|MockObject */ /** @var IAppManager|MockObject */
private $appManager; private $appManager;
/** @var IAppData|MockObject */
private $appData;
/** @var ImageManager|MockObject */ /** @var ImageManager|MockObject */
private $imageManager; private $imageManager;
/** @var IURLGenerator|MockObject */ /** @var IURLGenerator|MockObject */
private $urlGenerator; private $urlGenerator;
/** @var ThemeService|MockObject */ /** @var ThemesService|MockObject */
private $themesService; private $themesService;
protected function setUp(): void { protected function setUp(): void {
@ -82,9 +76,7 @@ class ThemingControllerTest extends TestCase {
$this->config = $this->createMock(IConfig::class); $this->config = $this->createMock(IConfig::class);
$this->themingDefaults = $this->createMock(ThemingDefaults::class); $this->themingDefaults = $this->createMock(ThemingDefaults::class);
$this->l10n = $this->createMock(L10N::class); $this->l10n = $this->createMock(L10N::class);
$this->appData = $this->createMock(IAppData::class);
$this->appManager = $this->createMock(IAppManager::class); $this->appManager = $this->createMock(IAppManager::class);
$this->tempManager = \OC::$server->getTempManager();
$this->urlGenerator = $this->createMock(IURLGenerator::class); $this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->imageManager = $this->createMock(ImageManager::class); $this->imageManager = $this->createMock(ImageManager::class);
$this->themesService = $this->createMock(ThemesService::class); $this->themesService = $this->createMock(ThemesService::class);
@ -102,8 +94,6 @@ class ThemingControllerTest extends TestCase {
$this->config, $this->config,
$this->themingDefaults, $this->themingDefaults,
$this->l10n, $this->l10n,
$this->tempManager,
$this->appData,
$this->urlGenerator, $this->urlGenerator,
$this->appManager, $this->appManager,
$this->imageManager, $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', 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'], ['url', 'javascript:alert(1)', 'The given web address is not a valid URL'],
['slogan', str_repeat('a', 501), 'The given slogan is too long'], ['slogan', str_repeat('a', 501), 'The given slogan is too long'],
['color', '0082C9', 'The given color is invalid'], ['primary_color', '0082C9', 'The given color is invalid'],
['color', '#0082Z9', 'The given color is invalid'], ['primary_color', '#0082Z9', 'The given color is invalid'],
['color', 'Nextcloud', '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', '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'], ['imprintUrl', 'javascript:foo', 'The given legal notice address is not a valid URL'],

@ -28,6 +28,7 @@
namespace OCA\Theming\Tests; namespace OCA\Theming\Tests;
use OCA\Theming\ImageManager; use OCA\Theming\ImageManager;
use OCA\Theming\Service\BackgroundService;
use OCP\Files\IAppData; use OCP\Files\IAppData;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile; use OCP\Files\SimpleFS\ISimpleFile;
@ -57,6 +58,8 @@ class ImageManagerTest extends TestCase {
private $tempManager; private $tempManager;
/** @var ISimpleFolder|MockObject */ /** @var ISimpleFolder|MockObject */
private $rootFolder; private $rootFolder;
/** @var BackgroundService|MockObject */
private $backgroundService;
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
@ -67,13 +70,15 @@ class ImageManagerTest extends TestCase {
$this->logger = $this->createMock(LoggerInterface::class); $this->logger = $this->createMock(LoggerInterface::class);
$this->tempManager = $this->createMock(ITempManager::class); $this->tempManager = $this->createMock(ITempManager::class);
$this->rootFolder = $this->createMock(ISimpleFolder::class); $this->rootFolder = $this->createMock(ISimpleFolder::class);
$this->backgroundService = $this->createMock(BackgroundService::class);
$this->imageManager = new ImageManager( $this->imageManager = new ImageManager(
$this->config, $this->config,
$this->appData, $this->appData,
$this->urlGenerator, $this->urlGenerator,
$this->cacheFactory, $this->cacheFactory,
$this->logger, $this->logger,
$this->tempManager $this->tempManager,
$this->backgroundService,
); );
$this->appData $this->appData
->expects($this->any()) ->expects($this->any())

@ -81,6 +81,14 @@ class DarkHighContrastThemeTest extends AccessibleThemeTestCase {
->expects($this->any()) ->expects($this->any())
->method('getDefaultColorPrimary') ->method('getDefaultColorPrimary')
->willReturn('#0082c9'); ->willReturn('#0082c9');
$this->themingDefaults
->expects($this->any())
->method('getColorBackground')
->willReturn('#0082c9');
$this->themingDefaults
->expects($this->any())
->method('getDefaultColorBackground')
->willReturn('#0082c9');
$this->themingDefaults $this->themingDefaults
->expects($this->any()) ->expects($this->any())

@ -78,6 +78,14 @@ class DarkThemeTest extends AccessibleThemeTestCase {
->expects($this->any()) ->expects($this->any())
->method('getDefaultColorPrimary') ->method('getDefaultColorPrimary')
->willReturn('#0082c9'); ->willReturn('#0082c9');
$this->themingDefaults
->expects($this->any())
->method('getColorBackground')
->willReturn('#0082c9');
$this->themingDefaults
->expects($this->any())
->method('getDefaultColorBackground')
->willReturn('#0082c9');
$this->themingDefaults $this->themingDefaults
->expects($this->any()) ->expects($this->any())

@ -69,15 +69,27 @@ class DefaultThemeTest extends AccessibleThemeTestCase {
$this->imageManager $this->imageManager
); );
$defaultBackground = BackgroundService::SHIPPED_BACKGROUNDS[BackgroundService::DEFAULT_BACKGROUND_IMAGE];
$this->themingDefaults $this->themingDefaults
->expects($this->any()) ->expects($this->any())
->method('getColorPrimary') ->method('getColorPrimary')
->willReturn('#0082c9'); ->willReturn($defaultBackground['primary_color']);
$this->themingDefaults
->expects($this->any())
->method('getColorBackground')
->willReturn($defaultBackground['background_color']);
$this->themingDefaults $this->themingDefaults
->expects($this->any()) ->expects($this->any())
->method('getDefaultColorPrimary') ->method('getDefaultColorPrimary')
->willReturn('#0082c9'); ->willReturn($defaultBackground['primary_color']);
$this->themingDefaults
->expects($this->any())
->method('getDefaultColorBackground')
->willReturn($defaultBackground['background_color']);
$this->themingDefaults $this->themingDefaults
->expects($this->any()) ->expects($this->any())

@ -94,6 +94,16 @@ class DyslexiaFontTest extends TestCase {
->method('getDefaultColorPrimary') ->method('getDefaultColorPrimary')
->willReturn('#0082c9'); ->willReturn('#0082c9');
$this->themingDefaults
->expects($this->any())
->method('getColorBackground')
->willReturn('#0082c9');
$this->themingDefaults
->expects($this->any())
->method('getDefaultColorBackground')
->willReturn('#0082c9');
$this->l10n $this->l10n
->expects($this->any()) ->expects($this->any())
->method('t') ->method('t')

@ -81,6 +81,14 @@ class HighContrastThemeTest extends AccessibleThemeTestCase {
->expects($this->any()) ->expects($this->any())
->method('getDefaultColorPrimary') ->method('getDefaultColorPrimary')
->willReturn('#0082c9'); ->willReturn('#0082c9');
$this->themingDefaults
->expects($this->any())
->method('getColorBackground')
->willReturn('#0082c9');
$this->themingDefaults
->expects($this->any())
->method('getDefaultColorBackground')
->willReturn('#0082c9');
$this->themingDefaults $this->themingDefaults
->expects($this->any()) ->expects($this->any())

@ -78,6 +78,8 @@ class ThemingDefaultsTest extends TestCase {
private $imageManager; private $imageManager;
/** @var INavigationManager|\PHPUnit\Framework\MockObject\MockObject */ /** @var INavigationManager|\PHPUnit\Framework\MockObject\MockObject */
private $navigationManager; private $navigationManager;
/** @var BackgroundService|\PHPUnit\Framework\MockObject\MockObject */
private $backgroundService;
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
@ -91,6 +93,7 @@ class ThemingDefaultsTest extends TestCase {
$this->imageManager = $this->createMock(ImageManager::class); $this->imageManager = $this->createMock(ImageManager::class);
$this->appManager = $this->createMock(IAppManager::class); $this->appManager = $this->createMock(IAppManager::class);
$this->navigationManager = $this->createMock(INavigationManager::class); $this->navigationManager = $this->createMock(INavigationManager::class);
$this->backgroundService = $this->createMock(BackgroundService::class);
$this->defaults = new \OC_Defaults(); $this->defaults = new \OC_Defaults();
$this->urlGenerator $this->urlGenerator
->expects($this->any()) ->expects($this->any())
@ -105,7 +108,8 @@ class ThemingDefaultsTest extends TestCase {
$this->util, $this->util,
$this->imageManager, $this->imageManager,
$this->appManager, $this->appManager,
$this->navigationManager $this->navigationManager,
$this->backgroundService,
); );
} }
@ -428,7 +432,7 @@ class ThemingDefaultsTest extends TestCase {
->method('getAppValue') ->method('getAppValue')
->willReturnMap([ ->willReturnMap([
['theming', 'disable-user-theming', 'no', 'no'], ['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()); $this->assertEquals($this->defaults->getColorPrimary(), $this->template->getColorPrimary());
@ -440,66 +444,101 @@ class ThemingDefaultsTest extends TestCase {
->method('getAppValue') ->method('getAppValue')
->willReturnMap([ ->willReturnMap([
['theming', 'disable-user-theming', 'no', 'no'], ['theming', 'disable-user-theming', 'no', 'no'],
['theming', 'color', '', '#fff'], ['theming', 'primary_color', '', '#fff'],
]); ]);
$this->assertEquals('#fff', $this->template->getColorPrimary()); $this->assertEquals('#fff', $this->template->getColorPrimary());
} }
public function testGetColorPrimaryWithDefaultBackground() { public function dataGetColorPrimary() {
$user = $this->createMock(IUser::class); return [
$this->userSession->expects($this->any()) 'with fallback default' => [
->method('getUser') 'disableTheming' => 'no',
->willReturn($user); 'primaryColor' => '',
$user->expects($this->any()) 'backgroundColor' => '',
->method('getUID') 'userBackgroundColor' => '',
->willReturn('user'); 'userPrimaryColor' => '',
$this->config 'expected' => BackgroundService::DEFAULT_COLOR,
->expects($this->exactly(2)) ],
->method('getAppValue') 'with custom admin background' => [
->willReturnMap([ 'disableTheming' => 'no',
['theming', 'disable-user-theming', 'no', 'no'], 'primaryColor' => '',
['theming', 'color', '', ''], 'backgroundColor' => '#123',
]); 'userBackgroundColor' => '',
$this->config 'userPrimaryColor' => '',
->expects($this->once()) 'expected' => '#123',
->method('getUserValue') ],
->with('user', 'theming', 'background_color') 'with custom invalid admin background' => [
->willReturn(''); 'disableTheming' => 'no',
'primaryColor' => '',
$this->assertEquals(BackgroundService::DEFAULT_COLOR, $this->template->getColorPrimary()); 'backgroundColor' => 'invalid-name',
} 'userBackgroundColor' => '',
'userPrimaryColor' => '',
public function testGetColorPrimaryWithCustomBackground() { 'expected' => BackgroundService::DEFAULT_COLOR,
$backgroundIndex = 2; ],
$background = array_values(BackgroundService::SHIPPED_BACKGROUNDS)[$backgroundIndex]; 'with custom admin primary' => [
'disableTheming' => 'no',
$user = $this->createMock(IUser::class); 'primaryColor' => '#aaa',
$this->userSession->expects($this->any()) 'backgroundColor' => '',
->method('getUser') 'userBackgroundColor' => '',
->willReturn($user); 'userPrimaryColor' => '',
$user->expects($this->any()) 'expected' => '#aaa',
->method('getUID') ],
->willReturn('user'); 'with custom invalid admin primary' => [
'disableTheming' => 'no',
$this->config 'primaryColor' => 'invalid',
->expects($this->once()) 'backgroundColor' => '',
->method('getUserValue') 'userBackgroundColor' => '',
->with('user', 'theming', 'background_color', '') 'userPrimaryColor' => '',
->willReturn($background['primary_color']); 'expected' => BackgroundService::DEFAULT_COLOR,
],
$this->config 'with custom user background' => [
->expects($this->exactly(2)) 'disableTheming' => 'no',
->method('getAppValue') 'primaryColor' => '',
->willReturnMap([ 'backgroundColor' => '',
['theming', 'color', '', ''], 'userBackgroundColor' => '#456',
['theming', 'disable-user-theming', 'no', 'no'], 'userPrimaryColor' => '#456',
]); 'expected' => '#456',
],
$this->assertEquals($background['primary_color'], $this->template->getColorPrimary()); '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); $user = $this->createMock(IUser::class);
$this->userSession->expects($this->any()) $this->userSession->expects($this->any())
->method('getUser') ->method('getUser')
@ -507,46 +546,23 @@ class ThemingDefaultsTest extends TestCase {
$user->expects($this->any()) $user->expects($this->any())
->method('getUID') ->method('getUID')
->willReturn('user'); ->willReturn('user');
$this->config
->expects($this->once())
->method('getUserValue')
->with('user', 'theming', 'background_color', '')
->willReturn('#fff');
$this->config $this->config
->expects($this->exactly(2)) ->expects($this->any())
->method('getAppValue') ->method('getAppValue')
->willReturnMap([ ->willReturnMap([
['theming', 'color', '', ''], ['theming', 'disable-user-theming', 'no', $disableTheming],
['theming', 'disable-user-theming', 'no', 'no'], ['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 $this->config
->expects($this->once()) ->expects($this->any())
->method('getUserValue') ->method('getUserValue')
->with('user', 'theming', 'background_color', '')
->willReturn('nextcloud');
$this->config
->expects($this->exactly(3))
->method('getAppValue')
->willReturnMap([ ->willReturnMap([
['theming', 'color', '', ''], ['user', 'theming', 'background_color', '', $userBackgroundColor],
['theming', 'disable-user-theming', 'no', 'no'], ['user', 'theming', 'primary_color', $userBackgroundColor, $userPrimaryColor],
]); ]);
$this->assertEquals($this->template->getDefaultColorPrimary(), $this->template->getColorPrimary()); $this->assertEquals($expected, $this->template->getColorPrimary());
} }
public function testSet() { public function testSet() {
@ -646,17 +662,17 @@ class ThemingDefaultsTest extends TestCase {
$this->assertSame($this->defaults->getSlogan(), $this->template->undo('slogan')); $this->assertSame($this->defaults->getSlogan(), $this->template->undo('slogan'));
} }
public function testUndoColor() { public function testUndoPrimaryColor() {
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('deleteAppValue') ->method('deleteAppValue')
->with('theming', 'color'); ->with('theming', 'primary_color');
$this->config $this->config
->expects($this->exactly(2)) ->expects($this->exactly(2))
->method('getAppValue') ->method('getAppValue')
->withConsecutive( ->withConsecutive(
['theming', 'cachebuster', '0'], ['theming', 'cachebuster', '0'],
['theming', 'color', null], ['theming', 'primary_color', null],
)->willReturnOnConsecutiveCalls( )->willReturnOnConsecutiveCalls(
'15', '15',
$this->defaults->getColorPrimary(), $this->defaults->getColorPrimary(),
@ -666,7 +682,7 @@ class ThemingDefaultsTest extends TestCase {
->method('setAppValue') ->method('setAppValue')
->with('theming', 'cachebuster', 16); ->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() { public function testUndoDefaultAction() {
@ -764,8 +780,8 @@ class ThemingDefaultsTest extends TestCase {
['theming', 'backgroundMime', '', 'jpeg'], ['theming', 'backgroundMime', '', 'jpeg'],
['theming', 'logoheaderMime', '', 'jpeg'], ['theming', 'logoheaderMime', '', 'jpeg'],
['theming', 'faviconMime', '', 'jpeg'], ['theming', 'faviconMime', '', 'jpeg'],
['theming', 'color', '', $this->defaults->getColorPrimary()], ['theming', 'primary_color', '', $this->defaults->getColorPrimary()],
['theming', 'color', $this->defaults->getColorPrimary(), $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); $this->util->expects($this->any())->method('invertTextColor')->with($this->defaults->getColorPrimary())->willReturn(false);