1 admin_bar.test AdminBarPermissionsTestCase::testPermissions()

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

File

core/modules/admin_bar/tests/admin_bar.test, line 132
Tests for the Administration bar module.

Class

AdminBarPermissionsTestCase
Tests menu links depending on user permissions.

Code

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

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

  // Create a user who
  // - can access content overview
  // - cannot administer Contact module
  $permissions = $this->basePermissions + array(
    'access content overview',
  );
  $admin_user = $this->backdropCreateUser($permissions);
  $this->backdropLogin($admin_user);

  // Check that the user can see the admin links, but not the Backdrop links.
  $this->assertElementByXPath('//div[@id="admin-bar"]', array(), 'Administration bar found.');
  $this->assertElementByXPath('//div[@id="admin-bar"]//a[contains(@href, :path)]', array(':path' => 'admin/content'), 'Content link found.');
  $this->assertNoElementByXPath('//div[@id="admin-bar"]//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 administer Contact module
  $permissions = $this->basePermissions + array(
    'administer contact forms',
  );
  $admin_user2 = $this->backdropCreateUser($permissions);
  $this->backdropLogin($admin_user2);
  $this->assertElementByXPath('//div[@id="admin-bar"]', array(), 'Administration bar found.');
  $this->assertNoElementByXPath('//div[@id="admin-bar"]//a[contains(@href, :path)]', array(':path' => 'admin/content'), 'Content link not found.');
  $this->assertElementByXPath('//div[@id="admin-bar"]//a[contains(@href, :path)]', array(':path' => 'admin/structure/contact'), 'Structure » Contact link found.');
}