Verify access rules for comment indexing with different permissions.
function testSearchResultsCommentAccess() {
$comment_body = 'Test comment body';
$this->comment_subject = 'Test comment subject';
$this->admin_role = $this->admin_user->roles[0];
// Create a node.
variable_set('comment_preview_article', DRUPAL_OPTIONAL);
$this->node = $this
->drupalCreateNode(array(
'type' => 'article',
));
// Post a comment using 'Full HTML' text format.
$edit_comment = array();
$edit_comment['subject'] = $this->comment_subject;
$edit_comment['comment_body[' . Language::LANGCODE_NOT_SPECIFIED . '][0][value]'] = '<h1>' . $comment_body . '</h1>';
$this
->drupalPost('comment/reply/' . $this->node->nid, $edit_comment, t('Save'));
$this
->drupalLogout();
$this
->setRolePermissions(DRUPAL_ANONYMOUS_RID);
$this
->assertCommentAccess(FALSE, 'Anon user has search permission but no access comments permission, comments should not be indexed');
$this
->setRolePermissions(DRUPAL_ANONYMOUS_RID, TRUE);
$this
->assertCommentAccess(TRUE, 'Anon user has search permission and access comments permission, comments should be indexed');
$this
->drupalLogin($this->admin_user);
$this
->drupalGet('admin/people/permissions');
// Disable search access for authenticated user to test admin user.
$this
->setRolePermissions(DRUPAL_AUTHENTICATED_RID, FALSE, FALSE);
$this
->setRolePermissions($this->admin_role);
$this
->assertCommentAccess(FALSE, 'Admin user has search permission but no access comments permission, comments should not be indexed');
$this
->setRolePermissions($this->admin_role, TRUE);
$this
->assertCommentAccess(TRUE, 'Admin user has search permission and access comments permission, comments should be indexed');
$this
->setRolePermissions(DRUPAL_AUTHENTICATED_RID);
$this
->assertCommentAccess(FALSE, 'Authenticated user has search permission but no access comments permission, comments should not be indexed');
$this
->setRolePermissions(DRUPAL_AUTHENTICATED_RID, TRUE);
$this
->assertCommentAccess(TRUE, 'Authenticated user has search permission and access comments permission, comments should be indexed');
// Verify that access comments permission is inherited from the
// authenticated role.
$this
->setRolePermissions(DRUPAL_AUTHENTICATED_RID, TRUE, FALSE);
$this
->setRolePermissions($this->admin_role);
$this
->assertCommentAccess(TRUE, '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');
// Verify that search content permission is inherited from the authenticated
// role.
$this
->setRolePermissions(DRUPAL_AUTHENTICATED_RID, TRUE, TRUE);
$this
->setRolePermissions($this->admin_role, TRUE, FALSE);
$this
->assertCommentAccess(TRUE, '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');
}