You are here

public function AdminMenuPermissionsTestCase::testPermissions in Administration menu 7.3

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

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

File

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

Class

AdminMenuPermissionsTestCase
Tests menu links depending on user permissions.

Code

public function testPermissions() {
  module_enable(array(
    'contact',
  ));
  $this
    ->resetAll();

  // 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(
    'access content overview',
  );
  $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/structure/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 contact forms',
  );
  $admin_user2 = $this
    ->drupalCreateUser($permissions);
  $this
    ->drupalLogin($admin_user2);
  $this
    ->assertElementByXPath('//div[@id="admin-menu"]', array(), 'Administration menu found.');
  $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/structure/contact',
  ), 'Structure » Contact link found.');
}