public function ContentAccessTest::testQueryAccessWithNodeGrants in Search API 8
Tests building the query when content is accessible based on node grants.
File
- tests/
src/ Kernel/ Processor/ ContentAccessTest.php, line 212
Class
- ContentAccessTest
- Tests the "Content access" processor.
Namespace
Drupal\Tests\search_api\Kernel\ProcessorCode
public function testQueryAccessWithNodeGrants() {
// Create the user that will be passed into the query.
$permissions = [
'access content',
];
$authenticated_user = $this
->createUser($permissions);
Database::getConnection()
->insert('node_access')
->fields([
'nid' => $this->nodes[0]
->id(),
'langcode' => $this->nodes[0]
->language()
->getId(),
'gid' => $authenticated_user
->id(),
'realm' => 'search_api_test',
'grant_view' => 1,
])
->execute();
$this->index
->reindex();
$this
->indexItems();
$query = \Drupal::getContainer()
->get('search_api.query_helper')
->createQuery($this->index);
$query
->setOption('search_api_access_account', $authenticated_user);
$result = $query
->execute();
$expected = [
'user' => [
0,
$authenticated_user
->id(),
],
'node' => [
0,
],
];
$this
->assertResults($result, $expected);
}