1 menu.test MenuRouterTestCase::testMenuCallbacks()

Tests title and theme callbacks in hook_menu().

File

core/modules/simpletest/tests/menu.test, line 139
Provides SimpleTests for menu.inc.

Class

MenuRouterTestCase

Code

function testMenuCallbacks() {
  // Test title callback set to FALSE.
  $this->backdropGet('node');
  $this->assertText('A title with @placeholder', 'Raw text found on the page');
  $this->assertNoText(t('A title with @placeholder', array('@placeholder' => 'some other text')), 'Text with placeholder substitutions not found.');

  // Test page title of MENU_CALLBACK items.
  // Verify that the menu router item title is not visible.
  $this->backdropGet('');
  $this->assertNoText(t('Menu Callback Title'));
  // Verify that the menu router item title is output as page title.
  $this->backdropGet('menu_callback_title');
  $this->assertText(t('Menu Callback Title'));

  // Test the theme callback when it is set to use an administrative theme.
  $this->backdropGet('menu-test/theme-callback/use-admin-theme');
  $this->assertText('Custom theme: seven. Actual theme: seven.', 'The administrative theme can be correctly set in a theme callback.');
  $this->assertRaw('seven/css/style.css', "The administrative theme's CSS appears on the page.");

  // Test that the theme callback is properly inherited.
  $this->backdropGet('menu-test/theme-callback/use-admin-theme/inheritance');
  $this->assertText('Custom theme: seven. Actual theme: seven. Theme callback inheritance is being tested.', 'Theme callback inheritance correctly uses the administrative theme.');
  $this->assertRaw('seven/css/style.css', "The administrative theme's CSS appears on the page.");

  // Test that 'page callback', 'file' and 'file path' keys are properly
  // inherited from parent menu paths.
  $this->backdropGet('admin/config/development/file-inheritance');
  $this->assertText('File inheritance test description', 'File inheritance works.');

  // Test path containing "exotic" characters.
  $path = "menu-test/ -._~!$'\"()*@[]?&+%#,;=:" . // "Special" ASCII characters.
    "%23%25%26%2B%2F%3F" . // Characters that look like a percent-escaped string.
    "éøïвβ中國書۞"; // Characters from various non-ASCII alphabets.
  $this->backdropGet($path);
  $this->assertRaw('This is menu_test_callback().');

  // Test the theme callback when the site is in maintenance mode.
  state_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->backdropGet('menu-test/theme-callback/use-admin-theme');
  $this->assertRaw('bartik/css/style.css', "The maintenance theme's CSS appears on the page.");

  // An administrator, however, should continue to see the requested theme.
  $admin_user = $this->backdropCreateUser(array('access site in maintenance mode'));
  $this->backdropLogin($admin_user);
  $this->backdropGet('menu-test/theme-callback/use-admin-theme');
  $this->assertText('Custom theme: seven. Actual theme: seven.', 'The theme callback system is correctly triggered for an administrator when the site is in maintenance mode.');
  $this->assertRaw('seven/css/style.css', "The administrative theme's CSS appears on the page.");
  $this->backdropLogout();

  // Make sure the maintenance mode can be bypassed using hook_menu_site_status_alter().
  $offline_message = t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => config_get_translated('system.core', 'site_name')));
  $this->backdropGet('node');
  $this->assertText($offline_message);
  $this->backdropGet('menu_login_callback');
  $this->assertText('This is menu_login_callback().', 'Maintenance mode can be bypassed through hook_login_paths().');
  state_set('maintenance_mode', FALSE);

  // Test the theme callback when it is set to use an optional theme.
  // Request a theme that is not enabled.
  $this->backdropGet('menu-test/theme-callback/use-stark-theme');
  $this->assertText('Custom theme: NONE. Actual theme: bartik.', 'The theme callback system falls back on the default theme when a theme that is not enabled is requested.');
  $this->assertRaw('bartik/css/style.css', "The default theme's CSS appears on the page.");

  // Now enable the theme and request it again.
  theme_enable(array('stark'));
  $this->backdropGet('menu-test/theme-callback/use-stark-theme');
  $this->assertText('Custom theme: stark. Actual theme: stark.', 'The theme callback system uses an optional theme once it has been enabled.');
  $this->assertRaw('stark/layout.css', "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.
  $this->backdropGet('menu-test/theme-callback/use-fake-theme');
  $this->assertText('Custom theme: NONE. Actual theme: bartik.', 'The theme callback system falls back on the default theme when a theme that does not exist is requested.');
  $this->assertRaw('bartik/css/style.css', "The default theme's CSS appears on the page.");

  // Test the theme callback when no theme is requested.
  $this->backdropGet('menu-test/theme-callback/no-theme-requested');
  $this->assertText('Custom theme: NONE. Actual theme: bartik.', 'The theme callback system falls back on the default theme when no theme is requested.');
  $this->assertRaw('bartik/css/style.css', "The default theme's CSS appears on the page.");
}