ENHANCEMENT ManifestBuilder::get_manifest_info() now uses ManifestBuilder::get_themes() instead of doing it's own retrieval of available themes

MINOR Added ManifestBuilderTest::testThemeRetrieval() to test ManifestBuilder::get_themes() (from r98091)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102583 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-04-13 02:02:52 +00:00
parent 72bb124951
commit 753a8804ac
2 changed files with 78 additions and 4 deletions

View File

@ -148,6 +148,34 @@ class ManifestBuilder {
}
}
/**
* Get themes from a particular directory.
*
* @param string $baseDir Optional: Absolute path to theme directory for testing e.g. "/Users/sharvey/Sites/test24/themes"
* @param boolean $includeSubThemes If set to TRUE, sub-themes such as "blackcandy_blog" are included too
* @return array indexed array of theme directories
*/
public static function get_themes($baseDir = null, $includeSubThemes = false) {
// If no base directory specified, the default is the project root
if(!$baseDir) $baseDir = BASE_PATH . DIRECTORY_SEPARATOR . THEMES_DIR;
$themes = array();
$handle = opendir($baseDir);
if($handle) {
while(false !== ($file = readdir($handle))) {
$fullPath = $baseDir . DIRECTORY_SEPARATOR . $file;
if(strpos($file, '.') === false && is_dir($fullPath)) {
$include = $includeSubThemes ? true : false;
if(strpos($file, '_') === false) {
$include = true;
}
if($include) $themes[] = $file;
}
}
closedir($handle);
}
return $themes;
}
/**
* Return an array containing information for the manifest
* @param $baseDir The root directory to analyse
@ -206,17 +234,14 @@ class ManifestBuilder {
if(preg_match("/\\\$project\s*=\s*[^\n\r]+[\n\r]/", file_get_contents("$baseDir/$filename/_config.php"), $parts)) {
eval($parts[0]);
}
}
}
}
// Get themes
if(file_exists("$baseDir/themes")) {
$themeDirs = scandir("$baseDir/themes");
$themeDirs = self::get_themes("$baseDir/themes", true);
foreach($themeDirs as $themeDir) {
if(substr($themeDir,0,1) == '.') continue;
// The theme something_forum is understood as being a part of the theme something
$themeName = strtok($themeDir, '_');
ManifestBuilder::getTemplateManifest($baseDir, "themes/$themeDir", $excludedFolders, $templateManifest, $cssManifest, $themeName);
}

View File

@ -127,6 +127,55 @@ class ManifestBuilderTest extends SapphireTest {
global $project;
}
function testThemeRetrieval() {
$ds = DIRECTORY_SEPARATOR;
$testThemeBaseDir = TEMP_FOLDER . $ds . 'test-themes';
// If the test directory somehow exists after a failed test, remove all the files and directories inside
if(file_exists($testThemeBaseDir)) {
$handle = opendir($testThemeBaseDir);
while(false !== ($file = readdir($handle))) {
$fullPath = $testThemeBaseDir . $ds . $file;
if(strpos($file, '.') === false) {
if(is_dir($fullPath)) rmdir($fullPath);
else unlink($fullPath);
}
}
closedir($handle);
rmdir($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',
'darkshades'
), ManifestBuilder::get_themes($testThemeBaseDir), 'Our test theme directory contains 2 themes');
$this->assertEquals(array(
'blackcandy',
'blackcandy_blog',
'darkshades',
'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
$handle = opendir($testThemeBaseDir);
while(false !== ($file = readdir($handle))) {
$fullPath = $testThemeBaseDir . $ds . $file;
if(strpos($file, '.') === false) {
if(is_dir($fullPath)) rmdir($fullPath);
else unlink($fullPath);
}
}
closedir($handle);
rmdir($testThemeBaseDir);
}
function tearDown() {
global $_CLASS_MANIFEST, $_ALL_CLASSES, $project;