public function NodeExcludeTest::testAlterItems in Search API exclude 8
Tests if nodes, which are configured to be excluded, are removed.
File
- tests/src/ Unit/ Plugin/ Processor/ NodeExcludeTest.php, line 111 
Class
- NodeExcludeTest
- Tests the "Node exclude" processor.
Namespace
Drupal\Tests\search_api_exclude\Unit\Plugin\ProcessorCode
public function testAlterItems() {
  $datasource_id = 'entity:node';
  /** @var \Drupal\search_api\Utility\FieldsHelper $fields_helper */
  $fields_helper = \Drupal::service('search_api.fields_helper');
  $items = [];
  foreach ([
    1 => '1',
    2 => '0',
    3 => NULL,
  ] as $i => $exclude) {
    $item_id = Utility::createCombinedId($datasource_id, sprintf('%d:en', $i));
    $item = $fields_helper
      ->createItem($this->index, $item_id, $this->datasources[$datasource_id]);
    /** @var \Drupal\Core\Entity\ContentEntityInterface $node */
    $item
      ->setOriginalObject(EntityAdapter::createFromEntity($this
      ->createNode($exclude)));
    $items[$item_id] = $item;
  }
  $this->processor
    ->alterIndexedItems($items);
  $expected = [
    Utility::createCombinedId($datasource_id, '2:en'),
    Utility::createCombinedId($datasource_id, '3:en'),
  ];
  $this
    ->assertEquals($expected, array_keys($items));
}