diff options
Diffstat (limited to 'modules/simpletest/tests')
-rw-r--r-- | modules/simpletest/tests/theme.test | 35 | ||||
-rw-r--r-- | modules/simpletest/tests/theme_test.module | 59 |
2 files changed, 85 insertions, 9 deletions
diff --git a/modules/simpletest/tests/theme.test b/modules/simpletest/tests/theme.test index d4dc89842..f6dea3309 100644 --- a/modules/simpletest/tests/theme.test +++ b/modules/simpletest/tests/theme.test @@ -66,6 +66,14 @@ class ThemeUnitTest extends DrupalWebTestCase { $_GET['q'] = $q; $this->assertTrue(in_array('page__front', $suggestions), t('Front page template was suggested.')); } + + /** + * Ensures theme hook_*_alter() implementations can run before anything is rendered. + */ + function testAlter() { + $this->drupalGet('theme-test/alter'); + $this->assertText('The altered data is test_theme_theme_test_alter_alter was invoked.', t('The theme was able to implement an alter hook during page building before anything was rendered.')); + } } /** @@ -181,3 +189,30 @@ class ThemeHookInitUnitTest extends DrupalWebTestCase { $this->assertRaw('bartik/css/style.css', t("The default theme's CSS appears on the page when the theme system is initialized in hook_init().")); } } + +/** + * Tests autocompletion not loading registry. + */ +class ThemeFastTestCase extends DrupalWebTestCase { + public static function getInfo() { + return array( + 'name' => 'Theme fast initialization', + 'description' => 'Test that autocompletion does not load the registry.', + 'group' => 'Theme' + ); + } + + function setUp() { + parent::setUp('theme_test'); + $this->account = $this->drupalCreateUser(array('access user profiles')); + } + + /** + * Tests access to user autocompletion and verify the correct results. + */ + function testUserAutocomplete() { + $this->drupalLogin($this->account); + $this->drupalGet('user/autocomplete/' . $this->account->name); + $this->assertText('registry not initialized', t('The registry was not initialized')); + } +} diff --git a/modules/simpletest/tests/theme_test.module b/modules/simpletest/tests/theme_test.module index ad22367b8..ff525ec34 100644 --- a/modules/simpletest/tests/theme_test.module +++ b/modules/simpletest/tests/theme_test.module @@ -12,6 +12,13 @@ function theme_test_menu() { 'theme callback' => '_theme_custom_theme', 'type' => MENU_CALLBACK, ); + $items['theme-test/alter'] = array( + 'title' => 'Suggestion', + 'page callback' => '_theme_test_alter', + 'access arguments' => array('access content'), + 'theme callback' => '_theme_custom_theme', + 'type' => MENU_CALLBACK, + ); $items['theme-test/hook-init'] = array( 'page callback' => 'theme_test_hook_init_page_callback', 'access callback' => TRUE, @@ -24,15 +31,36 @@ function theme_test_menu() { * Implements hook_init(). */ function theme_test_init() { - // First, force the theme registry to be rebuilt on this page request. This - // allows us to test a full initialization of the theme system in the code - // below. - drupal_theme_rebuild(); - // 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('more_link', array('url' => 'user', 'title' => 'Themed output generated in hook_init()')); + if (arg(0) == 'theme-test' && arg(1) == 'hook-init') { + // First, force the theme registry to be rebuilt on this page request. This + // allows us to test a full initialization of the theme system in the code + // below. + drupal_theme_rebuild(); + // 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('more_link', array('url' => 'user', 'title' => 'Themed output generated in hook_init()')); + } +} + +/** + * Implements hook_exit(). + */ +function theme_test_exit() { + if (arg(0) == 'user') { + // Register a fake registry loading callback. If it gets called by + // theme_get_registry(), the registry has not been initialized yet. + _theme_registry_callback('_theme_test_load_registry', array()); + print theme_get_registry() ? 'registry initialized' : 'registry not initialized'; + } +} + +/** + * Fake registry loading callback. + */ +function _theme_test_load_registry() { + return array(); } /** @@ -50,6 +78,19 @@ function _theme_custom_theme() { } /** + * Page callback, calls drupal_alter(). + * + * This is for testing that the theme can have hook_*_alter() implementations + * that run during page callback execution, even before theme() is called for + * the first time. + */ +function _theme_test_alter() { + $data = 'foo'; + drupal_alter('theme_test_alter', $data); + return "The altered data is $data."; +} + +/** * Page callback, calls a theme hook suggestion. */ function _theme_test_suggestion() { |