|
|
|
|
@ -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);
|
|
|
|
|
|