menu_example.test 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * @file
  4. * Tests for menu example module.
  5. */
  6. /**
  7. * Functional tests for the Menu Example module.
  8. *
  9. * @ingroup menu_example
  10. */
  11. class MenuExampleTestCase extends DrupalWebTestCase {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public static function getInfo() {
  16. return array(
  17. 'name' => 'Menu example functionality',
  18. 'description' => 'Checks behavior of Menu Example.',
  19. 'group' => 'Examples',
  20. );
  21. }
  22. /**
  23. * Enable modules and create user with specific permissions.
  24. */
  25. public function setUp() {
  26. parent::setUp('menu_example');
  27. }
  28. /**
  29. * Test the various menus.
  30. */
  31. public function testMenuExample() {
  32. $this->drupalGet('');
  33. $this->assertText(t('Menu Example: Menu in alternate menu'));
  34. $this->clickLink(t('Menu Example'));
  35. $this->assertText(t('This is the base page of the Menu Example'));
  36. $this->drupalGet('examples/menu_example_alternate_menu');
  37. $this->assertResponse(200);
  38. $this->clickLink(t('Custom Access Example'));
  39. $this->assertText(t('Custom Access Example'));
  40. $this->clickLink(t('examples/menu_example/custom_access/page'));
  41. $this->assertResponse(403);
  42. $this->drupalGet('examples/menu_example/permissioned');
  43. $this->assertText(t('Permissioned Example'));
  44. $this->clickLink('examples/menu_example/permissioned/controlled');
  45. $this->assertResponse(403);
  46. $this->drupalGet('examples/menu_example');
  47. $this->clickLink(t('MENU_CALLBACK example'));
  48. $this->drupalGet('examples/menu_example/path_only/callback');
  49. $this->assertText(t('The menu entry for this page is of type MENU_CALLBACK'));
  50. $this->clickLink(t('Tabs'));
  51. $this->assertText(t('This is the "tabs" menu entry'));
  52. $this->drupalGet('examples/menu_example/tabs/second');
  53. $this->assertText(t('This is the tab "second" in the "basic tabs" example'));
  54. $this->clickLink(t('third'));
  55. $this->assertText(t('This is the tab "third" in the "basic tabs" example'));
  56. $this->clickLink(t('Extra Arguments'));
  57. $this->drupalGet('examples/menu_example/use_url_arguments/one/two');
  58. $this->assertText(t('Argument 1=one'));
  59. $this->clickLink(t('Placeholder Arguments'));
  60. $this->clickLink(t('examples/menu_example/placeholder_argument/3343/display'));
  61. $this->assertRaw('<div>3343</div>');
  62. $this->clickLink(t('Processed Placeholder Arguments'));
  63. $this->assertText(t('Loaded value was jackpot! default'));
  64. // Create a user with permissions to access protected menu entry.
  65. $web_user = $this->drupalCreateUser(array('access protected menu example'));
  66. // Use custom overridden drupalLogin function to verify the user is logged
  67. // in.
  68. $this->drupalLogin($web_user);
  69. // Check that our title callback changing /user dynamically is working.
  70. // Using &#039; because of the format_username function.
  71. $this->assertRaw(t("@name&#039;s account", array('@name' => format_username($web_user))), format_string('Title successfully changed to account name: %name.', array('%name' => $web_user->name)));
  72. // Now start testing other menu entries.
  73. $this->drupalGet('examples/menu_example');
  74. $this->clickLink(t('Custom Access Example'));
  75. $this->assertText(t('Custom Access Example'));
  76. $this->drupalGet('examples/menu_example/custom_access/page');
  77. $this->assertResponse(200);
  78. $this->drupalGet('examples/menu_example/permissioned');
  79. $this->assertText('Permissioned Example');
  80. $this->clickLink('examples/menu_example/permissioned/controlled');
  81. $this->assertText('This menu entry will not show');
  82. $this->drupalGet('examples/menu_example/menu_altered_path');
  83. $this->assertText('This menu item was created strictly to allow the hook_menu_alter()');
  84. }
  85. }