| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: admin_menu.test,v 1.1.2.8 2010/07/28 02:09:12 sun Exp $ 3 4 /** 5 * @file 6 * Administration menu functionality tests. 7 * 8 * Note: When using $this->assertPattern(), be sure to use the 's' modifier for 9 * the PCRE pattern, since admin menu's output spans over multiple lines. 10 */ 11 12 13 /** 14 * Test menu links depending on user permissions. 15 */ 16 class AdminMenuPermissionsTestCase extends DrupalWebTestCase { 17 public static function getInfo() { 18 return array( 19 'name' => t('Menu link permissions'), 20 'description' => t('Verify that menu is displayed according to user permissions.'), 21 'group' => t('Administration menu'), 22 ); 23 } 24 25 function setUp() { 26 parent::setUp('admin_menu'); 27 } 28 29 /** 30 * Test that the links are added to the page (no JS testing). 31 */ 32 function testPermissions() { 33 // Anonymous users should not see the menu. 34 $this->assertNoRaw('<div id="admin-menu"', t('Admin menu not displayed to anonymous.')); 35 36 // Create a new user who can access administration menu, but without the 37 // permission 'display drupal links'. 38 $admin_user = $this->drupalCreateUser(array('administer site configuration', 'access administration pages', 'administer nodes', 'access administration menu')); 39 $this->drupalLogin($admin_user); 40 41 // Check that the user can see the admin links, but not the drupal links. 42 $this->assertRaw('<div id="admin-menu"', t('Administration menu is displayed.')); 43 $this->drupalGet('node'); 44 $this->assertPattern('@<div id="admin-menu".*admin/content/node@s', t('Administer content link found.')); 45 $this->assertNoPattern('@<div id="admin-menu".*http://drupal.org@s', t('Drupal links not found.')); 46 $this->assertNoPattern('@<div id="admin-menu".*admin/build/contact@s', t('Contact module link not found.')); 47 48 // Create a new user with the permission 'display drupal links'. 49 $admin_user2 = $this->drupalCreateUser(array('administer site configuration', 'access administration pages', 'administer nodes', 'access administration menu', 'display drupal links')); 50 $this->drupalLogin($admin_user2); 51 $this->drupalGet('node'); 52 $this->assertPattern('@<div id="admin-menu".*http://drupal.org@s', t('Drupal links found.')); 53 $this->assertNoPattern('@<div id="admin-menu".*admin/build/contact@s', t('Contact module link not found.')); 54 } 55 } 56 57 /** 58 * Test menu links depending on installed modules. 59 */ 60 class AdminMenuModulesTestCase extends DrupalWebTestCase { 61 public static function getInfo() { 62 return array( 63 'name' => t('Module menu links'), 64 'description' => t('Verify that menu contains links according to enabled modules.'), 65 'group' => t('Administration menu'), 66 ); 67 } 68 69 function setUp() { 70 parent::setUp('admin_menu', 'contact'); 71 } 72 73 /** 74 * Test that the links are added to the page (no JS testing). 75 */ 76 function testContactModuleLinks() { 77 // Create a new user without 'administer site-wide contact form' permission. 78 $admin_user = $this->drupalCreateUser(array('access administration pages', 'access administration menu')); 79 $this->drupalLogin($admin_user); 80 81 // Verify that proper links are displayed. 82 $this->assertRaw('<div id="admin-menu"', t('Administration menu is displayed.')); 83 $this->drupalGet('node'); 84 $this->assertNoPattern('@<div id="admin-menu".*admin/build/contact@s', t('Contact module link not found.')); 85 86 // Create a new user with 'administer site-wide contact form' permission. 87 $admin_user = $this->drupalCreateUser(array('access administration pages', 'access administration menu', 'administer site-wide contact form')); 88 $this->drupalLogin($admin_user); 89 90 // Verify that proper links are displayed. 91 $this->drupalGet('node'); 92 $this->assertPattern('@<div id="admin-menu".*admin/build/contact@s', t('Contact module link found.')); 93 } 94 } 95 96 /** 97 * Test contained links in administration menu. 98 */ 99 class AdminMenuLinksTestCase extends DrupalWebTestCase { 100 public static function getInfo() { 101 return array( 102 'name' => t('Menu links'), 103 'description' => t('Verify that menu contains proper links.'), 104 'group' => t('Administration menu'), 105 ); 106 } 107 108 function setUp() { 109 parent::setUp('admin_menu'); 110 111 // Create and log in a full-blown administrative user. 112 $permissions = module_invoke_all('perm'); 113 $admin_user = $this->drupalCreateUser($permissions); 114 $this->admin_user = $this->drupalLogin($admin_user); 115 } 116 117 /** 118 * Test link contents. 119 */ 120 function testLinkContents() { 121 // Create a content-type with special characters. 122 $info = array( 123 'type' => 'special', 124 'name' => 'Cool & Special', 125 'module' => 'node', 126 'description' => '', 127 ); 128 $info = (object)_node_type_set_defaults($info); 129 node_type_save($info); 130 drupal_flush_all_caches(); 131 132 // Fetch a page. 133 $this->drupalGet('node'); 134 $this->assertRaw('<div id="admin-menu"', t('Administration menu is displayed.')); 135 136 // Verify that proper links are displayed. 137 // We are explicitly NOT using t() here, since the purpose is to test our 138 // custom link titles and 't' option. 139 $links = array( 140 url('admin/content/node-type/page') => strtr('Edit !content-type', array('!content-type' => t('Page'))), 141 url('admin/content/node-type/special') => strtr('Edit !content-type', array('!content-type' => t('Cool & Special'))), 142 ); 143 foreach ($links as $url => $title) { 144 $this->assertFieldByXPath('//div[@id="admin-menu"]//a[@href="' . $url . '"]', $title, t('!link-title content-type link found.', array('!link-title' => $title))); 145 } 146 $links = array( 147 url('node/add/page') => t('Page'), 148 url('node/add/special') => t('Cool & Special'), 149 ); 150 foreach ($links as $url => $title) { 151 $this->assertFieldByXPath('//div[@id="admin-menu"]//a[@href="' . $url . '"]', $title, t('Create content » !link-title link found.', array('!link-title' => $title))); 152 } 153 } 154 } 155
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |