You are here

protected function SearchApiExcludeEntityProcessorTest::createMockItem in Search API Exclude Entity 8

Helper function for creating node based mock search index items.

Parameters

string $bundle: The bundle name of the mock node.

string $raw_id: The raw ID of the mock search index item.

\Drupal\Core\Field\FieldItemListInterface $field_value_1: (Optional) The value of the first exclude field of the mock node.

\Drupal\Core\Field\FieldItemListInterface $field_value_2: (Optional) The value of the second exclude field of the mock node.

Return value

\Drupal\search_api\Item\ItemInterface The mock search index item.

1 call to SearchApiExcludeEntityProcessorTest::createMockItem()
SearchApiExcludeEntityProcessorTest::testAlterIndexedItems in tests/src/Unit/Processor/SearchApiExcludeEntityProcessorTest.php
Tests altering the indexed items.

File

tests/src/Unit/Processor/SearchApiExcludeEntityProcessorTest.php, line 135

Class

SearchApiExcludeEntityProcessorTest
Tests the "Search API Exclude Entity" processor.

Namespace

Drupal\Tests\search_api_exclude_entity\Unit\Processor

Code

protected function createMockItem($bundle, $raw_id, FieldItemListInterface $field_value_1 = NULL, FieldItemListInterface $field_value_2 = NULL) {
  $node = $this
    ->createMock(NodeInterface::class);
  $node
    ->method('getEntityTypeId')
    ->willReturn('node');
  $node
    ->method('bundle')
    ->willReturn($bundle);
  $node
    ->method('get')
    ->will($this
    ->returnValueMap([
    [
      $this->fieldName1,
      $field_value_1,
    ],
    [
      $this->fieldName2,
      $field_value_2,
    ],
  ]));

  /** @var \Drupal\search_api\Item\ItemInterface $item */

  /** @var \Drupal\node\NodeInterface $node */
  $id = Utility::createCombinedId('entity:node', $raw_id);
  $item = $this->fieldsHelper
    ->createItem($this->index, $id);
  $item
    ->setOriginalObject(EntityAdapter::createFromEntity($node));
  return $item;
}