class BetterExposedFiltersTest in Better Exposed Filters 8.3
@coversDefaultClass \Drupal\better_exposed_filters\Plugin\views\exposed_form\BetterExposedFilters @group bef
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\better_exposed_filters\Tests\BetterExposedFiltersTest
Expanded class hierarchy of BetterExposedFiltersTest
File
- tests/
src/ Unit/ BetterExposedFiltersTest.php, line 12
Namespace
Drupal\better_exposed_filters\TestsView source
class BetterExposedFiltersTest extends UnitTestCase {
/**
* Order in the returned array matters for BEF rewrites. But assertEquals
* don't take array order into account.
*
* @param $expected
* Expectedd value.
* @param $actual
* Actual value.
* @param $message
* Optionsal error message on failure.
*/
protected function assertRewrite($expected, $actual, $message = NULL) {
// Order matters.
foreach ($actual as $actual_item) {
$expected_item = array_shift($expected);
$this
->assertEquals($expected_item, $actual_item, $message);
}
}
public function providerTestRewriteOptions() {
$data = [];
// Super basic rewrite.
$data[] = [
[
'foo' => 'bar',
],
"bar|baz",
[
'foo' => 'baz',
],
];
// Removes an option.
$data[] = [
[
'foo' => 'bar',
],
"bar|",
[],
];
// An option in the middle is removed -- preserves order.
$data[] = [
[
'foo' => '1',
'bar' => '2',
'baz' => '3',
],
"2|",
[
'foo' => '1',
'baz' => '3',
],
];
// Ensure order is preserved.
$data[] = [
[
'foo' => '1',
'bar' => '2',
'baz' => '3',
],
"2|Two",
[
'foo' => '1',
'bar' => 'Two',
'baz' => '3',
],
];
// No options are replaced.
$data[] = [
[
'foo' => '1',
'bar' => '2',
'baz' => '3',
],
"4|Two",
[
'foo' => '1',
'bar' => '2',
'baz' => '3',
],
];
// All options are replaced.
$data[] = [
[
'foo' => '1',
'bar' => '2',
'baz' => '3',
],
"1|One\n2|Two\n3|Three",
[
'foo' => 'One',
'bar' => 'Two',
'baz' => 'Three',
],
];
return $data;
}
/**
* Tests options are rewritten correctly.
*
* @dataProvider providerTestRewriteOptions
* @covers ::rewriteOptions
*/
public function testRewriteOptions($options, $rewriteSettings, $expected) {
$bef = new TestBEF([], 'default', []);
$actual = $bef
->testRewriteOptions($options, $rewriteSettings);
$this
->assertRewrite($expected, $actual);
}
public function providerTestRewriteReorderOptions() {
$data = [];
// Basic use case.
$data[] = [
[
'foo' => '1',
'bar' => '2',
'baz' => '3',
],
'2|Two',
[
'bar' => 'Two',
'foo' => '1',
'baz' => '3',
],
];
// No option replaced should not change the order
$data[] = [
[
'foo' => '1',
'bar' => '2',
'baz' => '3',
],
'4|Four',
[
'foo' => '1',
'bar' => '2',
'baz' => '3',
],
];
// Completely reorder options
$data[] = [
[
'foo' => '1',
'bar' => '2',
'baz' => '3',
],
"3|Three\n2|Two\n1|One",
[
'baz' => 'Three',
'bar' => 'Two',
'foo' => 'One',
],
];
return $data;
}
/**
* Tests options are rewritten correctly.
*
* @dataProvider providerTestRewriteReorderOptions
* @covers ::rewriteOptions
*/
public function testRewriteReorderOptions($options, $rewriteSettings, $expected) {
$bef = new TestBEF([], 'default', []);
$actual = $bef
->testRewriteOptions($options, $rewriteSettings, TRUE);
$this
->assertRewrite($expected, $actual);
}
public function providerTestRewriteTaxonomy() {
$data = [];
// Replace a single item, no change in order.
$data[] = [
[
(object) [
'option' => [
123 => 'term1',
],
],
(object) [
'option' => [
456 => 'term2',
],
],
(object) [
'option' => [
789 => 'term3',
],
],
],
"term2|Two",
[
(object) [
'option' => [
123 => 'term1',
],
],
(object) [
'option' => [
456 => 'Two',
],
],
(object) [
'option' => [
789 => 'term3',
],
],
],
];
// Replace all items, no change in order.
$data[] = [
[
(object) [
'option' => [
123 => 'term1',
],
],
(object) [
'option' => [
456 => 'term2',
],
],
(object) [
'option' => [
789 => 'term3',
],
],
],
"term2|Two\nterm3|Three\nterm1|One",
[
(object) [
'option' => [
123 => 'One',
],
],
(object) [
'option' => [
456 => 'Two',
],
],
(object) [
'option' => [
789 => 'Three',
],
],
],
];
// @TODO:
// Replace a single item, with change in order.
//$data[] = [
// [
// (object)['option' => [123 => 'term1']],
// (object)['option' => [456 => 'term2']],
// (object)['option' => [789 => 'term3']],
// ],
// "term2|Two",
// [
// (object)['option' => [456 => 'Two']],
// (object)['option' => [123 => 'term1']],
// (object)['option' => [789 => 'term3']],
// ],
// TRUE,
//];
//// Replace all items, with change in order.
//$data[] = [
// [
// (object)['option' => [123 => 'term1']],
// (object)['option' => [456 => 'term2']],
// (object)['option' => [789 => 'term3']],
// ],
// "term2|Two\nterm3|Three\nterm1|One",
// [
// (object)['option' => [456 => 'Two']],
// (object)['option' => [789 => 'Three']],
// (object)['option' => [123 => 'One']],
// ],
// TRUE,
//];
return $data;
}
/**
* Tests options are rewritten correctly.
*
* @dataProvider providerTestRewriteTaxonomy
* @covers ::rewriteOptions
*/
public function testRewriteTaxonomy($options, $rewriteSettings, $expected, $reorder = FALSE) {
$bef = new TestBEF([], 'default', []);
$actual = $bef
->testRewriteOptions($options, $rewriteSettings, $reorder);
$this
->assertRewrite($expected, $actual);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BetterExposedFiltersTest:: |
protected | function | Order in the returned array matters for BEF rewrites. But assertEquals don't take array order into account. | |
BetterExposedFiltersTest:: |
public | function | ||
BetterExposedFiltersTest:: |
public | function | ||
BetterExposedFiltersTest:: |
public | function | ||
BetterExposedFiltersTest:: |
public | function | Tests options are rewritten correctly. | |
BetterExposedFiltersTest:: |
public | function | Tests options are rewritten correctly. | |
BetterExposedFiltersTest:: |
public | function | Tests options are rewritten correctly. | |
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. | |
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. | |
UnitTestCase:: |
protected | function | 340 |