public function ContentAccessTinyTest::testViewAccess in Content Access 8
Test Viewing accessibility with permissions for single users.
File
- tests/
src/ Functional/ ContentAccessTinyTest.php, line 106
Class
- ContentAccessTinyTest
- Automated BrowserTest Case for having a tiny test to run fast.
Namespace
Drupal\Tests\content_access\FunctionalCode
public function testViewAccess() {
// Exit test if ACL module could not be enabled.
if (!\Drupal::moduleHandler()
->moduleExists('acl')) {
$this
->pass('No ACL module present, skipping test');
return;
}
// Restrict access to this content type.
// Enable per node access control.
$accessPermissions = [
'view[anonymous]' => FALSE,
'view[authenticated]' => FALSE,
'per_node' => TRUE,
];
$this
->changeAccessContentType($accessPermissions);
// Allow access for test user.
$edit = [
'acl[view][add]' => $this->testUser
->getAccountName(),
];
$this
->drupalPostForm('node/' . $this->node1
->id() . '/access', $edit, $this
->t('Add User'));
$this
->drupalPostForm(NULL, [], $this
->t('Submit'));
// Logout admin, try to access the node anonymously.
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1
->id());
$this
->assertSession()
->pageTextContains($this
->t('Access denied'));
// Login test user, view access should be allowed now.
$this
->drupalLogin($this->testUser);
$this
->drupalGet('node/' . $this->node1
->id());
$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 access the node anonymously.
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1
->id());
$this
->assertSession()
->pageTextContains($this
->t('Access denied'));
// Login test user, view access should be denied now.
$this
->drupalLogin($this->testUser);
$this
->drupalGet('node/' . $this->node1
->id());
$this
->assertSession()
->pageTextContains($this
->t('Access denied'));
}