You are here

public function SliderWidgetTest::testBuild in Facets 8

Tests building of the widget.

1 call to SliderWidgetTest::testBuild()
RangeSliderWidgetTest::testBuild in modules/facets_range_widget/tests/src/Unit/Plugin/widget/RangeSliderWidgetTest.php
Tests building of the widget.
1 method overrides SliderWidgetTest::testBuild()
RangeSliderWidgetTest::testBuild in modules/facets_range_widget/tests/src/Unit/Plugin/widget/RangeSliderWidgetTest.php
Tests building of the widget.

File

modules/facets_range_widget/tests/src/Unit/Plugin/widget/SliderWidgetTest.php, line 67

Class

SliderWidgetTest
Unit test for widget.

Namespace

Drupal\Tests\facets_range_widget\Unit\Plugin\widget

Code

public function testBuild() {
  $widget = $this
    ->prophesize(SliderWidget::class);
  $widget
    ->getConfiguration()
    ->willReturn([
    'show_numbers' => FALSE,
  ]);
  $pluginManager = $this
    ->prophesize(WidgetPluginManager::class);
  $pluginManager
    ->createInstance('slider', [])
    ->willReturn($widget
    ->reveal());
  $url_generator = $this
    ->prophesize(UrlGeneratorInterface::class);
  $container = new ContainerBuilder();
  $container
    ->set('plugin.manager.facets.widget', $pluginManager
    ->reveal());
  $container
    ->set('url_generator', $url_generator
    ->reveal());
  \Drupal::setContainer($container);
  $facet = new Facet([
    'id' => 'barn_owl',
  ], 'facets_facet');
  $originalResults = [];
  foreach (range(3, 20000, 2) as $rv) {
    $res = new Result($facet, $rv, 'Value: ' . $rv, ceil($rv / 2));
    $res
      ->setUrl(new Url('test'));
    $originalResults[] = $res;
  }
  $this->originalResults = $originalResults;
  $facet
    ->setResults($this->originalResults);
  $facet
    ->setFieldIdentifier('owl');
  $facet
    ->setWidget('slider', []);
  $startTime = microtime(TRUE);
  $build = $this->widget
    ->build($facet);
  $stopTime = microtime(TRUE);
  if ($stopTime - $startTime > 1) {
    $this
      ->fail('Test is too slow');
  }
  $this
    ->assertSame('array', gettype($build));
  $build = $build['#attached']['drupalSettings']['facets']['sliders']['barn_owl'];
  $this
    ->assertEquals(3, $build['min']);
  $this
    ->assertEquals(19999, $build['max']);
  return $build;
}