function SearchByPageNodesTest::testSearchAccess in Search by Page 6
Same name and namespace in other branches
- 7 tests/search_by_page.test \SearchByPageNodesTest::testSearchAccess()
Tests that access permissions are obeyed.
File
- tests/
search_by_page.test, line 550 - 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.
Code
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 = 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
->assertTrue(!isset($grants['sbp_test']) || !$grants['sbp_test'], "Non-priv user does not have sbp test grant");
$grants = node_access_grants('view', $this->privuser);
$this
->assertTrue($grants['sbp_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
->drupalPost($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");
}