1 admin_bar.test AdminBarPermissionsTestCase::testPermissions()

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


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


Tests menu links depending on user permissions.


function testPermissions() {

  // Anonymous users should not see the menu.
  $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);

  // 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->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.');