Index: modules/simpletest/tests/theme.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/theme.test,v
retrieving revision 1.9
diff -u -p -r1.9 theme.test
--- modules/simpletest/tests/theme.test	16 Oct 2009 08:27:41 -0000	1.9
+++ modules/simpletest/tests/theme.test	2 Nov 2009 06:05:01 -0000
@@ -93,3 +93,30 @@ class ThemeTableUnitTest extends DrupalW
     drupal_static_reset('drupal_add_js');
   }
 }
+
+/**
+ * Functional test for initialization of the theme system in hook_init().
+ */
+class ThemeHookInitTestCase extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Theme initialization in hook_init()',
+      'description' => 'Tests that the theme system can be correctly initialized in hook_init().',
+      'group' => 'Theme',
+    );
+  }
+
+  function setUp() {
+    parent::setUp('theme_test');
+    variable_set('theme_default', 'garland');
+  }
+
+  /**
+   * Test that the theme system can generate output when called by hook_init().
+   */
+  function testThemeInitializationHookInit() {
+    $this->drupalGet('theme-test/hook-init');
+    $this->assertText('Themed output generated in hook_init()', t('Themed output generated in hook_init() correctly appears on the page.'));
+    $this->assertRaw('garland/style.css', t("The default theme's CSS appears on the page when the theme system is initialized in hook_init()."));
+  }
+}
Index: modules/simpletest/tests/theme_test.info
===================================================================
RCS file: modules/simpletest/tests/theme_test.info
diff -N modules/simpletest/tests/theme_test.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/simpletest/tests/theme_test.info	2 Nov 2009 06:05:01 -0000
@@ -0,0 +1,8 @@
+; $Id$
+name = Theme test
+description = Support module for testing the theme system.
+package = Testing
+version = VERSION
+core = 7.x
+files[] = theme_test.module
+hidden = TRUE
Index: modules/simpletest/tests/theme_test.module
===================================================================
RCS file: modules/simpletest/tests/theme_test.module
diff -N modules/simpletest/tests/theme_test.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/simpletest/tests/theme_test.module	2 Nov 2009 06:05:01 -0000
@@ -0,0 +1,36 @@
+<?php
+// $Id$
+
+/**
+ * Implement hook_menu().
+ */
+function theme_test_menu() {
+  $items['theme-test/hook-init'] = array(
+    'page callback' => 'theme_test_hook_init_page_callback',
+    'access callback' => TRUE,
+    'type' => MENU_CALLBACK,
+  );
+  return $items;
+}
+
+/**
+ * Implement hook_init().
+ */
+function theme_test_init() {
+  // First, flush all caches to ensure that the theme registry will be rebuilt
+  // on this page request. This allows us to test a full initialization of the
+  // theme system in the code below.
+  drupal_flush_all_caches();
+  // Next, initialize the theme system by storing themed text in a global
+  // variable. We will use this later in theme_test_hook_init_page_callback()
+  // to test that even when the theme system is initialized this early, it is
+  // still capable of returning output and theming the page as a whole.
+  $GLOBALS['theme_test_output'] = theme('placeholder', array('text' => 'Themed output generated in hook_init()'));
+}
+
+/**
+ * Menu callback for testing themed output generated in hook_init().
+ */
+function theme_test_hook_init_page_callback() {
+  return $GLOBALS['theme_test_output'];
+}
