public function ContentAccessTest::testQueryAccessOwn in Search API 8
Tests searching for own unpublished content.
File
- tests/
src/ Kernel/ Processor/ ContentAccessTest.php, line 178
Class
- ContentAccessTest
- Tests the "Content access" processor.
Namespace
Drupal\Tests\search_api\Kernel\ProcessorCode
public function testQueryAccessOwn() {
// Create the user that will be passed into the query.
$permissions = [
'access content',
'access comments',
'view own unpublished content',
];
$authenticated_user = $this
->createUser($permissions);
$uid = $authenticated_user
->id();
$values = [
'status' => NodeInterface::NOT_PUBLISHED,
'type' => 'page',
'title' => 'foo',
'uid' => $uid,
];
$this->nodes[3] = Node::create($values);
$this->nodes[3]
->save();
$this
->indexItems();
$this
->assertEquals(7, $this->index
->getTrackerInstance()
->getIndexedItemsCount(), '7 items indexed, as expected.');
$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,
$uid,
],
'node' => [
3,
],
];
$this
->assertResults($result, $expected);
}