API CHANGE: Moved ManifestBuilder::get_themes() to SSViewer::get_themes().

This commit is contained in:
ajshort 2011-02-26 17:55:04 +11:00
parent 969aa0b51e
commit 5c972b231d
4 changed files with 57 additions and 29 deletions

24
core/SSViewer.php Executable file → Normal file
View 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
*/

View File

@ -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]);
}

View File

@ -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;

View File

@ -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);
}
}
/**