public function PremiumContentTest::testQueryAccessOwn in Node Option Premium 8
Tests searching for own premium content.
File
- tests/
src/ Kernel/ Plugin/ search_api/ processor/ PremiumContentTest.php, line 148
Class
- PremiumContentTest
- Tests the "Premium content" processor.
Namespace
Drupal\Tests\nopremium\Kernel\Plugin\search_api\processorCode
public function testQueryAccessOwn() {
// Create the user that will be passed into the query.
$permissions = [
'access content',
];
$authenticated_user = $this
->createUser($permissions);
$uid = $authenticated_user
->id();
// Create a premium node owned by the created user.
$values = [
'status' => NodeInterface::PUBLISHED,
'type' => 'article',
'title' => 'foo',
'uid' => $uid,
'premium' => TRUE,
];
$this->nodes[2] = Node::create($values);
$this->nodes[2]
->save();
$this
->indexItems();
$this
->assertEquals(3, $this->index
->getTrackerInstance()
->getIndexedItemsCount(), '3 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 = [
'node' => [
1,
2,
],
];
$this
->assertResults($result, $expected);
}