You are here

function AdminMenuPermissionsTestCase::testPermissions in Administration menu 6.3

Same name and namespace in other branches
  1. 6 tests/admin_menu.test \AdminMenuPermissionsTestCase::testPermissions()
  2. 7.3 tests/admin_menu.test \AdminMenuPermissionsTestCase::testPermissions()

Test that the links are added to the page (no JS testing).

File

tests/admin_menu.test, line 130
Tests for the Administration menu module.

Class

AdminMenuPermissionsTestCase
Tests menu links depending on user permissions.

Code

function testPermissions() {

  // Anonymous users should not see the menu.
  $this
    ->drupalGet('');
  $this
    ->assertNoElementByXPath('//div[@id="admin-menu"]', array(), t('Administration menu not found.'));

  // Create a user who
  // - can access content overview
  // - cannot access drupal.org links
  // - cannot administer Contact module
  $permissions = $this->basePermissions + array(
    'administer nodes',
  );
  $admin_user = $this
    ->drupalCreateUser($permissions);
  $this
    ->drupalLogin($admin_user);

  // Check that the user can see the admin links, but not the drupal links.
  $this
    ->assertElementByXPath('//div[@id="admin-menu"]', array(), 'Administration menu found.');
  $this
    ->assertElementByXPath('//div[@id="admin-menu"]//a[contains(@href, :path)]', array(
    ':path' => 'admin/content',
  ), 'Content link found.');
  $this
    ->assertNoElementByXPath('//div[@id="admin-menu"]//a[@href=:path]', array(
    ':path' => 'http://drupal.org',
  ), 'Icon » Drupal.org link not found.');
  $this
    ->assertNoElementByXPath('//div[@id="admin-menu"]//a[contains(@href, :path)]', array(
    ':path' => 'admin/build/contact',
  ), 'Structure » Contact link not found.');

  // Create a user "reversed" to the above; i.e., who
  // - cannot access content overview
  // - can access drupal.org links
  // - can administer Contact module
  $permissions = $this->basePermissions + array(
    'display drupal links',
    'administer site-wide contact form',
  );
  $admin_user2 = $this
    ->drupalCreateUser($permissions);
  $this
    ->drupalLogin($admin_user2);
  $this
    ->assertElementByXPath('//div[@id="admin-menu"]', array(), 'Administration menu found.');

  // @todo Top-level category links are based on access administration pages
  //   permission only.

  //$this->assertNoElementByXPath('//div[@id="admin-menu"]//a[contains(@href, :path)]', array(':path' => 'admin/content'), 'Content link not found.');
  $this
    ->assertElementByXPath('//div[@id="admin-menu"]//a[@href=:path]', array(
    ':path' => 'http://drupal.org',
  ), 'Icon » Drupal.org link found.');
  $this
    ->assertElementByXPath('//div[@id="admin-menu"]//a[contains(@href, :path)]', array(
    ':path' => 'admin/build/contact',
  ), 'Structure » Contact link found.');
}