You are here

public function ListItemProcessorTest::testBuildBundle in Facets 8

Tests facet build with field.module field.

File

tests/src/Unit/Plugin/processor/ListItemProcessorTest.php, line 146

Class

ListItemProcessorTest
Unit test for processor.

Namespace

Drupal\Tests\facets\Unit\Plugin\processor

Code

public function testBuildBundle() {
  $module_field = $this
    ->getMockBuilder(FieldStorageConfig::class)
    ->disableOriginalConstructor()
    ->getMock();
  $config_manager = $this
    ->getMockBuilder(ConfigManager::class)
    ->disableOriginalConstructor()
    ->getMock();
  $config_manager
    ->expects($this
    ->exactly(2))
    ->method('loadConfigEntityByName')
    ->willReturn($module_field);
  $entity_field_manager = $this
    ->getMockBuilder(EntityFieldManager::class)
    ->disableOriginalConstructor()
    ->getMock();
  $entity_type_bundle_info = $this
    ->getMockBuilder(EntityTypeBundleInfo::class)
    ->disableOriginalConstructor()
    ->getMock();
  $processor = new ListItemProcessor([], 'list_item', [], $config_manager, $entity_field_manager, $entity_type_bundle_info);

  // Config entity field facet.
  $module_field_facet = new Facet([], 'facets_facet');
  $module_field_facet
    ->setFieldIdentifier('test_facet');
  $module_field_facet
    ->setFacetSourceId('llama_source');
  $module_field_facet
    ->setResults($this->results);
  $module_field_facet
    ->addProcessor([
    'processor_id' => 'list_item',
    'weights' => [],
    'settings' => [],
  ]);

  /* @var \Drupal\facets\Result\Result[] $module_field_facet- */
  $module_field_results = $processor
    ->build($module_field_facet, $this->results);
  $this
    ->assertCount(3, $module_field_results);
  $this
    ->assertEquals('llama', $module_field_results[0]
    ->getDisplayValue());
  $this
    ->assertEquals('badger', $module_field_results[1]
    ->getDisplayValue());
  $this
    ->assertEquals('kitten', $module_field_results[2]
    ->getDisplayValue());
}