You are here

protected function ListItemProcessorTest::setUp in Facets 8

Creates a new processor object for use in the tests.

Overrides UnitTestCase::setUp

File

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

Class

ListItemProcessorTest
Unit test for processor.

Namespace

Drupal\Tests\facets\Unit\Plugin\processor

Code

protected function setUp() {
  parent::setUp();
  $facet = new Facet([], 'facets_facet');
  $this->results = [
    new Result($facet, 1, 1, 10),
    new Result($facet, 2, 2, 5),
    new Result($facet, 3, 3, 15),
  ];
  $config_manager = $this
    ->getMockBuilder(ConfigManager::class)
    ->disableOriginalConstructor()
    ->getMock();
  $entity_field_manager = $this
    ->getMockBuilder(EntityFieldManager::class)
    ->disableOriginalConstructor()
    ->getMock();
  $entity_type_bundle_info = $this
    ->getMockBuilder(EntityTypeBundleInfo::class)
    ->disableOriginalConstructor()
    ->getMock();

  // Create a search api based facet source and make the property definition
  // return null.
  $data_definition = $this
    ->createMock(ComplexDataDefinitionInterface::class);
  $data_definition
    ->expects($this
    ->any())
    ->method('getPropertyDefinition')
    ->willReturn(NULL);
  $facet_source = $this
    ->getMockBuilder(FacetSourcePluginInterface::class)
    ->disableOriginalConstructor()
    ->getMock();
  $facet_source
    ->expects($this
    ->any())
    ->method('getDataDefinition')
    ->willReturn($data_definition);

  // Add the plugin manager.
  $pluginManager = $this
    ->getMockBuilder(FacetSourcePluginManager::class)
    ->disableOriginalConstructor()
    ->getMock();
  $pluginManager
    ->expects($this
    ->any())
    ->method('hasDefinition')
    ->willReturn(TRUE);
  $pluginManager
    ->expects($this
    ->any())
    ->method('createInstance')
    ->willReturn($facet_source);
  $this->processor = new ListItemProcessor([], 'list_item', [], $config_manager, $entity_field_manager, $entity_type_bundle_info);
  $container = new ContainerBuilder();
  $container
    ->set('plugin.manager.facets.facet_source', $pluginManager);
  \Drupal::setContainer($container);
}