public function ListItemProcessorTest::testBuildBaseField in Facets 8
Tests facet build with base props.
File
- tests/
src/ Unit/ Plugin/ processor/ ListItemProcessorTest.php, line 190
Class
- ListItemProcessorTest
- Unit test for processor.
Namespace
Drupal\Tests\facets\Unit\Plugin\processorCode
public function testBuildBaseField() {
$config_manager = $this
->getMockBuilder(ConfigManager::class)
->disableOriginalConstructor()
->getMock();
$base_field = $this
->getMockBuilder(BaseFieldDefinition::class)
->disableOriginalConstructor()
->getMock();
$entity_field_manager = $this
->getMockBuilder(EntityFieldManager::class)
->disableOriginalConstructor()
->getMock();
$entity_field_manager
->expects($this
->any())
->method('getFieldDefinitions')
->with('node', '')
->willReturn([
'test_facet_baseprop' => $base_field,
]);
$entity_type_bundle_info = $this
->getMockBuilder(EntityTypeBundleInfo::class)
->disableOriginalConstructor()
->getMock();
$processor = new ListItemProcessor([], 'list_item', [], $config_manager, $entity_field_manager, $entity_type_bundle_info);
// Base prop facet.
$base_prop_facet = new Facet([], 'facets_facet');
$base_prop_facet
->setFieldIdentifier('test_facet_baseprop');
$base_prop_facet
->setFacetSourceId('llama_source');
$base_prop_facet
->setResults($this->results);
$base_prop_facet
->addProcessor([
'processor_id' => 'list_item',
'weights' => [],
'settings' => [],
]);
/** @var \Drupal\facets\Result\Result[] $base_prop_results */
$base_prop_results = $processor
->build($base_prop_facet, $this->results);
$this
->assertCount(3, $base_prop_results);
$this
->assertEquals('llama', $base_prop_results[0]
->getDisplayValue());
$this
->assertEquals('badger', $base_prop_results[1]
->getDisplayValue());
$this
->assertEquals('kitten', $base_prop_results[2]
->getDisplayValue());
}