Optimize chek if background is themed

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2020-11-20 19:28:18 +01:00
parent 691409cdec
commit a0c0918ce2
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
2 changed files with 6 additions and 26 deletions

View File

@ -250,13 +250,6 @@ class Util {
public function isBackgroundThemed() {
$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', '');
$backgroundExists = true;
try {
$this->appData->getFolder('images')->getFile('background');
} catch (\Exception $e) {
$backgroundExists = false;
}
return $backgroundLogo && $backgroundLogo !== 'backgroundColor' && $backgroundExists;
return $backgroundLogo !== '' && $backgroundLogo !== 'backgroundColor';
}
}

View File

@ -216,32 +216,19 @@ class UtilTest extends TestCase {
public function dataIsBackgroundThemed() {
return [
[false, false, false],
['png', true, true],
['backgroundColor', false, false],
['', false],
['png', true],
['backgroundColor', false],
];
}
/**
* @dataProvider dataIsBackgroundThemed
*/
public function testIsBackgroundThemed($backgroundMime, $fileFound, $expected) {
public function testIsBackgroundThemed($backgroundMime, $expected) {
$this->config->expects($this->once())
->method('getAppValue')
->with('theming', 'backgroundMime', false)
->with('theming', 'backgroundMime', '')
->willReturn($backgroundMime);
$folder = $this->createMock(ISimpleFolder::class);
if ($fileFound) {
$folder->expects($this->once())
->method('getFile')
->willReturn($this->createMock(ISimpleFile::class));
} else {
$folder->expects($this->once())
->method('getFile')
->willThrowException(new NotFoundException());
}
$this->appData->expects($this->once())
->method('getFolder')
->willReturn($folder);
$this->assertEquals($expected, $this->util->isBackgroundThemed());
}
}