function AdminMenuPermissionsTest::testPermissions in Administration menu 8.3
Test that the links are added to the page (no JS testing).
File
- lib/
Drupal/ admin_menu/ Tests/ AdminMenuPermissionsTest.php, line 23
Class
- AdminMenuPermissionsTest
- Tests menu links depending on user permissions.
Namespace
Drupal\admin_menu\TestsCode
function testPermissions() {
module_enable([
'contact',
]);
$this
->resetAll();
// Anonymous users should not see the menu.
$this
->drupalGet('');
$this
->assertNoElementByXPath('//div[@id="admin-menu"]', [], 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 + [
'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"]', [], 'Administration menu found.');
$this
->assertElementByXPath('//div[@id="admin-menu"]//a[contains(@href, :path)]', [
':path' => 'admin/content',
], 'Content link found.');
$this
->assertNoElementByXPath('//div[@id="admin-menu"]//a[@href=:path]', [
':path' => 'http://drupal.org',
], 'Icon » Drupal.org link not found.');
$this
->assertNoElementByXPath('//div[@id="admin-menu"]//a[contains(@href, :path)]', [
':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 + [
'display drupal links',
'administer contact forms',
];
$admin_user2 = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($admin_user2);
$this
->assertElementByXPath('//div[@id="admin-menu"]', [], 'Administration menu found.');
$this
->assertNoElementByXPath('//div[@id="admin-menu"]//a[contains(@href, :path)]', [
':path' => 'admin/content',
], 'Content link not found.');
$this
->assertElementByXPath('//div[@id="admin-menu"]//a[@href=:path]', [
':path' => 'http://drupal.org',
], 'Icon » Drupal.org link found.');
$this
->assertElementByXPath('//div[@id="admin-menu"]//a[contains(@href, :path)]', [
':path' => 'admin/structure/contact',
], 'Structure » Contact link found.');
}