FIX SSViewer::add_themes() to properly prepend

This commit is contained in:
Andrew Aitken-Fincham 2017-09-12 12:32:28 +01:00
parent c7c0ee39f1
commit 6613826ed8
2 changed files with 23 additions and 1 deletions

View File

@ -165,7 +165,10 @@ class SSViewer implements Flushable
public static function add_themes($themes = [])
{
SSViewer::config()->merge('themes', $themes);
$currentThemes = SSViewer::get_themes();
$finalThemes = array_merge($themes, $currentThemes);
// array_values is used to ensure sequential array keys as array_unique can leave gaps
SSViewer::set_themes(array_values(array_unique($finalThemes)));
}
public static function get_themes()

View File

@ -80,6 +80,25 @@ class SSViewerTest extends SapphireTest
);
}
/**
* Tests for themes helper functions, ensuring they behave as defined in the RFC at
* https://github.com/silverstripe/silverstripe-framework/issues/5604
*/
public function testThemesHelpers()
{
// Test set_themes()
SSViewer::set_themes(['mytheme', '$default']);
$this->assertEquals(['mytheme', '$default'], SSViewer::get_themes());
// Ensure add_themes() prepends
SSViewer::add_themes(['my_more_important_theme']);
$this->assertEquals(['my_more_important_theme', 'mytheme', '$default'], SSViewer::get_themes());
// Ensure add_themes() on theme already in cascade promotes it to the top
SSViewer::add_themes(['mytheme']);
$this->assertEquals(['mytheme', 'my_more_important_theme', '$default'], SSViewer::get_themes());
}
/**
* Test that a template without a <head> tag still renders.
*/