mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API CHANGE: Moved ManifestBuilder::get_themes() to SSViewer::get_themes().
This commit is contained in:
parent
969aa0b51e
commit
5c972b231d
24
core/SSViewer.php
Executable file → Normal file
24
core/SSViewer.php
Executable file → Normal file
@ -306,6 +306,30 @@ class SSViewer {
|
||||
return self::current_theme() ? THEMES_DIR . "/" . self::current_theme() : project();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of theme names present in a directory.
|
||||
*
|
||||
* @param string $path
|
||||
* @param bool $subthemes Include subthemes (default false).
|
||||
* @return array
|
||||
*/
|
||||
public static function get_themes($path = null, $subthemes = false) {
|
||||
$path = rtrim($path ? $path : THEMES_PATH, '/');
|
||||
$themes = array();
|
||||
|
||||
if (!is_dir($path)) return $themes;
|
||||
|
||||
foreach (scandir($path) as $item) {
|
||||
if ($item[0] != '.' && is_dir("$path/$item")) {
|
||||
if ($subthemes || !strpos($item, '_')) {
|
||||
$themes[$item] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $themes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
@ -116,7 +116,7 @@ class SiteConfig extends DataObject implements PermissionProvider {
|
||||
* @return array of theme directory names
|
||||
*/
|
||||
public function getAvailableThemes($baseDir = null) {
|
||||
$themes = ManifestBuilder::get_themes($baseDir);
|
||||
$themes = SSViewer::get_themes($baseDir);
|
||||
foreach(self::$disabled_themes as $theme) {
|
||||
if(isset($themes[$theme])) unset($themes[$theme]);
|
||||
}
|
||||
|
@ -127,34 +127,6 @@ class ManifestBuilderTest extends SapphireTest {
|
||||
global $project;
|
||||
}
|
||||
|
||||
function testThemeRetrieval() {
|
||||
$ds = DIRECTORY_SEPARATOR;
|
||||
$testThemeBaseDir = TEMP_FOLDER . $ds . 'test-themes';
|
||||
|
||||
if(file_exists($testThemeBaseDir)) Filesystem::removeFolder($testThemeBaseDir);
|
||||
|
||||
mkdir($testThemeBaseDir);
|
||||
mkdir($testThemeBaseDir . $ds . 'blackcandy');
|
||||
mkdir($testThemeBaseDir . $ds . 'blackcandy_blog');
|
||||
mkdir($testThemeBaseDir . $ds . 'darkshades');
|
||||
mkdir($testThemeBaseDir . $ds . 'darkshades_blog');
|
||||
|
||||
$this->assertEquals(array(
|
||||
'blackcandy' => 'blackcandy',
|
||||
'darkshades' => 'darkshades'
|
||||
), ManifestBuilder::get_themes($testThemeBaseDir), 'Our test theme directory contains 2 themes');
|
||||
|
||||
$this->assertEquals(array(
|
||||
'blackcandy' => 'blackcandy',
|
||||
'blackcandy_blog' => 'blackcandy_blog',
|
||||
'darkshades' => 'darkshades',
|
||||
'darkshades_blog' => 'darkshades_blog'
|
||||
), ManifestBuilder::get_themes($testThemeBaseDir, true), 'Our test theme directory contains 2 themes and 2 sub-themes');
|
||||
|
||||
// Remove all the test themes we created
|
||||
Filesystem::removeFolder($testThemeBaseDir);
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
global $_CLASS_MANIFEST, $_ALL_CLASSES, $project;
|
||||
|
||||
|
@ -499,6 +499,38 @@ after')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers SSViewer::get_themes()
|
||||
*/
|
||||
function testThemeRetrieval() {
|
||||
$ds = DIRECTORY_SEPARATOR;
|
||||
$testThemeBaseDir = TEMP_FOLDER . $ds . 'test-themes';
|
||||
|
||||
if(file_exists($testThemeBaseDir)) Filesystem::removeFolder($testThemeBaseDir);
|
||||
|
||||
mkdir($testThemeBaseDir);
|
||||
mkdir($testThemeBaseDir . $ds . 'blackcandy');
|
||||
mkdir($testThemeBaseDir . $ds . 'blackcandy_blog');
|
||||
mkdir($testThemeBaseDir . $ds . 'darkshades');
|
||||
mkdir($testThemeBaseDir . $ds . 'darkshades_blog');
|
||||
|
||||
$this->assertEquals(array(
|
||||
'blackcandy' => 'blackcandy',
|
||||
'darkshades' => 'darkshades'
|
||||
), SSViewer::get_themes($testThemeBaseDir), 'Our test theme directory contains 2 themes');
|
||||
|
||||
$this->assertEquals(array(
|
||||
'blackcandy' => 'blackcandy',
|
||||
'blackcandy_blog' => 'blackcandy_blog',
|
||||
'darkshades' => 'darkshades',
|
||||
'darkshades_blog' => 'darkshades_blog'
|
||||
), SSViewer::get_themes($testThemeBaseDir, true), 'Our test theme directory contains 2 themes and 2 sub-themes');
|
||||
|
||||
// Remove all the test themes we created
|
||||
Filesystem::removeFolder($testThemeBaseDir);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user