You are here

public function ContentAccessTest::testContentAccessWithNodeGrants in Search API 8

Tests comment indexing when hook_node_grants() takes effect.

File

tests/src/Kernel/Processor/ContentAccessTest.php, line 290

Class

ContentAccessTest
Tests the "Content access" processor.

Namespace

Drupal\Tests\search_api\Kernel\Processor

Code

public function testContentAccessWithNodeGrants() {
  $items = [];
  foreach ($this->comments as $comment) {
    $items[] = [
      'datasource' => 'entity:comment',
      'item' => $comment
        ->getTypedData(),
      'item_id' => $comment
        ->id(),
      'field_text' => 'Text: &' . $comment
        ->id(),
    ];
  }
  $items = $this
    ->generateItems($items);

  // Add the processor's field values to the items.
  foreach ($items as $item) {
    $this->processor
      ->addFieldValues($item);
  }
  foreach ($items as $item) {
    $this
      ->assertEquals([
      'node_access_search_api_test:0',
    ], $item
      ->getField('node_grants')
      ->getValues());
  }
}