diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-09-30 13:09:30 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-09-30 13:09:30 +0000 |
commit | a8f8a26f6d77f6aca8821e28e66ea253687d7d59 (patch) | |
tree | d0f2b694e18a3ccc343d379b3742791becb57b39 /modules/simpletest | |
parent | 15343a993ce45ec6626c79406aaa85c2631d023e (diff) | |
download | brdo-a8f8a26f6d77f6aca8821e28e66ea253687d7d59.tar.gz brdo-a8f8a26f6d77f6aca8821e28e66ea253687d7d59.tar.bz2 |
- Patch #553944 by David_Rothstein, ksenzee | JacobSingh, sun, jhodgdon, pwolanin: allow modules to specify per-page custom themes in hook_menu().
Diffstat (limited to 'modules/simpletest')
-rw-r--r-- | modules/simpletest/tests/menu.test | 78 | ||||
-rw-r--r-- | modules/simpletest/tests/menu_test.module | 64 |
2 files changed, 142 insertions, 0 deletions
diff --git a/modules/simpletest/tests/menu.test b/modules/simpletest/tests/menu.test index 26443f74e..d8ac5a882 100644 --- a/modules/simpletest/tests/menu.test +++ b/modules/simpletest/tests/menu.test @@ -18,6 +18,10 @@ class MenuIncTestCase extends DrupalWebTestCase { function setUp() { // Enable dummy module that implements hook_menu. parent::setUp('menu_test'); + // Make the tests below more robust by explicitly setting the default theme + // and administrative theme that they expect. + variable_set('theme_default', 'garland'); + variable_set('admin_theme', 'seven'); } /** @@ -30,6 +34,80 @@ class MenuIncTestCase extends DrupalWebTestCase { } /** + * Test the theme callback when it is set to use an administrative theme. + */ + 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->assertRaw('seven/style.css', t("The administrative theme's CSS appears on the page.")); + } + + /** + * Test that the theme callback is properly inherited. + */ + 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->assertRaw('seven/style.css', t("The administrative theme's CSS appears on the page.")); + } + + /** + * Test the theme callback when the site is in maintenance mode. + */ + function testThemeCallbackMaintenanceMode() { + variable_set('maintenance_mode', TRUE); + + // For a regular user, the fact that the site is in maintenance mode means + // we expect the theme callback system to be bypassed entirely. + $this->drupalGet('menu-test/theme-callback/use-admin-theme'); + $this->assertRaw('minnelli/minnelli.css', t("The maintenance theme's CSS appears on the page.")); + + // An administrator, however, should continue to see the requested theme. + $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->assertRaw('seven/style.css', t("The administrative theme's CSS appears on the page.")); + } + + /** + * Test the theme callback when it is set to use an optional theme. + */ + 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->assertRaw('garland/style.css', t("The default theme's CSS appears on the page.")); + + // Now enable the theme and request it again. + $admin_user = $this->drupalCreateUser(array('administer site configuration')); + $this->drupalLogin($admin_user); + $this->drupalPost('admin/appearance', array('status[stark]' => 1), t('Save configuration')); + $this->drupalLogout(); + $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->assertRaw('stark/layout.css', t("The optional theme's CSS appears on the page.")); + } + + /** + * Test the theme callback when it is set to use a theme that does not exist. + */ + 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->assertRaw('garland/style.css', t("The default theme's CSS appears on the page.")); + } + + /** + * Test the theme callback when no theme is requested. + */ + 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->assertRaw('garland/style.css', t("The default theme's CSS appears on the page.")); + } + + /** * Tests for menu_link_maintain(). */ function testMenuLinkMaintain() { diff --git a/modules/simpletest/tests/menu_test.module b/modules/simpletest/tests/menu_test.module index 15ecea71a..ae8235a9f 100644 --- a/modules/simpletest/tests/menu_test.module +++ b/modules/simpletest/tests/menu_test.module @@ -44,6 +44,20 @@ function menu_test_menu() { 'title' => 'Unattached subchild router', 'page callback' => 'node_page_default', ); + // Theme callback tests. + $items['menu-test/theme-callback/%'] = array( + 'title' => 'Page that displays different themes', + 'page callback' => 'menu_test_theme_page_callback', + 'access arguments' => array('access content'), + 'theme callback' => 'menu_test_theme_callback', + 'theme arguments' => array(2), + ); + $items['menu-test/theme-callback/%/inheritance'] = array( + 'title' => 'Page that tests theme callback inheritance.', + 'page callback' => 'menu_test_theme_page_callback', + 'page arguments' => array(TRUE), + 'access arguments' => array('access content'), + ); return $items; } @@ -58,6 +72,56 @@ function menu_test_callback() { } /** + * Page callback to use when testing the theme callback functionality. + * + * @param $inherited + * An optional boolean to set to TRUE when the requested page is intended to + * inherit the theme of its parent. + * @return + * A string describing the requested custom theme and actual theme being used + * for the current page request. + */ +function menu_test_theme_page_callback($inherited = FALSE) { + global $theme_key; + // Initialize the theme system so that $theme_key will be populated. + drupal_theme_initialize(); + // 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."; + if ($inherited) { + $output .= ' Theme callback inheritance is being tested.'; + } + return $output; +} + +/** + * Theme callback to use when testing the theme callback functionality. + * + * @param $argument + * The argument passed in from the URL. + * @return + * The name of the custom theme to request for the current page. + */ +function menu_test_theme_callback($argument) { + // Test using the variable administrative theme. + if ($argument == 'use-admin-theme') { + return variable_get('admin_theme'); + } + // Test using a theme that exists, but may or may not be enabled. + elseif ($argument == 'use-stark-theme') { + return 'stark'; + } + // Test using a theme that does not exist. + elseif ($argument == 'use-fake-theme') { + return 'fake_theme'; + } + // For any other value of the URL argument, do not return anything. This + // allows us to test that returning nothing from a theme callback function + // causes the page to correctly fall back on using the main site theme. +} + +/** * Helper function for the testMenuName() test. Used to change the menu_name * parameter of a menu. * |