From 196aaa7d51b5ea9ac6422b93937b9070d5832272 Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Sat, 30 Jan 2010 03:38:22 +0000 Subject: #553944 follow-up by David_Rothstein: Allow modules to override per-page custom themes. --- modules/simpletest/tests/menu.test | 37 +++++++++++++++++++++++++------ modules/simpletest/tests/menu_test.module | 17 +++++++++++++- 2 files changed, 46 insertions(+), 8 deletions(-) (limited to 'modules/simpletest/tests') diff --git a/modules/simpletest/tests/menu.test b/modules/simpletest/tests/menu.test index c98014b06..d9563a86a 100644 --- a/modules/simpletest/tests/menu.test +++ b/modules/simpletest/tests/menu.test @@ -38,7 +38,7 @@ class MenuRouterTestCase extends DrupalWebTestCase { */ function testThemeCallbackAdministrative() { $this->drupalGet('menu-test/theme-callback/use-admin-theme'); - $this->assertText('Requested theme: seven. Actual theme: seven.', t('The administrative theme can be correctly set in a theme callback.')); + $this->assertText('Custom theme: seven. Actual theme: seven.', t('The administrative theme can be correctly set in a theme callback.')); $this->assertRaw('seven/style.css', t("The administrative theme's CSS appears on the page.")); } @@ -47,7 +47,7 @@ class MenuRouterTestCase extends DrupalWebTestCase { */ function testThemeCallbackInheritance() { $this->drupalGet('menu-test/theme-callback/use-admin-theme/inheritance'); - $this->assertText('Requested theme: seven. Actual theme: seven. Theme callback inheritance is being tested.', t('Theme callback inheritance correctly uses the administrative theme.')); + $this->assertText('Custom theme: seven. Actual theme: seven. Theme callback inheritance is being tested.', t('Theme callback inheritance correctly uses the administrative theme.')); $this->assertRaw('seven/style.css', t("The administrative theme's CSS appears on the page.")); } @@ -77,7 +77,7 @@ class MenuRouterTestCase extends DrupalWebTestCase { $admin_user = $this->drupalCreateUser(array('access site in maintenance mode')); $this->drupalLogin($admin_user); $this->drupalGet('menu-test/theme-callback/use-admin-theme'); - $this->assertText('Requested theme: seven. Actual theme: seven.', t('The theme callback system is correctly triggered for an administrator when the site is in maintenance mode.')); + $this->assertText('Custom theme: seven. Actual theme: seven.', t('The theme callback system is correctly triggered for an administrator when the site is in maintenance mode.')); $this->assertRaw('seven/style.css', t("The administrative theme's CSS appears on the page.")); } @@ -87,13 +87,13 @@ class MenuRouterTestCase extends DrupalWebTestCase { function testThemeCallbackOptionalTheme() { // Request a theme that is not enabled. $this->drupalGet('menu-test/theme-callback/use-stark-theme'); - $this->assertText('Requested theme: stark. Actual theme: garland.', t('The theme callback system falls back on the default theme when a theme that is not enabled is requested.')); + $this->assertText('Custom theme: NONE. Actual theme: garland.', t('The theme callback system falls back on the default theme when a theme that is not enabled is requested.')); $this->assertRaw('garland/style.css', t("The default theme's CSS appears on the page.")); // Now enable the theme and request it again. theme_enable(array('stark')); $this->drupalGet('menu-test/theme-callback/use-stark-theme'); - $this->assertText('Requested theme: stark. Actual theme: stark.', t('The theme callback system uses an optional theme once it has been enabled.')); + $this->assertText('Custom theme: stark. Actual theme: stark.', t('The theme callback system uses an optional theme once it has been enabled.')); $this->assertRaw('stark/layout.css', t("The optional theme's CSS appears on the page.")); } @@ -102,7 +102,7 @@ class MenuRouterTestCase extends DrupalWebTestCase { */ function testThemeCallbackFakeTheme() { $this->drupalGet('menu-test/theme-callback/use-fake-theme'); - $this->assertText('Requested theme: fake_theme. Actual theme: garland.', t('The theme callback system falls back on the default theme when a theme that does not exist is requested.')); + $this->assertText('Custom theme: NONE. Actual theme: garland.', t('The theme callback system falls back on the default theme when a theme that does not exist is requested.')); $this->assertRaw('garland/style.css', t("The default theme's CSS appears on the page.")); } @@ -111,10 +111,33 @@ class MenuRouterTestCase extends DrupalWebTestCase { */ function testThemeCallbackNoThemeRequested() { $this->drupalGet('menu-test/theme-callback/no-theme-requested'); - $this->assertText('Requested theme: NONE. Actual theme: garland.', t('The theme callback system falls back on the default theme when no theme is requested.')); + $this->assertText('Custom theme: NONE. Actual theme: garland.', t('The theme callback system falls back on the default theme when no theme is requested.')); $this->assertRaw('garland/style.css', t("The default theme's CSS appears on the page.")); } + /** + * Test that the result of hook_custom_theme() overrides the theme callback. + */ + function testHookCustomTheme() { + // Trigger hook_custom_theme() to dynamically request the Stark theme for + // the requested page. + variable_set('menu_test_hook_custom_theme_name', 'stark'); + + // Request a page whose theme callback returns the Seven theme. Since Stark + // is not a currently enabled theme, our above request should be ignored, + // and Seven should still be used. + $this->drupalGet('menu-test/theme-callback/use-admin-theme'); + $this->assertText('Custom theme: seven. Actual theme: seven.', t('The result of hook_custom_theme() does not override a theme callback when it returns a theme that is not enabled.')); + $this->assertRaw('seven/style.css', t("The Seven theme's CSS appears on the page.")); + + // Now enable the Stark theme and request the same page as above. This + // time, we expect hook_custom_theme() to prevail. + theme_enable(array('stark')); + $this->drupalGet('menu-test/theme-callback/use-admin-theme'); + $this->assertText('Custom theme: stark. Actual theme: stark.', t('The result of hook_custom_theme() overrides what was set in a theme callback.')); + $this->assertRaw('stark/layout.css', t("The Stark theme's CSS appears on the page.")); + } + /** * Tests for menu_link_maintain(). */ diff --git a/modules/simpletest/tests/menu_test.module b/modules/simpletest/tests/menu_test.module index 194fe8006..1e436ee59 100644 --- a/modules/simpletest/tests/menu_test.module +++ b/modules/simpletest/tests/menu_test.module @@ -203,7 +203,7 @@ function menu_test_theme_page_callback($inherited = FALSE) { // Now check both the requested custom theme and the actual theme being used. $custom_theme = menu_get_custom_theme(); $requested_theme = empty($custom_theme) ? 'NONE' : $custom_theme; - $output = "Requested theme: $requested_theme. Actual theme: $theme_key."; + $output = "Custom theme: $requested_theme. Actual theme: $theme_key."; if ($inherited) { $output .= ' Theme callback inheritance is being tested.'; } @@ -236,6 +236,21 @@ function menu_test_theme_callback($argument) { // causes the page to correctly fall back on using the main site theme. } +/** + * Implement hook_custom_theme(). + * + * @return + * The name of the custom theme to use for the current page. + */ +function menu_test_custom_theme() { + // If an appropriate variable has been set in the database, request the theme + // that is stored there. Otherwise, do not attempt to dynamically set the + // theme. + if ($theme = variable_get('menu_test_hook_custom_theme_name', FALSE)) { + return $theme; + } +} + /** * Helper function for the testMenuName() test. Used to change the menu_name * parameter of a menu. -- cgit v1.2.3