Mercurial > hg > isophonics-drupal-site
comparison core/modules/views/tests/src/Kernel/BasicTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\views\Kernel; | |
4 | |
5 use Drupal\views\Views; | |
6 | |
7 /** | |
8 * A basic query test for Views. | |
9 * | |
10 * @group views | |
11 */ | |
12 class BasicTest extends ViewsKernelTestBase { | |
13 | |
14 /** | |
15 * Views used by this test. | |
16 * | |
17 * @var array | |
18 */ | |
19 public static $testViews = ['test_view', 'test_simple_argument']; | |
20 | |
21 /** | |
22 * Tests a trivial result set. | |
23 */ | |
24 public function testSimpleResultSet() { | |
25 $view = Views::getView('test_view'); | |
26 $view->setDisplay(); | |
27 | |
28 // Execute the view. | |
29 $this->executeView($view); | |
30 | |
31 // Verify the result. | |
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', | |
36 ]); | |
37 } | |
38 | |
39 /** | |
40 * Tests filtering of the result set. | |
41 */ | |
42 public function testSimpleFiltering() { | |
43 $view = Views::getView('test_view'); | |
44 $view->setDisplay(); | |
45 | |
46 // Add a filter. | |
47 $view->displayHandlers->get('default')->overrideOption('filters', [ | |
48 'age' => [ | |
49 'operator' => '<', | |
50 'value' => [ | |
51 'value' => '28', | |
52 'min' => '', | |
53 'max' => '', | |
54 ], | |
55 'group' => '0', | |
56 'exposed' => FALSE, | |
57 'expose' => [ | |
58 'operator' => FALSE, | |
59 'label' => '', | |
60 ], | |
61 'id' => 'age', | |
62 'table' => 'views_test_data', | |
63 'field' => 'age', | |
64 'relationship' => 'none', | |
65 ], | |
66 ]); | |
67 | |
68 // Execute the view. | |
69 $this->executeView($view); | |
70 | |
71 // Build the expected result. | |
72 $dataset = [ | |
73 [ | |
74 'id' => 1, | |
75 'name' => 'John', | |
76 'age' => 25, | |
77 ], | |
78 [ | |
79 'id' => 2, | |
80 'name' => 'George', | |
81 'age' => 27, | |
82 ], | |
83 [ | |
84 'id' => 4, | |
85 'name' => 'Paul', | |
86 'age' => 26, | |
87 ], | |
88 ]; | |
89 | |
90 // Verify the 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', | |
95 ]); | |
96 } | |
97 | |
98 /** | |
99 * Tests simple argument. | |
100 */ | |
101 public function testSimpleArgument() { | |
102 // Execute with a view | |
103 $view = Views::getView('test_simple_argument'); | |
104 $view->setArguments([27]); | |
105 $this->executeView($view); | |
106 | |
107 // Build the expected result. | |
108 $dataset = [ | |
109 [ | |
110 'id' => 2, | |
111 'name' => 'George', | |
112 'age' => 27, | |
113 ], | |
114 ]; | |
115 | |
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', | |
121 ]); | |
122 | |
123 // Test "show all" if no argument is present. | |
124 $view = Views::getView('test_simple_argument'); | |
125 $this->executeView($view); | |
126 | |
127 // Build the expected result. | |
128 $dataset = $this->dataSet(); | |
129 | |
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', | |
134 ]); | |
135 } | |
136 | |
137 } |