menu_token.test 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * @file
  4. * Menu Token tests.
  5. */
  6. class MenuTokenTestCase extends DrupalWebTestCase {
  7. public $admin_user;
  8. public static function getInfo() {
  9. return array(
  10. 'name' => 'Menu Token test',
  11. 'description' => 'Create tokenized menu item.',
  12. 'group' => 'Menu Token',
  13. );
  14. }
  15. /**
  16. * Enable modules and create users with specific permissions.
  17. */
  18. function setUp() {
  19. parent::setUp('token', 'menu_token');
  20. // Create user and login.
  21. $this->admin_user = $this->drupalCreateUser(array('administer menu'));
  22. $this->drupalLogin($this->admin_user);
  23. }
  24. /**
  25. * Create menu item and check it works properly.
  26. */
  27. function testCreateMenuItem() {
  28. // Add new menu item.
  29. $edit = array(
  30. 'link_title' => '[current-user:name]',
  31. 'link_path' => 'user/[current-user:uid]',
  32. 'menu_token_enabled' => TRUE,
  33. );
  34. $this->drupalPost('admin/structure/menu/manage/user-menu/add', $edit, t('Save'));
  35. // Go to front page and assert menu item exists.
  36. $this->drupalGet('');
  37. $admin_user = $this->admin_user;
  38. $this->assertLink($admin_user->name, 0, t('Tokenized menu item found by title.'), 'Menu token');
  39. $this->assertLinkByHref('user/' . $admin_user->uid, 0, t('Tokenized menu item found by href.'), 'Menu token');
  40. // Logout and assert that our menu item is not shown to anonymous user.
  41. $this->drupalLogout();
  42. $this->drupalGet('');
  43. $this->assertNoLinkByHref('user/0', t('Tokenized link user/[uid] not shown to anonymous user.'), 'Menu token');
  44. }
  45. }