class RangeSliderProcessorTest in Facets 8
Unit test for processor.
@group facets @coversDefaultClass \Drupal\facets_range_widget\Plugin\facets\processor\RangeSliderProcessor
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\facets_range_widget\Unit\Plugin\processor\RangeSliderProcessorTest
Expanded class hierarchy of RangeSliderProcessorTest
File
- modules/
facets_range_widget/ tests/ src/ Unit/ Plugin/ processor/ RangeSliderProcessorTest.php, line 24
Namespace
Drupal\Tests\facets_range_widget\Unit\Plugin\processorView source
class RangeSliderProcessorTest extends UnitTestCase {
/**
* The processor we're testing.
*
* @var \Drupal\facets_range_widget\Plugin\facets\processor\RangeSliderProcessor
*/
protected $processor;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->processor = new RangeSliderProcessor([], 'range_slider', []);
$facets_url_generator = $this
->prophesize(FacetsUrlGenerator::class);
$facets_url_generator
->getUrl(Argument::any(), Argument::any())
->willReturn(new Url('test', [], [
'query' => [
'f' => [
'animals::(min:__range_slider_min__,max:__range_slider_max__)',
],
],
]));
$url_generator = $this
->prophesize(UrlGeneratorInterface::class);
$container = new ContainerBuilder();
$container
->set('url_generator', $url_generator
->reveal());
$container
->set('facets.utility.url_generator', $facets_url_generator
->reveal());
\Drupal::setContainer($container);
}
/**
* Tests the pre query method.
*
* @covers ::preQuery
*/
public function testPreQuery() {
$facet = new Facet([
'id' => 'llama',
], 'facets_facet');
$facet
->setActiveItems([
'(min:2,max:10)',
]);
$this->processor
->preQuery($facet);
$this
->assertCount(2, $facet
->getActiveItems()[0]);
$this
->assertEquals([
2,
10,
], $facet
->getActiveItems()[0]);
}
/**
* Tests the build method.
*
* @covers ::build
*/
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());
}
}
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. | |
RangeSliderProcessorTest:: |
protected | property | The processor we're testing. | |
RangeSliderProcessorTest:: |
public | function |
Overrides UnitTestCase:: |
|
RangeSliderProcessorTest:: |
public | function | Tests the build method. | |
RangeSliderProcessorTest:: |
public | function | Tests the pre query method. | |
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. |