3 namespace Drupal\Tests\views\Kernel;
5 use Drupal\views\Views;
8 * A basic query test for Views.
12 class BasicTest extends ViewsKernelTestBase {
15 * Views used by this test.
19 public static $testViews = ['test_view', 'test_simple_argument'];
22 * Tests a trivial result set.
24 public function testSimpleResultSet() {
25 $view = Views::getView('test_view');
29 $this->executeView($view);
32 $this->assertEqual(5, count($view->result), 'The number of returned rows match.');
33 $this->assertIdenticalResultset($view, $this->dataSet(), [
34 'views_test_data_name' => 'name',
35 'views_test_data_age' => 'age',
40 * Tests filtering of the result set.
42 public function testSimpleFiltering() {
43 $view = Views::getView('test_view');
47 $view->displayHandlers->get('default')->overrideOption('filters', [
62 'table' => 'views_test_data',
64 'relationship' => 'none',
69 $this->executeView($view);
71 // Build the expected result.
91 $this->assertEqual(3, count($view->result), 'The number of returned rows match.');
92 $this->assertIdenticalResultSet($view, $dataset, [
93 'views_test_data_name' => 'name',
94 'views_test_data_age' => 'age',
99 * Tests simple argument.
101 public function testSimpleArgument() {
102 // Execute with a view
103 $view = Views::getView('test_simple_argument');
104 $view->setArguments([27]);
105 $this->executeView($view);
107 // Build the expected result.
116 // Verify the result.
117 $this->assertEqual(1, count($view->result), 'The number of returned rows match.');
118 $this->assertIdenticalResultSet($view, $dataset, [
119 'views_test_data_name' => 'name',
120 'views_test_data_age' => 'age',
123 // Test "show all" if no argument is present.
124 $view = Views::getView('test_simple_argument');
125 $this->executeView($view);
127 // Build the expected result.
128 $dataset = $this->dataSet();
130 $this->assertEqual(5, count($view->result), 'The number of returned rows match.');
131 $this->assertIdenticalResultSet($view, $dataset, [
132 'views_test_data_name' => 'name',
133 'views_test_data_age' => 'age',