function BasicTest::testSimpleFiltering
Same name in other branches
- 8.9.x core/modules/views/tests/src/Kernel/BasicTest.php \Drupal\Tests\views\Kernel\BasicTest::testSimpleFiltering()
- 10 core/modules/views/tests/src/Kernel/BasicTest.php \Drupal\Tests\views\Kernel\BasicTest::testSimpleFiltering()
- 11.x core/modules/views/tests/src/Kernel/BasicTest.php \Drupal\Tests\views\Kernel\BasicTest::testSimpleFiltering()
Tests filtering of the result set.
File
-
core/
modules/ views/ tests/ src/ Kernel/ BasicTest.php, line 42
Class
- BasicTest
- A basic query test for Views.
Namespace
Drupal\Tests\views\KernelCode
public function testSimpleFiltering() {
$view = Views::getView('test_view');
$view->setDisplay();
// Add a filter.
$view->displayHandlers
->get('default')
->overrideOption('filters', [
'age' => [
'operator' => '<',
'value' => [
'value' => '28',
'min' => '',
'max' => '',
],
'group' => '0',
'exposed' => FALSE,
'expose' => [
'operator' => FALSE,
'label' => '',
],
'id' => 'age',
'table' => 'views_test_data',
'field' => 'age',
'relationship' => 'none',
],
]);
// Execute the view.
$this->executeView($view);
// Build the expected result.
$dataset = [
[
'id' => 1,
'name' => 'John',
'age' => 25,
],
[
'id' => 2,
'name' => 'George',
'age' => 27,
],
[
'id' => 4,
'name' => 'Paul',
'age' => 26,
],
];
// Verify the result.
$this->assertCount(3, $view->result, 'The number of returned rows match.');
$this->assertIdenticalResultSet($view, $dataset, [
'views_test_data_name' => 'name',
'views_test_data_age' => 'age',
]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.