public function TranslateEntityProcessorTest::testTermResultsChanged in Facets 8
Tests that term 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 185
Class
- TranslateEntityProcessorTest
- Unit test for processor.
Namespace
Drupal\Tests\facets\Unit\Plugin\processorCode
public function testTermResultsChanged(FacetInterface $facet, array $results) {
// Mock term.
$term = $this
->getMockBuilder(Term::class)
->disableOriginalConstructor()
->getMock();
$term
->expects($this
->once())
->method('label')
->willReturn('Burrowing owl');
$terms = [
2 => $term,
];
$term_storage = $this
->createMock(EntityStorageInterface::class);
$term_storage
->expects($this
->any())
->method('loadMultiple')
->willReturn($terms);
$this->entityTypeManager
->expects($this
->exactly(1))
->method('getStorage')
->willReturn($term_storage);
// Set expected results.
$expected_results = [
[
'tid' => 2,
'name' => 'Burrowing owl',
],
];
// Without the processor we expect the id to display.
foreach ($expected_results as $key => $expected) {
$this
->assertEquals($expected['tid'], $results[$key]
->getRawValue());
$this
->assertEquals($expected['tid'], $results[$key]
->getDisplayValue());
}
/** @var \Drupal\facets\Result\ResultInterface[] $filtered_results */
$processor = new TranslateEntityProcessor([], 'translate_entity', [], $this->languageManager, $this->entityTypeManager);
$filtered_results = $processor
->build($facet, $results);
// With the processor we expect the title to display.
foreach ($expected_results as $key => $expected) {
$this
->assertEquals($expected['tid'], $filtered_results[$key]
->getRawValue());
$this
->assertEquals($expected['name'], $filtered_results[$key]
->getDisplayValue());
}
}