From 5c972b231d00117ca0cf4a32d08b59ed760256c6 Mon Sep 17 00:00:00 2001 From: ajshort Date: Sat, 26 Feb 2011 17:55:04 +1100 Subject: [PATCH] API CHANGE: Moved ManifestBuilder::get_themes() to SSViewer::get_themes(). --- core/SSViewer.php | 24 ++++++++++++++++++++++++ core/model/SiteConfig.php | 2 +- tests/ManifestBuilderTest.php | 28 ---------------------------- tests/SSViewerTest.php | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 29 deletions(-) mode change 100755 => 100644 core/SSViewer.php diff --git a/core/SSViewer.php b/core/SSViewer.php old mode 100755 new mode 100644 index 506c78e32..3b89c664e --- a/core/SSViewer.php +++ b/core/SSViewer.php @@ -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 */ diff --git a/core/model/SiteConfig.php b/core/model/SiteConfig.php index 02fb87efd..72b8c60f1 100644 --- a/core/model/SiteConfig.php +++ b/core/model/SiteConfig.php @@ -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]); } diff --git a/tests/ManifestBuilderTest.php b/tests/ManifestBuilderTest.php index 88587daa3..acdaa0edc 100644 --- a/tests/ManifestBuilderTest.php +++ b/tests/ManifestBuilderTest.php @@ -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; diff --git a/tests/SSViewerTest.php b/tests/SSViewerTest.php index 7306947b5..f4ecef103 100644 --- a/tests/SSViewerTest.php +++ b/tests/SSViewerTest.php @@ -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); + } + } /**