public function ContentAccessAclTest::testEditAccess in Content Access 8
Test Editing accessibility with permissions for single users.
File
- tests/
src/ Functional/ ContentAccessAclTest.php, line 157
Class
- ContentAccessAclTest
- Automated BrowserTest Case for using content access module with acl module.
Namespace
Drupal\Tests\content_access\FunctionalCode
public function testEditAccess() {
// 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 edit access for test user.
$edit = [
'acl[update][add]' => $this->testUser
->getAccountName(),
];
$this
->drupalPostForm('node/' . $this->node1
->id() . '/access', $edit, $this
->t('edit-acl-update-add-button'));
$this
->drupalPostForm(NULL, [], $this
->t('Submit'));
// Logout admin, try to edit the node anonymously.
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1
->id() . '/edit');
$this
->assertSession()
->pageTextContains($this
->t('Access denied'));
// Login test user, edit access should be allowed now.
$this
->drupalLogin($this->testUser);
$this
->drupalGet('node/' . $this->node1
->id() . '/edit');
$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 edit the node anonymously.
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1
->id() . '/edit');
$this
->assertSession()
->pageTextContains($this
->t('Access denied'));
// Login test user, edit access should be denied now.
$this
->drupalLogin($this->testUser);
$this
->drupalGet('node/' . $this->node1
->id() . '/edit');
$this
->assertSession()
->pageTextContains($this
->t('Access denied'));
}