Theming: Clean up css generation and fix tests

This commit is contained in:
Julius Haertl 2016-07-19 14:39:53 +02:00
parent d07f04e4f7
commit acd1172998
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
2 changed files with 87 additions and 55 deletions

View File

@ -217,41 +217,39 @@ class ThemingController extends Controller {
$elementColor = Util::elementColor($color); $elementColor = Util::elementColor($color);
if($color !== '') { if($color !== '') {
$responseCss .= sprintf( $responseCss .= sprintf(
'#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: %s}', '#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: %s}'."\n",
$color $color
); );
$responseCss .= sprintf(' $responseCss .= sprintf('input[type="checkbox"].checkbox:checked + label:before {' .
input[type="checkbox"].checkbox:checked + label:before { 'background-image:url(\'' . \OC::$WEBROOT . '/core/img/actions/checkmark-white.svg\');' .
background-image:url(\'' . \OC::$WEBROOT . '/core/img/actions/checkmark-white.svg\'); 'background-color: %s; background-position: center center; background-size:contain;' .
background-color: %s; background-position: center center; background-size:contain; 'width:12px; height:12px; padding:0; margin:1px 6px 7px 2px;' .
width:12px; height:12px; padding:0; margin:1px 6px 7px 2px; '}' . PHP_EOL,
}',
$elementColor $elementColor
); );
} }
$logo = $this->config->getAppValue($this->appName, 'logoMime'); $logo = $this->config->getAppValue($this->appName, 'logoMime');
if($logo !== '') { if($logo !== '') {
$responseCss .= sprintf('#header .logo { $responseCss .= sprintf(
background-image: url(\'./logo?v='.$cacheBusterValue.'\'); '#header .logo {' .
background-size: contain; 'background-image: url(\'./logo?v='.$cacheBusterValue.'\')' .
} 'background-size: contain;' .
#header .logo-icon { '}' . PHP_EOL .
background-image: url(\'./logo?v='.$cacheBusterValue.'\'); '#header .logo-icon {' .
background-size: contain; 'background-image: url(\'./logo?v='.$cacheBusterValue.'\');' .
}' 'background-size: contain;' .
'}' . PHP_EOL
); );
} }
$backgroundLogo = $this->config->getAppValue($this->appName, 'backgroundMime'); $backgroundLogo = $this->config->getAppValue($this->appName, 'backgroundMime');
if($backgroundLogo !== '') { if($backgroundLogo !== '') {
$responseCss .= '#body-login { $responseCss .= '#body-login {background-image: url(\'./loginbackground?v='.$cacheBusterValue.'\');}' . PHP_EOL;
background-image: url(\'./loginbackground?v='.$cacheBusterValue.'\');
}';
} }
if(Util::invertTextColor($color)) { if(Util::invertTextColor($color)) {
$responseCss .= '#header .header-appname, #expandDisplayName { color: #000000; } '; $responseCss .= '#header .header-appname, #expandDisplayName { color: #000000; }' . PHP_EOL;
$responseCss .= '#header .icon-caret { background-image: url(\'' . \OC::$WEBROOT . '/core/img/actions/caret-dark.svg\'); } '; $responseCss .= '#header .icon-caret { background-image: url(\'' . \OC::$WEBROOT . '/core/img/actions/caret-dark.svg\'); }' . PHP_EOL;
$responseCss .= '.searchbox input[type="search"] { background: transparent url(\'' . \OC::$WEBROOT . '/core/img/actions/search.svg\') no-repeat 6px center; color: #000; }'; $responseCss .= '.searchbox input[type="search"] { background: transparent url(\'' . \OC::$WEBROOT . '/core/img/actions/search.svg\') no-repeat 6px center; color: #000; }' . PHP_EOL;
$responseCss .= '.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid { color: #000; border: 1px solid rgba(0, 0, 0, .5); }'; $responseCss .= '.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid { color: #000; border: 1px solid rgba(0, 0, 0, .5); }' . PHP_EOL;
} }
\OC_Response::setExpiresHeader(gmdate('D, d M Y H:i:s', time() + (60*60*24*45)) . ' GMT'); \OC_Response::setExpiresHeader(gmdate('D, d M Y H:i:s', time() + (60*60*24*45)) . ' GMT');

View File

@ -327,7 +327,13 @@ class ThemingControllerTest extends TestCase {
->with('theming', 'backgroundMime', '') ->with('theming', 'backgroundMime', '')
->willReturn(''); ->willReturn('');
$expected = new Http\DataDownloadResponse('#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: #000}', 'style', 'text/css'); $expectedCss = '#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: #000}' . PHP_EOL .
'input[type="checkbox"].checkbox:checked + label:before {' .
'background-image:url(\'' . \OC::$WEBROOT . '/core/img/actions/checkmark-white.svg\');' .
'background-color: #000; background-position: center center; background-size:contain;' .
'width:12px; height:12px; padding:0; margin:1px 6px 7px 2px;' .
'}' . PHP_EOL;
$expected = new Http\DataDownloadResponse($expectedCss, 'style', 'text/css');
$expected->cacheFor(3600); $expected->cacheFor(3600);
@$this->assertEquals($expected, $this->themingController->getStylesheet()); @$this->assertEquals($expected, $this->themingController->getStylesheet());
} }
@ -354,7 +360,17 @@ class ThemingControllerTest extends TestCase {
->with('theming', 'backgroundMime', '') ->with('theming', 'backgroundMime', '')
->willReturn(''); ->willReturn('');
$expected = new Http\DataDownloadResponse('#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: #fff}#header .header-appname, #expandDisplayName { color: #000000; } #header .icon-caret { background-image: url(\'' . \OC::$WEBROOT . '/core/img/actions/caret-dark.svg\'); } .searchbox input[type="search"] { background: transparent url(\'' . \OC::$WEBROOT . '/core/img/actions/search.svg\') no-repeat 6px center; color: #000; }.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid { color: #000; border: 1px solid rgba(0, 0, 0, .5); }', 'style', 'text/css'); $expectedCss = '#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: #fff}' . PHP_EOL .
'input[type="checkbox"].checkbox:checked + label:before {' .
'background-image:url(\'' . \OC::$WEBROOT . '/core/img/actions/checkmark-white.svg\');' .
'background-color: #969696; background-position: center center; background-size:contain;' .
'width:12px; height:12px; padding:0; margin:1px 6px 7px 2px;' .
'}' . PHP_EOL .
'#header .header-appname, #expandDisplayName { color: #000000; }' . PHP_EOL .
'#header .icon-caret { background-image: url(\'' . \OC::$WEBROOT . '/core/img/actions/caret-dark.svg\'); }' . PHP_EOL .
'.searchbox input[type="search"] { background: transparent url(\'' . \OC::$WEBROOT . '/core/img/actions/search.svg\') no-repeat 6px center; color: #000; }' . PHP_EOL .
'.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid { color: #000; border: 1px solid rgba(0, 0, 0, .5); }' . PHP_EOL;
$expected = new Http\DataDownloadResponse($expectedCss, 'style', 'text/css');
$expected->cacheFor(3600); $expected->cacheFor(3600);
@$this->assertEquals($expected, $this->themingController->getStylesheet()); @$this->assertEquals($expected, $this->themingController->getStylesheet());
} }
@ -381,14 +397,15 @@ class ThemingControllerTest extends TestCase {
->with('theming', 'backgroundMime', '') ->with('theming', 'backgroundMime', '')
->willReturn(''); ->willReturn('');
$expected = new Http\DataDownloadResponse('#header .logo { $expectedCss = '#header .logo {' .
background-image: url(\'./logo?v=0\'); 'background-image: url(\'./logo?v=0\')' .
background-size: contain; 'background-size: contain;' .
} '}' . PHP_EOL .
#header .logo-icon { '#header .logo-icon {' .
background-image: url(\'./logo?v=0\'); 'background-image: url(\'./logo?v=0\');' .
background-size: contain; 'background-size: contain;' .
}', 'style', 'text/css'); '}' . PHP_EOL;
$expected = new Http\DataDownloadResponse($expectedCss, 'style', 'text/css');
$expected->cacheFor(3600); $expected->cacheFor(3600);
@$this->assertEquals($expected, $this->themingController->getStylesheet()); @$this->assertEquals($expected, $this->themingController->getStylesheet());
} }
@ -415,9 +432,8 @@ class ThemingControllerTest extends TestCase {
->with('theming', 'backgroundMime', '') ->with('theming', 'backgroundMime', '')
->willReturn('text/svg'); ->willReturn('text/svg');
$expected = new Http\DataDownloadResponse('#body-login { $expectedCss = '#body-login {background-image: url(\'./loginbackground?v=0\');}' . PHP_EOL;
background-image: url(\'./loginbackground?v=0\'); $expected = new Http\DataDownloadResponse($expectedCss, 'style', 'text/css');
}', 'style', 'text/css');
$expected->cacheFor(3600); $expected->cacheFor(3600);
@$this->assertEquals($expected, $this->themingController->getStylesheet()); @$this->assertEquals($expected, $this->themingController->getStylesheet());
} }
@ -444,16 +460,23 @@ class ThemingControllerTest extends TestCase {
->with('theming', 'backgroundMime', '') ->with('theming', 'backgroundMime', '')
->willReturn('image/png'); ->willReturn('image/png');
$expected = new Http\DataDownloadResponse('#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: #000}#header .logo { $expectedCss = '#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: #000}' . PHP_EOL .
background-image: url(\'./logo?v=0\'); 'input[type="checkbox"].checkbox:checked + label:before {' .
background-size: contain; 'background-image:url(\'' . \OC::$WEBROOT . '/core/img/actions/checkmark-white.svg\');' .
} 'background-color: #000; background-position: center center; background-size:contain;' .
#header .logo-icon { 'width:12px; height:12px; padding:0; margin:1px 6px 7px 2px;' .
background-image: url(\'./logo?v=0\'); '}' . PHP_EOL;
background-size: contain; $expectedCss .= '#header .logo {' .
}#body-login { 'background-image: url(\'./logo?v=0\')' .
background-image: url(\'./loginbackground?v=0\'); 'background-size: contain;' .
}', 'style', 'text/css'); '}' . PHP_EOL .
'#header .logo-icon {' .
'background-image: url(\'./logo?v=0\');' .
'background-size: contain;' .
'}' . PHP_EOL;
$expectedCss .= '#body-login {background-image: url(\'./loginbackground?v=0\');}' . PHP_EOL;
$expected = new Http\DataDownloadResponse($expectedCss, 'style', 'text/css');
$expected->cacheFor(3600); $expected->cacheFor(3600);
@$this->assertEquals($expected, $this->themingController->getStylesheet()); @$this->assertEquals($expected, $this->themingController->getStylesheet());
} }
@ -479,16 +502,27 @@ class ThemingControllerTest extends TestCase {
->with('theming', 'backgroundMime', '') ->with('theming', 'backgroundMime', '')
->willReturn('image/png'); ->willReturn('image/png');
$expected = new Http\DataDownloadResponse('#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: #fff}#header .logo {
background-image: url(\'./logo?v=0\'); $expectedCss = '#body-user #header,#body-settings #header,#body-public #header,#body-login,.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid {background-color: #fff}' . PHP_EOL .
background-size: contain; 'input[type="checkbox"].checkbox:checked + label:before {' .
} 'background-image:url(\'' . \OC::$WEBROOT . '/core/img/actions/checkmark-white.svg\');' .
#header .logo-icon { 'background-color: #969696; background-position: center center; background-size:contain;' .
background-image: url(\'./logo?v=0\'); 'width:12px; height:12px; padding:0; margin:1px 6px 7px 2px;' .
background-size: contain; '}' . PHP_EOL;
}#body-login { $expectedCss .= '#header .logo {' .
background-image: url(\'./loginbackground?v=0\'); 'background-image: url(\'./logo?v=0\')' .
}#header .header-appname, #expandDisplayName { color: #000000; } #header .icon-caret { background-image: url(\'' . \OC::$WEBROOT . '/core/img/actions/caret-dark.svg\'); } .searchbox input[type="search"] { background: transparent url(\'' . \OC::$WEBROOT . '/core/img/actions/search.svg\') no-repeat 6px center; color: #000; }.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid { color: #000; border: 1px solid rgba(0, 0, 0, .5); }', 'style', 'text/css'); 'background-size: contain;' .
'}' . PHP_EOL .
'#header .logo-icon {' .
'background-image: url(\'./logo?v=0\');' .
'background-size: contain;' .
'}' . PHP_EOL;
$expectedCss .= '#body-login {background-image: url(\'./loginbackground?v=0\');}' . PHP_EOL;
$expectedCss .= '#header .header-appname, #expandDisplayName { color: #000000; }' . PHP_EOL .
'#header .icon-caret { background-image: url(\'' . \OC::$WEBROOT . '/core/img/actions/caret-dark.svg\'); }' . PHP_EOL .
'.searchbox input[type="search"] { background: transparent url(\'' . \OC::$WEBROOT . '/core/img/actions/search.svg\') no-repeat 6px center; color: #000; }' . PHP_EOL .
'.searchbox input[type="search"]:focus,.searchbox input[type="search"]:active,.searchbox input[type="search"]:valid { color: #000; border: 1px solid rgba(0, 0, 0, .5); }' . PHP_EOL;
$expected = new Http\DataDownloadResponse($expectedCss, 'style', 'text/css');
$expected->cacheFor(3600); $expected->cacheFor(3600);
@$this->assertEquals($expected, $this->themingController->getStylesheet()); @$this->assertEquals($expected, $this->themingController->getStylesheet());
} }