public function RangeViewsFilterTest::testRangeViewsFilter in Range 8
Tests range views filter.
File
- tests/
src/ Functional/ Views/ RangeViewsFilterTest.php, line 43
Class
- RangeViewsFilterTest
- Tests the range views filter handler.
Namespace
Drupal\Tests\range\Functional\ViewsCode
public function testRangeViewsFilter() {
$view = Views::getView('test_filter_range');
// Range contains, exclude endpoints.
$view
->initHandlers();
$view->filter[$this->fieldName]->operator = 'within';
$view->filter[$this->fieldName]->value = 5;
$view->filter[$this->fieldName]->options['include_endpoints'] = FALSE;
$view
->setDisplay('default');
$this
->executeView($view);
$expected_result = [
[
'nid' => $this->nodes[0]
->id(),
],
[
'nid' => $this->nodes[2]
->id(),
],
];
$this
->assertIdenticalResultset($view, $expected_result, $this->map, 'Range views filter (contains, exclude endpoints) produces correct results');
$view
->destroy();
// Range contains, include endpoints.
$view
->initHandlers();
$view->filter[$this->fieldName]->operator = 'within';
$view->filter[$this->fieldName]->value = 5;
$view->filter[$this->fieldName]->options['include_endpoints'] = TRUE;
$view
->setDisplay('default');
$this
->executeView($view);
$expected_result = [
[
'nid' => $this->nodes[0]
->id(),
],
[
'nid' => $this->nodes[1]
->id(),
],
[
'nid' => $this->nodes[2]
->id(),
],
[
'nid' => $this->nodes[3]
->id(),
],
];
$this
->assertIdenticalResultset($view, $expected_result, $this->map, 'Range views filter (contains, include endpoints) produces correct results');
$view
->destroy();
// Range does contains, exclude endpoints.
$view
->initHandlers();
$view->filter[$this->fieldName]->operator = 'not within';
$view->filter[$this->fieldName]->value = 5;
$view->filter[$this->fieldName]->options['include_endpoints'] = FALSE;
$view
->setDisplay('default');
$this
->executeView($view);
$expected_result = [
[
'nid' => $this->nodes[1]
->id(),
],
[
'nid' => $this->nodes[3]
->id(),
],
];
$this
->assertIdenticalResultset($view, $expected_result, $this->map, 'Range views filter (does not contain, exclude endpoints) produces correct results');
$view
->destroy();
// Range does contains, include endpoints.
$view
->initHandlers();
$view->filter[$this->fieldName]->operator = 'not within';
$view->filter[$this->fieldName]->value = 5;
$view->filter[$this->fieldName]->options['include_endpoints'] = TRUE;
$view
->setDisplay('default');
$this
->executeView($view);
$expected_result = [];
$this
->assertIdenticalResultset($view, $expected_result, $this->map, 'Range views filter (does not contain, include endpoints) produces correct results');
$view
->destroy();
}