You are here

public function TranslateEntityProcessorTest::testNodeResultsChanged in Facets 8

Tests that node results were correctly changed.

@dataProvider facetDataProvider

Parameters

\Drupal\facets\FacetInterface $facet: A facet mock.

array $results: The facet original results mock.

File

tests/src/Unit/Plugin/processor/TranslateEntityProcessorTest.php, line 135

Class

TranslateEntityProcessorTest
Unit test for processor.

Namespace

Drupal\Tests\facets\Unit\Plugin\processor

Code

public function testNodeResultsChanged(FacetInterface $facet, array $results) {

  // Mock a node and add the label to it.
  $node = $this
    ->getMockBuilder(Node::class)
    ->disableOriginalConstructor()
    ->getMock();
  $node
    ->expects($this
    ->any())
    ->method('label')
    ->willReturn('shaken not stirred');
  $nodes = [
    2 => $node,
  ];
  $node_storage = $this
    ->createMock(EntityStorageInterface::class);
  $node_storage
    ->expects($this
    ->any())
    ->method('loadMultiple')
    ->willReturn($nodes);
  $this->entityTypeManager
    ->expects($this
    ->exactly(1))
    ->method('getStorage')
    ->willReturn($node_storage);

  // Set expected results.
  $expected_results = [
    [
      'nid' => 2,
      'title' => 'shaken not stirred',
    ],
  ];

  // Without the processor we expect the id to display.
  foreach ($expected_results as $key => $expected) {
    $this
      ->assertEquals($expected['nid'], $results[$key]
      ->getRawValue());
    $this
      ->assertEquals($expected['nid'], $results[$key]
      ->getDisplayValue());
  }

  // With the processor we expect the title to display.

  /** @var \Drupal\facets\Result\ResultInterface[] $filtered_results */
  $processor = new TranslateEntityProcessor([], 'translate_entity', [], $this->languageManager, $this->entityTypeManager);
  $filtered_results = $processor
    ->build($facet, $results);
  foreach ($expected_results as $key => $expected) {
    $this
      ->assertEquals($expected['nid'], $filtered_results[$key]
      ->getRawValue());
    $this
      ->assertEquals($expected['title'], $filtered_results[$key]
      ->getDisplayValue());
  }
}