function SearchByPageNodesTest::testSearchAccess in Search by Page 8
Tests that access permissions are obeyed.
File
- tests/
src/ Functional/ search_by_page.test, line 241 - Tests for the Search by Page module. By Jennifer Hodgdon of Poplar ProductivityWare, www.poplarware.com
Class
- SearchByPageNodesTest
- Functionality tests for Search by Page Nodes.
Namespace
Drupal\Tests\search_by_page\FunctionalCode
function testSearchAccess() {
// Log in as a non-priv user
$this
->drupalLogin($this->noprivuser);
// Some node access tests...
// Note: The following access tests are low-level, but they were failing at
// one time, until I rebuilt node access permissions in startup. So, leave
// them here -- at the least they are useful for debugging if other tests
// start failing later!
$node = \Drupal\node\Entity\Node::load($this->privnodeid, NULL, TRUE);
$this
->assertTrue($node->test_private, "Node is marked private");
$this
->assertTrue($node->status, "Node is published");
$grants = node_access_grants('view', $this->noprivuser);
$this
->assertFalse(isset($grants['search_by_page_test']), "Non-priv user does not have sbp test grant");
$grants = node_access_grants('view', $this->privuser);
$this
->assertTrue($grants['search_by_page_test'], "Priv user does have sbp test grant");
$this
->assertFalse(user_access('administer nodes', $this->noprivuser), "Non priv user does not have administer nodes permission");
$this
->assertTrue(user_access('access content', $this->noprivuser), "Non priv user does have access content permission");
$this
->assertFalse(node_access("view", $node, $this->noprivuser), "Node access is restricted for non-priv user");
$this
->assertTrue(node_access("view", $node, $this->privuser), "Node access is not restricted for priv user");
// Verify we cannot see the private page
$this
->drupalGet('node/' . $this->privnodeid);
$this
->assertNoText('walk', "Cannot see private page");
// Run a search for "walk"
$search_path = $this->envinfo1['page_path'];
$this
->drupalPostForm($search_path, array(
'keys' => 'walk',
), t('Search pages'));
// Should be able to see the public page, but not the private page.
$this
->assertText('walk', "Walk appears in search results");
$this
->assertText('streets', "Streets appears in search results");
$this
->assertNoText('north', "North does not appear in search results for nonpriv user");
}