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