From bbe908410773f9112839d5e9a91cc6bfa110c0a1 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Tue, 12 Apr 2011 23:34:57 +0200
Subject: [PATCH 1/2] Re-rolled against HEAD.

---
 modules/simpletest/tests/theme.test                |    2 ++
 modules/simpletest/tests/theme_test.module         |    8 ++++++++
 .../tests/themes}/test_theme/template.php          |    0
 .../tests/themes}/test_theme/test_theme.info       |    0
 modules/system/system.api.php                      |   17 +++++++++++++++++
 modules/system/system.module                       |   12 ++++++++++++
 .../update_test_basetheme.info                     |    0
 .../update_test_subtheme/update_test_subtheme.info |    0
 modules/update/tests/update_test.module            |    9 +++++++++
 themes/tests/README.txt                            |    4 ----
 10 files changed, 48 insertions(+), 4 deletions(-)
 rename {themes/tests => modules/simpletest/tests/themes}/test_theme/template.php (100%)
 rename {themes/tests => modules/simpletest/tests/themes}/test_theme/test_theme.info (100%)
 rename {themes/tests => modules/update/tests/themes}/update_test_basetheme/update_test_basetheme.info (100%)
 rename {themes/tests => modules/update/tests/themes}/update_test_subtheme/update_test_subtheme.info (100%)
 delete mode 100644 themes/tests/README.txt

diff --git a/modules/simpletest/tests/theme.test b/modules/simpletest/tests/theme.test
index d064359..2107677 100644
--- a/modules/simpletest/tests/theme.test
+++ b/modules/simpletest/tests/theme.test
@@ -9,6 +9,8 @@
  * Unit tests for the Theme API.
  */
 class ThemeUnitTest extends DrupalWebTestCase {
+  protected $profile = 'testing';
+
   public static function getInfo() {
     return array(
       'name' => 'Theme API',
diff --git a/modules/simpletest/tests/theme_test.module b/modules/simpletest/tests/theme_test.module
index 160d192..9cec538 100644
--- a/modules/simpletest/tests/theme_test.module
+++ b/modules/simpletest/tests/theme_test.module
@@ -1,6 +1,14 @@
 <?php
 
 /**
+ * Implements hook_system_theme_info().
+ */
+function theme_test_system_theme_info() {
+  $themes['test_theme'] = drupal_get_path('module', 'theme_test') . '/themes/test_theme/test_theme.info';
+  return $themes;
+}
+
+/**
  * Implements hook_menu().
  */
 function theme_test_menu() {
diff --git a/themes/tests/test_theme/template.php b/modules/simpletest/tests/themes/test_theme/template.php
similarity index 100%
rename from themes/tests/test_theme/template.php
rename to modules/simpletest/tests/themes/test_theme/template.php
diff --git a/themes/tests/test_theme/test_theme.info b/modules/simpletest/tests/themes/test_theme/test_theme.info
similarity index 100%
rename from themes/tests/test_theme/test_theme.info
rename to modules/simpletest/tests/themes/test_theme/test_theme.info
diff --git a/modules/system/system.api.php b/modules/system/system.api.php
index d040ab3..f5b8dfd 100644
--- a/modules/system/system.api.php
+++ b/modules/system/system.api.php
@@ -1487,6 +1487,23 @@ function hook_module_implements_alter(&$implementations, $hook) {
 }
 
 /**
+ * Return additional themes provided by modules.
+ *
+ * This hook is invoked from _system_rebuild_theme_data() and allows modules to
+ * register additional themes outside of the regular 'themes' directories of a
+ * Drupal installation. It is most commonly used to register hidden themes for
+ * testing purposes.
+ *
+ * @return
+ *   An associative array. Each key is the system name of a theme and each value
+ *   is the corresponding path to the theme's .info file.
+ */
+function hook_system_theme_info() {
+  $themes['mymodule_test_theme'] = drupal_get_path('module', 'mymodule') . '/mymodule_test_theme/mymodule_test_theme.info';
+  return $themes;
+}
+
+/**
  * Alter the information parsed from module and theme .info files
  *
  * This hook is invoked in _system_rebuild_module_data() and in
diff --git a/modules/system/system.module b/modules/system/system.module
index b11e77e..8739424 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -2465,6 +2465,18 @@ function _system_update_bootstrap_status() {
 function _system_rebuild_theme_data() {
   // Find themes
   $themes = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.info$/', 'themes');
+  // Allow modules to add further themes.
+  if ($module_themes = module_invoke_all('system_theme_info')) {
+    foreach ($module_themes as $name => $uri) {
+      // @see file_scan_directory()
+      $themes[$name] = (object) array(
+        'uri' => $uri,
+        'filename' => pathinfo($uri, PATHINFO_FILENAME),
+        'name' => $name,
+      );
+    }
+  }
+
   // Find theme engines
   $engines = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.engine$/', 'themes/engines');
 
diff --git a/themes/tests/update_test_basetheme/update_test_basetheme.info b/modules/update/tests/themes/update_test_basetheme/update_test_basetheme.info
similarity index 100%
rename from themes/tests/update_test_basetheme/update_test_basetheme.info
rename to modules/update/tests/themes/update_test_basetheme/update_test_basetheme.info
diff --git a/themes/tests/update_test_subtheme/update_test_subtheme.info b/modules/update/tests/themes/update_test_subtheme/update_test_subtheme.info
similarity index 100%
rename from themes/tests/update_test_subtheme/update_test_subtheme.info
rename to modules/update/tests/themes/update_test_subtheme/update_test_subtheme.info
diff --git a/modules/update/tests/update_test.module b/modules/update/tests/update_test.module
index 4acb6ef..e7ee43e 100644
--- a/modules/update/tests/update_test.module
+++ b/modules/update/tests/update_test.module
@@ -1,6 +1,15 @@
 <?php
 
 /**
+ * Implements hook_system_theme_info().
+ */
+function update_test_system_theme_info() {
+  $themes['update_test_basetheme'] = drupal_get_path('module', 'update_test') . '/themes/update_test_basetheme/update_test_basetheme.info';
+  $themes['update_test_subtheme'] = drupal_get_path('module', 'update_test') . '/themes/update_test_subtheme/update_test_subtheme.info';
+  return $themes;
+}
+
+/**
  * Implements hook_menu().
  */
 function update_test_menu() {
diff --git a/themes/tests/README.txt b/themes/tests/README.txt
deleted file mode 100644
index 5ddaa8c..0000000
--- a/themes/tests/README.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-
-The themes in this subdirectory are all used by the Drupal core testing
-framework. They are not functioning themes that could be used on a real site
-and are hidden in the administrative user interface.
-- 
1.7.4.msysgit.0


From cdce8ca9df41fbb1ae86be637e47ae2ecd83da9d Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Sat, 1 Oct 2011 18:41:43 +0200
Subject: [PATCH 2/2] Clarified to be for testing purposes only.

---
 modules/system/system.api.php |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/modules/system/system.api.php b/modules/system/system.api.php
index f5b8dfd..eae66f1 100644
--- a/modules/system/system.api.php
+++ b/modules/system/system.api.php
@@ -1489,10 +1489,12 @@ function hook_module_implements_alter(&$implementations, $hook) {
 /**
  * Return additional themes provided by modules.
  *
+ * Only use this hook for testing purposes. Use a hidden MYMODULE_test.module
+ * to implement this hook. Testing themes should be hidden, too.
+ *
  * This hook is invoked from _system_rebuild_theme_data() and allows modules to
  * register additional themes outside of the regular 'themes' directories of a
- * Drupal installation. It is most commonly used to register hidden themes for
- * testing purposes.
+ * Drupal installation.
  *
  * @return
  *   An associative array. Each key is the system name of a theme and each value
-- 
1.7.4.msysgit.0

