You are here

public function RangeSliderProcessorTest::testBuild in Facets 8

Tests the build method.

@covers ::build

File

modules/facets_range_widget/tests/src/Unit/Plugin/processor/RangeSliderProcessorTest.php, line 70

Class

RangeSliderProcessorTest
Unit test for processor.

Namespace

Drupal\Tests\facets_range_widget\Unit\Plugin\processor

Code

public function testBuild() {

  // Create the Url processor.
  $queryString = $this
    ->prophesize(QueryString::class);
  $queryString
    ->getFilterKey()
    ->willReturn('f');
  $queryString
    ->getSeparator()
    ->willReturn('::');
  $queryString
    ->getActiveFilters()
    ->willReturn([]);
  $urlHandler = $this
    ->prophesize(UrlProcessorHandler::class);
  $urlHandler
    ->getProcessor()
    ->willReturn($queryString
    ->reveal());
  $facet = $this
    ->prophesize(Facet::class);
  $facet
    ->getProcessors()
    ->willReturn([
    'url_processor_handler' => $urlHandler
      ->reveal(),
  ]);
  $facet
    ->getUrlAlias()
    ->willReturn('animals');
  $facet
    ->id()
    ->willReturn('animals');

  /** @var \Drupal\facets\Result\ResultInterface[] $results */
  $results = [
    new Result($facet
      ->reveal(), 1, 1, 1),
    new Result($facet
      ->reveal(), 5, 5, 5),
  ];
  $results[0]
    ->setUrl(new Url('test'));
  $results[1]
    ->setUrl(new Url('test'));
  $new_results = $this->processor
    ->build($facet
    ->reveal(), $results);
  $this
    ->assertCount(2, $new_results);
  $params = UrlHelper::buildQuery([
    'f' => [
      'animals::(min:__range_slider_min__,max:__range_slider_max__)',
    ],
  ]);
  $expected_route = 'route:test?' . $params;
  $this
    ->assertEquals($expected_route, $new_results[0]
    ->getUrl()
    ->toUriString());
  $this
    ->assertEquals($expected_route, $new_results[1]
    ->getUrl()
    ->toUriString());
}