From 57f6b458b021ea983b1158fc016f6a9eef59ef3b Mon Sep 17 00:00:00 2001
From: Bob Vincent <bobvin@pillars.net>
Date: Sat, 1 Oct 2011 18:05:16 -0400
Subject: [PATCH] Issue #953336: Allow contributed modules to test
 theme-related functionality.

---
 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                      |   21 ++++++++++++++++++++
 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, 52 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 d064359f253a2fc268a0329c921008a308057c24..21076776492e85071aa0f22a6d416b6ce776a13d 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 160d192dd82a565858bdafc82dab953b2b952ef9..9cec5381d23ccf87bb90fac5e4963fde65e10b46 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 d040ab39834aae9dec5955f96810e0293e5c343f..cb96ab2b9e5e60a00520352c2f33a4ff73fda6fe 100644
--- a/modules/system/system.api.php
+++ b/modules/system/system.api.php
@@ -1487,6 +1487,27 @@ 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.
+ *
+ * @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.
+ *
+ * @see http://drupal.org/node/302577
+ */
+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 b11e77e297c0574337aae3dbc68eef78473e5e5f..873942420bc226deedab2d5a5fa3fd80e8c91c4a 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 4acb6ef837e605af25927aa7aeda03fea82212de..e7ee43eecf2eb5bee9cfbee201675fb734d1067b 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 5ddaa8caf22eedc2dc5e854f695b4a89614710ad..0000000000000000000000000000000000000000
--- 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.5.4

