Browse Source

Make sure that ThemingDefaults uses the correct default values from \OC_Defaults

Signed-off-by: Julius Härtl <jus@bitgrid.net>
tags/v12.0.0beta1
Julius Härtl 7 years ago
parent
commit
b436e43d68
No account linked to committer's email address

+ 5
- 5
apps/theming/lib/ThemingDefaults.php View File

public function __construct(IConfig $config, public function __construct(IConfig $config,
IL10N $l, IL10N $l,
IURLGenerator $urlGenerator, IURLGenerator $urlGenerator,
\OC_Defaults $defaults,
IAppData $appData, IAppData $appData,
ICacheFactory $cacheFactory, ICacheFactory $cacheFactory,
Util $util Util $util
) { ) {
parent::__construct();
$this->config = $config; $this->config = $config;
$this->l = $l; $this->l = $l;
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;
$this->cacheFactory = $cacheFactory; $this->cacheFactory = $cacheFactory;
$this->util = $util; $this->util = $util;


$this->name = $defaults->getName();
$this->url = $defaults->getBaseUrl();
$this->slogan = $defaults->getSlogan();
$this->color = $defaults->getColorPrimary();
$this->name = parent::getName();
$this->url = parent::getBaseUrl();
$this->slogan = parent::getSlogan();
$this->color = parent::getColorPrimary();
} }


public function getName() { public function getName() {

+ 31
- 50
apps/theming/tests/ThemingDefaultsTest.php View File

$this->cacheFactory = $this->createMock(ICacheFactory::class); $this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->cache = $this->createMock(ICache::class); $this->cache = $this->createMock(ICache::class);
$this->util = $this->createMock(Util::class); $this->util = $this->createMock(Util::class);
$this->defaults = $this->getMockBuilder(\OC_Defaults::class)
->disableOriginalConstructor()
->getMock();
$this->defaults
->expects($this->at(0))
->method('getName')
->willReturn('Nextcloud');
$this->defaults
->expects($this->at(1))
->method('getBaseUrl')
->willReturn('https://nextcloud.com/');
$this->defaults
->expects($this->at(2))
->method('getSlogan')
->willReturn('Safe Data');
$this->defaults
->expects($this->at(3))
->method('getColorPrimary')
->willReturn('#000');
$this->defaults = new \OC_Defaults();
$this->cacheFactory $this->cacheFactory
->expects($this->any()) ->expects($this->any())
->method('create') ->method('create')
$this->config, $this->config,
$this->l10n, $this->l10n,
$this->urlGenerator, $this->urlGenerator,
$this->defaults,
$this->appData, $this->appData,
$this->cacheFactory, $this->cacheFactory,
$this->util $this->util
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getAppValue') ->method('getAppValue')
->with('theming', 'url', 'https://nextcloud.com/')
->willReturn('https://nextcloud.com/');
->with('theming', 'url', $this->defaults->getBaseUrl())
->willReturn($this->defaults->getBaseUrl());


$this->assertEquals('https://nextcloud.com/', $this->template->getBaseUrl());
$this->assertEquals($this->defaults->getBaseUrl(), $this->template->getBaseUrl());
} }


public function testGetBaseUrlWithCustom() { public function testGetBaseUrlWithCustom() {
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getAppValue') ->method('getAppValue')
->with('theming', 'url', 'https://nextcloud.com/')
->with('theming', 'url', $this->defaults->getBaseUrl())
->willReturn('https://example.com/'); ->willReturn('https://example.com/');


$this->assertEquals('https://example.com/', $this->template->getBaseUrl()); $this->assertEquals('https://example.com/', $this->template->getBaseUrl());
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getAppValue') ->method('getAppValue')
->with('theming', 'slogan', 'Safe Data')
->willReturn('Safe Data');
->with('theming', 'slogan', $this->defaults->getSlogan())
->willReturn($this->defaults->getSlogan());


$this->assertEquals('Safe Data', $this->template->getSlogan());
$this->assertEquals($this->defaults->getSlogan(), $this->template->getSlogan());
} }


public function testGetSloganWithCustom() { public function testGetSloganWithCustom() {
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getAppValue') ->method('getAppValue')
->with('theming', 'slogan', 'Safe Data')
->with('theming', 'slogan', $this->defaults->getSlogan())
->willReturn('My custom Slogan'); ->willReturn('My custom Slogan');


$this->assertEquals('My custom Slogan', $this->template->getSlogan()); $this->assertEquals('My custom Slogan', $this->template->getSlogan());
->expects($this->exactly(3)) ->expects($this->exactly(3))
->method('getAppValue') ->method('getAppValue')
->willReturnMap([ ->willReturnMap([
['theming', 'url', 'https://nextcloud.com/', 'url'],
['theming', 'url', $this->defaults->getBaseUrl(), 'url'],
['theming', 'name', 'Nextcloud', 'Name'], ['theming', 'name', 'Nextcloud', 'Name'],
['theming', 'slogan', 'Safe Data', 'Slogan'],
['theming', 'slogan', $this->defaults->getSlogan(), 'Slogan'],
]); ]);


$this->assertEquals('<a href="url" target="_blank" rel="noreferrer">Name</a> – Slogan', $this->template->getShortFooter()); $this->assertEquals('<a href="url" target="_blank" rel="noreferrer">Name</a> – Slogan', $this->template->getShortFooter());
->expects($this->exactly(3)) ->expects($this->exactly(3))
->method('getAppValue') ->method('getAppValue')
->willReturnMap([ ->willReturnMap([
['theming', 'url', 'https://nextcloud.com/', 'url'],
['theming', 'url', $this->defaults->getBaseUrl(), 'url'],
['theming', 'name', 'Nextcloud', 'Name'], ['theming', 'name', 'Nextcloud', 'Name'],
['theming', 'slogan', 'Safe Data', ''],
['theming', 'slogan', $this->defaults->getSlogan(), ''],
]); ]);


$this->assertEquals('<a href="url" target="_blank" rel="noreferrer">Name</a>', $this->template->getShortFooter()); $this->assertEquals('<a href="url" target="_blank" rel="noreferrer">Name</a>', $this->template->getShortFooter());
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getAppValue') ->method('getAppValue')
->with('theming', 'color', '#000')
->willReturn('#000');
->with('theming', 'color', $this->defaults->getColorPrimary())
->willReturn($this->defaults->getColorPrimary());


$this->assertEquals('#000', $this->template->getColorPrimary());
$this->assertEquals($this->defaults->getColorPrimary(), $this->template->getColorPrimary());
} }


public function testgetColorPrimaryWithCustom() { public function testgetColorPrimaryWithCustom() {
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getAppValue') ->method('getAppValue')
->with('theming', 'color', '#000')
->with('theming', 'color', $this->defaults->getColorPrimary())
->willReturn('#fff'); ->willReturn('#fff');


$this->assertEquals('#fff', $this->template->getColorPrimary()); $this->assertEquals('#fff', $this->template->getColorPrimary());
$this->config $this->config
->expects($this->at(3)) ->expects($this->at(3))
->method('getAppValue') ->method('getAppValue')
->with('theming', 'url', 'https://nextcloud.com/')
->willReturn('https://nextcloud.com/');
->with('theming', 'url', $this->defaults->getBaseUrl())
->willReturn($this->defaults->getBaseUrl());


$this->assertSame('https://nextcloud.com/', $this->template->undo('url'));
$this->assertSame($this->defaults->getBaseUrl(), $this->template->undo('url'));
} }


public function testUndoSlogan() { public function testUndoSlogan() {
$this->config $this->config
->expects($this->at(3)) ->expects($this->at(3))
->method('getAppValue') ->method('getAppValue')
->with('theming', 'slogan', 'Safe Data')
->willReturn('Safe Data');
->with('theming', 'slogan', $this->defaults->getSlogan())
->willReturn($this->defaults->getSlogan());


$this->assertSame('Safe Data', $this->template->undo('slogan'));
$this->assertSame($this->defaults->getSlogan(), $this->template->undo('slogan'));
} }


public function testUndoColor() { public function testUndoColor() {
$this->config $this->config
->expects($this->at(3)) ->expects($this->at(3))
->method('getAppValue') ->method('getAppValue')
->with('theming', 'color', '#000')
->willReturn('#000');
->with('theming', 'color', $this->defaults->getColorPrimary())
->willReturn($this->defaults->getColorPrimary());


$this->assertSame('#000', $this->template->undo('color'));
$this->assertSame($this->defaults->getColorPrimary(), $this->template->undo('color'));
} }


public function testUndoDefaultAction() { public function testUndoDefaultAction() {
$this->config->expects($this->at(1))->method('getAppValue')->with('theming', 'logoMime', false)->willReturn('jpeg'); $this->config->expects($this->at(1))->method('getAppValue')->with('theming', 'logoMime', false)->willReturn('jpeg');
$this->config->expects($this->at(2))->method('getAppValue')->with('theming', 'cachebuster', '0')->willReturn('0'); $this->config->expects($this->at(2))->method('getAppValue')->with('theming', 'cachebuster', '0')->willReturn('0');
$this->config->expects($this->at(3))->method('getAppValue')->with('theming', 'backgroundMime', false)->willReturn('jpeg'); $this->config->expects($this->at(3))->method('getAppValue')->with('theming', 'backgroundMime', false)->willReturn('jpeg');
$this->config->expects($this->at(4))->method('getAppValue')->with('theming', 'color', null)->willReturn('#000000');
$this->config->expects($this->at(5))->method('getAppValue')->with('theming', 'color', '#000')->willReturn('#000000');
$this->config->expects($this->at(6))->method('getAppValue')->with('theming', 'color', '#000')->willReturn('#000000');
$this->config->expects($this->at(4))->method('getAppValue')->with('theming', 'color', null)->willReturn($this->defaults->getColorPrimary());
$this->config->expects($this->at(5))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary());
$this->config->expects($this->at(6))->method('getAppValue')->with('theming', 'color', $this->defaults->getColorPrimary())->willReturn($this->defaults->getColorPrimary());


$this->util->expects($this->any())->method('invertTextColor')->with('#000000')->willReturn(false);
$this->util->expects($this->any())->method('invertTextColor')->with($this->defaults->getColorPrimary())->willReturn(false);
$this->cache->expects($this->once())->method('get')->with('getScssVariables')->willReturn(null); $this->cache->expects($this->once())->method('get')->with('getScssVariables')->willReturn(null);
$folder = $this->createMock(ISimpleFolder::class); $folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class); $file = $this->createMock(ISimpleFile::class);
'theming-cachebuster' => '\'0\'', 'theming-cachebuster' => '\'0\'',
'image-logo' => "'absolute-custom-logo?v=0'", 'image-logo' => "'absolute-custom-logo?v=0'",
'image-login-background' => "'absolute-custom-background'", 'image-login-background' => "'absolute-custom-background'",
'color-primary' => '#000000',
'color-primary' => $this->defaults->getColorPrimary(),
'color-primary-text' => '#ffffff' 'color-primary-text' => '#ffffff'


]; ];

+ 0
- 1
lib/private/Server.php View File

$c->getConfig(), $c->getConfig(),
$c->getL10N('theming'), $c->getL10N('theming'),
$c->getURLGenerator(), $c->getURLGenerator(),
new \OC_Defaults(),
$c->getAppDataDir('theming'), $c->getAppDataDir('theming'),
$c->getMemCacheFactory(), $c->getMemCacheFactory(),
new Util($c->getConfig(), $this->getRootFolder(), $this->getAppManager()) new Util($c->getConfig(), $this->getRootFolder(), $this->getAppManager())

Loading…
Cancel
Save