function ContentAccessModuleTestCase::testViewAccess in Content Access 6
Same name and namespace in other branches
- 5 tests/content_access.test \ContentAccessModuleTestCase::testViewAccess()
- 7 tests/content_access.test \ContentAccessModuleTestCase::testViewAccess()
Test for viewing nodes
File
- tests/
content_access.test, line 34
Class
Code
function testViewAccess() {
// Restrict access to the content type (access is only allowed for the author)
$access_permissions = array(
'view[1]' => FALSE,
'view[2]' => FALSE,
);
$this
->changeAccessContentType($access_permissions);
// Logout admin and try to access the node anonymously
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1->nid);
$this
->assertText(t('Access denied'), 'node is not viewable');
// Login test user, view node, access must be denied
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node1->nid);
$this
->assertText(t('Access denied'), 'node is not viewable');
// Login admin and grant access for viewing to the test user
$this
->drupalLogin($this->admin_user);
$this
->changeAccessContentTypeKeyword('view');
// Logout admin and try to access the node anonymously
// access must be denied again
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1->nid);
$this
->assertText(t('Access denied'), 'node is not viewable');
// Login test user, view node, access must be granted
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node1->nid);
$this
->assertNoText(t('Access denied'), 'node is viewable');
// Login admin and enable per node access
$this
->drupalLogin($this->admin_user);
$this
->changeAccessPerNode();
// Restrict access on node2 for the test user role
$this
->changeAccessNodeKeyword($this->node2, 'view', FALSE);
// Logout admin and try to access both nodes anonymously
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1->nid);
$this
->assertText(t('Access denied'), 'node1 is not viewable');
$this
->drupalGet('node/' . $this->node2->nid);
$this
->assertText(t('Access denied'), 'node2 is not viewable');
// Login test user, view node1, access must be granted
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node1->nid);
$this
->assertNoText(t('Access denied'), 'node1 is viewable');
// View node2, access must be denied
$this
->drupalGet('node/' . $this->node2->nid);
$this
->assertText(t('Access denied'), 'node2 is not viewable');
// Login admin, swap permissions between content type and node2
$this
->drupalLogin($this->admin_user);
// Restrict access to content type
$this
->changeAccessContentTypeKeyword('view', FALSE);
// Grant access to node2
$this
->changeAccessNodeKeyword($this->node2, 'view');
// Logout admin and try to access both nodes anonymously
$this
->drupalLogout();
$this
->drupalGet('node/' . $this->node1->nid);
$this
->assertText(t('Access denied'), 'node1 is not viewable');
$this
->drupalGet('node/' . $this->node2->nid);
$this
->assertText(t('Access denied'), 'node2 is not viewable');
// Login test user, view node1, access must be denied
$this
->drupalLogin($this->test_user);
$this
->drupalGet('node/' . $this->node1->nid);
$this
->assertText(t('Access denied'), 'node1 is not viewable');
// View node2, access must be granted
$this
->drupalGet('node/' . $this->node2->nid);
$this
->assertNoText(t('Access denied'), 'node2 is viewable');
}