class SliderWidgetTest in Facets 8
Unit test for widget.
@group facets
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\facets\Unit\Plugin\widget\WidgetTestBase
- class \Drupal\Tests\facets_range_widget\Unit\Plugin\widget\SliderWidgetTest
- class \Drupal\Tests\facets\Unit\Plugin\widget\WidgetTestBase
Expanded class hierarchy of SliderWidgetTest
File
- modules/
facets_range_widget/ tests/ src/ Unit/ Plugin/ widget/ SliderWidgetTest.php, line 19
Namespace
Drupal\Tests\facets_range_widget\Unit\Plugin\widgetView source
class SliderWidgetTest extends WidgetTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->widget = new SliderWidget([], 'slider_widget', []);
}
/**
* {@inheritdoc}
*/
public function testGetQueryType() {
$result = $this->widget
->getQueryType($this->queryTypes);
$this
->assertEquals(NULL, $result);
}
/**
* {@inheritdoc}
*/
public function testDefaultConfiguration() {
$default_config = $this->widget
->defaultConfiguration();
$expected = [
'show_numbers' => FALSE,
'prefix' => '',
'suffix' => '',
'min_type' => 'search_result',
'min_value' => 0,
'max_type' => 'search_result',
'max_value' => 10,
'step' => 1,
];
$this
->assertEquals($expected, $default_config);
}
/**
* {@inheritdoc}
*/
public function testIsPropertyRequired() {
$this
->assertFalse($this->widget
->isPropertyRequired('llama', 'owl'));
$this
->assertTrue($this->widget
->isPropertyRequired('slider', 'processors'));
$this
->assertTrue($this->widget
->isPropertyRequired('show_only_one_result', 'settings'));
}
/**
* Tests building of the widget.
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
SliderWidgetTest:: |
public | function |
Sets up the container and other variables used in all the tests. Overrides WidgetTestBase:: |
1 |
SliderWidgetTest:: |
public | function | Tests building of the widget. | 1 |
SliderWidgetTest:: |
public | function |
Tests default configuration. Overrides WidgetTestBase:: |
1 |
SliderWidgetTest:: |
public | function |
Tests get query type. Overrides WidgetTestBase:: |
1 |
SliderWidgetTest:: |
public | function |
Tests default for required properties. Overrides WidgetTestBase:: |
1 |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
WidgetTestBase:: |
protected | property | The facet used for the widget test. | |
WidgetTestBase:: |
protected | property | An array containing the results for the widget. | |
WidgetTestBase:: |
protected | property | An array of possible query types. | |
WidgetTestBase:: |
protected | property | The widget to be tested. | |
WidgetTestBase:: |
protected | function | Build a formattable markup object to use as assertion. |