Commit aa301ada authored by webchick's avatar webchick

#296115 by naxoc, dereine: Tests for menu router item titles.

parent 063fe482
......@@ -431,6 +431,39 @@ class MenuRouterTestCase extends DrupalWebTestCase {
$this->assertRaw('title="Test title attribute"', t('Title attribute of a menu link renders.'));
$this->assertRaw('testparam=testvalue', t('Query parameter added to menu link.'));
}
/**
* Tests the possible ways to set the title for menu items.
* Also tests that menu item titles work with string overrides.
*/
function testMenuItemTitlesCases() {
// Build array with string overrides.
$test_data = array(
1 => array('Example title - Case 1' => 'Alternative example title - Case 1'),
2 => array('Example @sub1 - Case @op2' => 'Alternative example @sub1 - Case @op2'),
3 => array('Example title' => 'Alternative example title'),
4 => array('Example title' => 'Alternative example title'),
);
foreach ($test_data as $case_no => $override) {
$this->menuItemTitlesCasesHelper($case_no);
variable_set('locale_custom_strings_en', array('' => $override));
$this->menuItemTitlesCasesHelper($case_no, TRUE);
variable_set('locale_custom_strings_en', array());
}
}
/**
* Get a url and assert the title given a case number. If override is true,
* the title is asserted to begin with "Alternative".
*/
private function menuItemTitlesCasesHelper($case_no, $override = FALSE) {
$this->drupalGet('menu-title-test/case' . $case_no);
$this->assertResponse(200);
$asserted_title = $override ? 'Alternative example title - Case ' . $case_no : 'Example title - Case ' . $case_no;
$this->assertTitle($asserted_title . ' | Drupal', t('Menu title is') . ': ' . $asserted_title, 'Menu');
}
}
/**
......
......@@ -227,6 +227,34 @@ function menu_test_menu() {
'access callback' => TRUE,
);
$items['menu-title-test/case1'] = array(
'title' => 'Example title - Case 1',
'access callback' => TRUE,
'page callback' => 'menu_test_callback',
);
$items['menu-title-test/case2'] = array(
'title' => 'Example @sub1 - Case @op2',
// If '2' is not in quotes, the argument becomes arg(2).
'title arguments' => array('@sub1' => 'title', '@op2' => '2'),
'access callback' => TRUE,
'page callback' => 'menu_test_callback',
);
$items['menu-title-test/case3'] = array(
'title' => 'Example title',
'title callback' => 'menu_test_title_callback',
'access callback' => TRUE,
'page callback' => 'menu_test_callback',
);
$items['menu-title-test/case4'] = array(
// Title gets completely ignored. Good thing, too.
'title' => 'Bike sheds full of blue smurfs',
'title callback' => 'menu_test_title_callback',
// If '4' is not in quotes, the argument becomes arg(4).
'title arguments' => array('Example title', '4'),
'access callback' => TRUE,
'page callback' => 'menu_test_callback',
);
return $items;
}
......@@ -384,3 +412,15 @@ function menu_test_menu_site_status_alter(&$menu_site_status, $path) {
function menu_login_callback() {
return 'This is menu_login_callback().';
}
/**
* Concatenates a string, by using the t() function and a case number.
*
* @param $title
* Title string.
* @param $case_number
* The current case number which is tests (defaults to 3).
*/
function menu_test_title_callback($title, $case_no = 3) {
return t($title) . ' - Case ' . $case_no;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment