summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-10-15 04:46:59 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-10-15 04:46:59 +0000
commitaa301ada485cc9e99f73fb81635909bdb3c1c3e8 (patch)
tree59c4a1803b23cfabfd097e7e2cc1fbd6a75946aa
parent063fe4821daef625278d12d323631c6014714a85 (diff)
downloadbrdo-aa301ada485cc9e99f73fb81635909bdb3c1c3e8.tar.gz
brdo-aa301ada485cc9e99f73fb81635909bdb3c1c3e8.tar.bz2
#296115 by naxoc, dereine: Tests for menu router item titles.
-rw-r--r--modules/simpletest/tests/menu.test33
-rw-r--r--modules/simpletest/tests/menu_test.module40
2 files changed, 73 insertions, 0 deletions
diff --git a/modules/simpletest/tests/menu.test b/modules/simpletest/tests/menu.test
index e615f4b8d..087293670 100644
--- a/modules/simpletest/tests/menu.test
+++ b/modules/simpletest/tests/menu.test
@@ -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');
+ }
}
/**
diff --git a/modules/simpletest/tests/menu_test.module b/modules/simpletest/tests/menu_test.module
index 344bdb027..d420f06c0 100644
--- a/modules/simpletest/tests/menu_test.module
+++ b/modules/simpletest/tests/menu_test.module
@@ -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;
+}