| 1 search.test | SearchCommentTestCase::testSearchResultsCommentAccess() | 
        
Verify access rules for comment indexing with different permissions.
File
- core/
modules/ search/ tests/ search.test, line 822  - Tests for search.module.
 
Class
- SearchCommentTestCase
 - Test integration searching comments.
 
Code
function testSearchResultsCommentAccess() {
  $comment_body = 'Test comment body';
  $this->comment_subject = 'Test comment subject';
  $roles = array_diff($this->admin_user->roles, array(BACKDROP_AUTHENTICATED_ROLE));
  $this->admin_role = reset($roles);
  // Create a node.
  $this->node = $this->backdropCreateNode(array('type' => 'post'));
  // Post a comment using 'Raw HTML' (full_html) text format.
  $edit_comment = array();
  $edit_comment['subject'] = $this->comment_subject;
  $edit_comment['comment_body[' . LANGUAGE_NONE . '][0][value]'] = '<h1>' . $comment_body . '</h1>';
  $this->backdropPost('comment/reply/' . $this->node->nid, $edit_comment, t('Save'));
  $this->backdropLogout();
  $this->setRolePermissions(BACKDROP_ANONYMOUS_ROLE);
  $this->assertCommentAccess('Anon user has search permission but no access comments permission, comments should not be indexed');
  $this->setRolePermissions(BACKDROP_ANONYMOUS_ROLE, TRUE);
  $this->assertCommentAccess('Anon user has search permission and access comments permission, comments should be indexed', TRUE);
  $this->backdropLogin($this->admin_user);
  $this->backdropGet('admin/config/people/permissions');
  // Disable search access for authenticated user to test admin user.
  $this->setRolePermissions(BACKDROP_AUTHENTICATED_ROLE, FALSE, FALSE);
  $this->setRolePermissions($this->admin_role);
  $this->assertCommentAccess('Admin user has search permission but no access comments permission, comments should not be indexed');
  $this->setRolePermissions($this->admin_role, TRUE);
  $this->assertCommentAccess('Admin user has search permission and access comments permission, comments should be indexed', TRUE);
  $this->setRolePermissions(BACKDROP_AUTHENTICATED_ROLE);
  $this->assertCommentAccess('Authenticated user has search permission but no access comments permission, comments should not be indexed');
  $this->setRolePermissions(BACKDROP_AUTHENTICATED_ROLE, TRUE);
  $this->assertCommentAccess('Authenticated user has search permission and access comments permission, comments should be indexed', TRUE);
  // Verify that access comments permission is inherited from the
  // authenticated role.
  $this->setRolePermissions(BACKDROP_AUTHENTICATED_ROLE, TRUE, FALSE);
  $this->setRolePermissions($this->admin_role);
  $this->assertCommentAccess('Admin user has search permission and no access comments permission, but comments should be indexed because admin user inherits authenticated user\'s permission to access comments', TRUE);
  // Verify that search content permission is inherited from the authenticated
  // role.
  $this->setRolePermissions(BACKDROP_AUTHENTICATED_ROLE, TRUE, TRUE);
  $this->setRolePermissions($this->admin_role, TRUE, FALSE);
  $this->assertCommentAccess('Admin user has access comments permission and no search permission, but comments should be indexed because admin user inherits authenticated user\'s permission to search', TRUE);
}