public function ContentAccessAclTest::testDeleteAccess in Content Access 8
Test Deleting accessibility with permissions for single users.
File
- tests/
src/ Functional/ ContentAccessAclTest.php, line 202
Class
- ContentAccessAclTest
- Automated BrowserTest Case for using content access module with acl module.
Namespace
Drupal\Tests\content_access\FunctionalCode
public function testDeleteAccess() {
// Exit test if ACL module could not be enabled.
if (!\Drupal::moduleHandler()
->moduleExists('acl')) {
$this
->pass('No ACL module present, skipping test');
return;
}
// Enable per node access control.
$this
->changeAccessPerNode();
// Allow delete access for test user.
$edit = [
'acl[delete][add]' => $this->testUser
->getAccountName(),
];
$this
->drupalPostForm('node/' . $this->node1
->id() . '/access', $edit, $this
->t('edit-acl-delete-add-button'));
$this
->drupalPostForm(NULL, [], $this
->t('Submit'));
// Logout admin, try to delete the node anonymously.
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1
->id() . '/delete');
$this
->assertSession()
->pageTextContains($this
->t('Access denied'));
// Login test user, delete access should be allowed now.
$this
->drupalLogin($this->testUser);
$this
->drupalGet('node/' . $this->node1
->id() . '/delete');
$this
->assertSession()
->pageTextNotContains($this
->t('Access denied'));
// Login admin and disable per node access.
$this
->drupalLogin($this->adminUser);
$this
->changeAccessPerNode(FALSE);
// Logout admin, try to delete the node anonymously.
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1
->id() . '/delete');
$this
->assertSession()
->pageTextContains($this
->t('Access denied'));
// Login test user, delete access should be denied now.
$this
->drupalLogin($this->testUser);
$this
->drupalGet('node/' . $this->node1
->id() . '/delete');
$this
->assertSession()
->pageTextContains($this
->t('Access denied'));
}