mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #7370 from andrewandante/FIX/add_themes
FIX SSViewer::add_themes() to properly prepend
This commit is contained in:
commit
546b4dedcf
@ -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()
|
||||
|
@ -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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user