You are here

public function QueryStringTest::testSetMultipleActiveItems in Facets 8

Tests with multiple active items.

File

tests/src/Unit/Plugin/url_processor/QueryStringTest.php, line 128

Class

QueryStringTest
Unit test for processor.

Namespace

Drupal\Tests\facets\Unit\Plugin\url_processor

Code

public function testSetMultipleActiveItems() {
  $facet = new Facet([], 'facets_facet');
  $facet
    ->setResults($this->originalResults);
  $facet
    ->setUrlAlias('test');
  $facet
    ->setFieldIdentifier('test');
  $discovery_property = new \ReflectionProperty($facet, 'id');
  $discovery_property
    ->setAccessible(TRUE);
  $discovery_property
    ->setValue($facet, 'test');
  $storage = $this
    ->createMock(EntityStorageInterface::class);
  $storage
    ->expects($this
    ->atLeastOnce())
    ->method('loadByProperties')
    ->willReturnOnConsecutiveCalls([
    $facet,
  ], [
    $facet,
  ], []);
  $entityTypeManager = $this
    ->getMockBuilder(EntityTypeManagerInterface::class)
    ->disableOriginalConstructor()
    ->getMock();
  $entityTypeManager
    ->expects($this
    ->any())
    ->method('getStorage')
    ->willReturn($storage);
  $container = \Drupal::getContainer();
  $container
    ->set('entity_type.manager', $entityTypeManager);
  \Drupal::setContainer($container);
  $request = new Request();
  $request->query
    ->set('f', [
    'test:badger',
    'test:mushroom',
    'donkey:kong',
  ]);
  $this->processor = new QueryString([
    'facet' => $facet,
  ], 'query_string', [], $request, $entityTypeManager, $this->eventDispatcher);
  $this->processor
    ->setActiveItems($facet);
  $this
    ->assertEquals([
    'badger',
    'mushroom',
  ], $facet
    ->getActiveItems());
}