You are here

public function QueryStringTest::testFacetSourceFilterKeyOverride in Facets 8

Tests that the facet source configuration filter key override works.

File

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

Class

QueryStringTest
Unit test for processor.

Namespace

Drupal\Tests\facets\Unit\Plugin\url_processor

Code

public function testFacetSourceFilterKeyOverride() {
  $facet_source = new FacetSource([
    'filter_key' => 'ab',
  ], 'facets_facet_source');

  // Override the container with the new facet source.
  $storage = $this
    ->createMock(EntityStorageInterface::class);
  $storage
    ->expects($this
    ->once())
    ->method('load')
    ->willReturn($facet_source);
  $em = $this
    ->getMockBuilder(EntityTypeManagerInterface::class)
    ->disableOriginalConstructor()
    ->getMock();
  $em
    ->expects($this
    ->any())
    ->method('getStorage')
    ->willReturn($storage);
  $container = \Drupal::getContainer();
  $container
    ->set('entity_type.manager', $em);
  \Drupal::setContainer($container);
  $facet = new Facet([], 'facets_facet');
  $facet
    ->setFieldIdentifier('test');
  $facet
    ->setFacetSourceId('facet_source__dummy');
  $facet
    ->setUrlAlias('test');
  $request = new Request();
  $request->query
    ->set('ab', []);
  $this->processor = new QueryString([
    'facet' => $facet,
  ], 'query_string', [], $request, $this->entityManager, $this->eventDispatcher);
  $results = $this->processor
    ->buildUrls($facet, $this->originalResults);

  /** @var \Drupal\facets\Result\ResultInterface $r */
  foreach ($results as $r) {
    $this
      ->assertInstanceOf(ResultInterface::class, $r);
    $this
      ->assertEquals('route:test?ab%5B0%5D=test%3A' . $r
      ->getRawValue(), $r
      ->getUrl()
      ->toUriString());
  }
}