Skip to content

Commit

Permalink
Handle minified in themes list; fixes #3310
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Dec 19, 2017
1 parent 3c22eb0 commit baca5c9
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 12 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ before_script:
- if [[ "$LDAP" == "true" ]]; then ./tests/LDAP/ldap_fixtures.sh > /dev/null; fi
#APCu
- phpenv config-add tests/enable-apcu.ini
- if [[ "$UPDATE" == "true" ]]; then ./vendor/bin/robo --load-from tools minify; fi
script:
- mysql -u root -e 'select version();'
- if [[ "$UPDATE" == "true" ]]; then composer testdb; fi
Expand Down
43 changes: 31 additions & 12 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1142,18 +1142,14 @@ function showFormUserPrefs($data = []) {

echo "<tr class='tab_bg_2'>";
echo "<td><label for='theme-selector'>" . __("Color palette") . "</label></td><td>";
$themes_files = scandir(GLPI_ROOT."/css/palettes/");
echo "<select name='palette' id='theme-selector'>";
foreach ($themes_files as $key => $file) {
if (strpos($file, ".css") !== false) {
$name = substr($file, 0, -4);
$selected = "";
if ($data["palette"] == $name) {
$selected = "selected='selected'";
}
echo "<option value='$name' $selected>".ucfirst($name)."</option>";
}
}
echo Html::select(
'palette',
$this->getPalettes(),
[
'id' => 'theme-selector',
'selected' => $data['palette']
]
);
echo Html::scriptBlock("
function formatThemes(theme) {
if (!theme.id) {
Expand Down Expand Up @@ -2810,4 +2806,27 @@ public static function getCache($optname, $context = 'core') {
//Toolbox::logDebug("CACHE $optname", get_class($cache));
return $cache;
}

/**
* Get available palettes
*
* @return array
*/
public function getPalettes() {
$themes_files = scandir(GLPI_ROOT."/css/palettes/");
$themes = [];
foreach ($themes_files as $file) {
if (strpos($file, ".css") !== false) {
$name = substr($file, 0, -4);
if (strpos($name, '.min') !== false) {
$name = substr($name, 0, -4);
if (isset($themes[$name])) {
continue;
}
}
$themes[$name] = ucfirst($name);
}
}
return $themes;
}
}
26 changes: 26 additions & 0 deletions tests/units/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,30 @@ public function testGetRights() {
UPDATE => 'Update'
]);
}

public function testGetPalettes() {
$expected = [
'aerialgreen' => 'Aerialgreen',
'auror' => 'Auror',
'automn' => 'Automn',
'classic' => 'Classic',
'clockworkorange' => 'Clockworkorange',
'dark' => 'Dark',
'flood' => 'Flood',
'greenflat' => 'Greenflat',
'hipster' => 'Hipster',
'icecream' => 'Icecream',
'lightblue' => 'Lightblue',
'premiumred' => 'Premiumred',
'purplehaze' => 'Purplehaze',
'teclib' => 'Teclib',
'vintage' => 'Vintage'
];
$this
->if($this->newTestedInstance)
->then
->array($this->testedInstance->getPalettes())
->isIdenticalTo($expected);

}
}

0 comments on commit baca5c9

Please sign in to comment.