function AdminMenuPermissionsTest::testPermissionChanges in Administration menu 8.3
Tests that user role and permission changes are properly taken up.
File
- lib/
Drupal/ admin_menu/ Tests/ AdminMenuPermissionsTest.php, line 95
Class
- AdminMenuPermissionsTest
- Tests menu links depending on user permissions.
Namespace
Drupal\admin_menu\TestsCode
function testPermissionChanges() {
// Create a user who is able to change permissions.
$permissions = $this->basePermissions + [
'administer permissions',
];
$admin_user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($admin_user);
// Extract the user role ID that was created for above permissions.
$rid = key(array_diff_key($admin_user->roles, [
DRUPAL_AUTHENTICATED_RID => 0,
]));
// Verify that Configuration does not appear.
$this
->assertNoLinkTrailByTitle([
t('Configuration'),
]);
// Grant the 'administer site configuration' permission to ourselves.
$edit = [
$rid . '[administer site configuration]' => TRUE,
];
$this
->drupalPost('admin/people/permissions', $edit, t('Save permissions'));
// Verify that Configuration appears.
$this
->assertLinkTrailByTitle([
t('Configuration'),
]);
// Verify that Structure » Content types does not appear.
$this
->assertNoLinkTrailByTitle([
t('Structure'),
t('Content types'),
]);
// Create a new role.
$test_rid = drupal_strtolower($this
->randomName(8));
$edit = [
'role[label]' => 'test',
'role[id]' => $test_rid,
];
$this
->drupalPost('admin/people/roles', $edit, t('Add role'));
// Grant the 'administer content types' permission for the role.
$edit = [
$test_rid . '[administer content types]' => TRUE,
];
$this
->drupalPost('admin/people/permissions/' . $test_rid, $edit, t('Save permissions'));
// Verify that Structure » Content types does not appear.
$this
->assertNoLinkTrailByTitle([
t('Structure'),
t('Content types'),
]);
// Assign the role to ourselves.
$edit = [
'roles[' . $test_rid . ']' => TRUE,
];
$this
->drupalPost('user/' . $admin_user->uid . '/edit', $edit, t('Save'));
// Verify that Structure » Content types appears.
$this
->assertLinkTrailByTitle([
t('Structure'),
t('Content types'),
]);
// Delete the role.
$this
->drupalPost('admin/people/roles/edit/' . $test_rid, [], t('Delete role'));
$this
->drupalPost(NULL, [], t('Delete'));
// Verify that Structure » Content types does not appear.
$this
->assertNoLinkTrailByTitle([
t('Structure'),
t('Content types'),
]);
}