Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / datetime / tests / src / Kernel / Views / ArgumentDateTimeTest.php
1 <?php
2
3 namespace Drupal\Tests\datetime\Kernel\Views;
4
5 use Drupal\node\Entity\Node;
6 use Drupal\views\Views;
7
8 /**
9  * Tests the Drupal\datetime\Plugin\views\filter\Date handler.
10  *
11  * @group datetime
12  */
13 class ArgumentDateTimeTest extends DateTimeHandlerTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $testViews = ['test_argument_datetime'];
19
20   /**
21    * {@inheritdoc}
22    */
23   protected function setUp($import_test_views = TRUE) {
24     parent::setUp($import_test_views);
25
26     // Add some basic test nodes.
27     $dates = [
28       '2000-10-10',
29       '2001-10-10',
30       '2002-01-01',
31     ];
32     foreach ($dates as $date) {
33       $node = Node::create([
34         'title' => $this->randomMachineName(8),
35         'type' => 'page',
36         'field_date' => [
37           'value' => $date,
38         ]
39       ]);
40       $node->save();
41       $this->nodes[] = $node;
42     }
43   }
44
45   /**
46    * Test year argument.
47    *
48    * @see \Drupal\datetime\Plugin\views\argument\YearDate
49    */
50   public function testDatetimeArgumentYear() {
51     $view = Views::getView('test_argument_datetime');
52
53     // The 'default' display has the 'year' argument.
54     $view->setDisplay('default');
55     $this->executeView($view, ['2000']);
56     $expected = [];
57     $expected[] = ['nid' => $this->nodes[0]->id()];
58     $this->assertIdenticalResultset($view, $expected, $this->map);
59     $view->destroy();
60
61     $view->setDisplay('default');
62     $this->executeView($view, ['2002']);
63     $expected = [];
64     $expected[] = ['nid' => $this->nodes[2]->id()];
65     $this->assertIdenticalResultset($view, $expected, $this->map);
66     $view->destroy();
67   }
68
69   /**
70    * Test month argument.
71    *
72    * @see \Drupal\datetime\Plugin\views\argument\MonthDate
73    */
74   public function testDatetimeArgumentMonth() {
75     $view = Views::getView('test_argument_datetime');
76     // The 'embed_1' display has the 'month' argument.
77     $view->setDisplay('embed_1');
78
79     $this->executeView($view, ['10']);
80     $expected = [];
81     $expected[] = ['nid' => $this->nodes[0]->id()];
82     $expected[] = ['nid' => $this->nodes[1]->id()];
83     $this->assertIdenticalResultset($view, $expected, $this->map);
84     $view->destroy();
85
86     $view->setDisplay('embed_1');
87     $this->executeView($view, ['01']);
88     $expected = [];
89     $expected[] = ['nid' => $this->nodes[2]->id()];
90     $this->assertIdenticalResultset($view, $expected, $this->map);
91     $view->destroy();
92   }
93
94   /**
95    * Test day argument.
96    *
97    * @see \Drupal\datetime\Plugin\views\argument\DayDate
98    */
99   public function testDatetimeArgumentDay() {
100     $view = Views::getView('test_argument_datetime');
101
102     // The 'embed_2' display has the 'day' argument.
103     $view->setDisplay('embed_2');
104     $this->executeView($view, ['10']);
105     $expected = [];
106     $expected[] = ['nid' => $this->nodes[0]->id()];
107     $expected[] = ['nid' => $this->nodes[1]->id()];
108     $this->assertIdenticalResultset($view, $expected, $this->map);
109     $view->destroy();
110
111     $view->setDisplay('embed_2');
112     $this->executeView($view, ['01']);
113     $expected = [];
114     $expected[] = ['nid' => $this->nodes[2]->id()];
115     $this->assertIdenticalResultset($view, $expected, $this->map);
116     $view->destroy();
117   }
118
119   /**
120    * Test year, month, and day arguments combined.
121    */
122   public function testDatetimeArgumentAll() {
123     $view = Views::getView('test_argument_datetime');
124     // The 'embed_3' display has year, month, and day arguments.
125     $view->setDisplay('embed_3');
126
127     $this->executeView($view, ['2000', '10', '10']);
128     $expected = [];
129     $expected[] = ['nid' => $this->nodes[0]->id()];
130     $this->assertIdenticalResultset($view, $expected, $this->map);
131     $view->destroy();
132
133     $view->setDisplay('embed_3');
134     $this->executeView($view, ['2002', '01', '01']);
135     $expected = [];
136     $expected[] = ['nid' => $this->nodes[2]->id()];
137     $this->assertIdenticalResultset($view, $expected, $this->map);
138     $view->destroy();
139   }
140
141   /**
142    * Test week WW argument.
143    */
144   public function testDatetimeArgumentWeek() {
145     $view = Views::getView('test_argument_datetime');
146     // The 'embed_4' display has WW argument.
147     $view->setDisplay('embed_4');
148
149     $this->executeView($view, ['41']);
150     $expected = [];
151     $expected[] = ['nid' => $this->nodes[0]->id()];
152     $expected[] = ['nid' => $this->nodes[1]->id()];
153     $this->assertIdenticalResultset($view, $expected, $this->map);
154     $view->destroy();
155
156     $view->setDisplay('embed_4');
157     $this->executeView($view, ['01']);
158     $expected = [];
159     $expected[] = ['nid' => $this->nodes[2]->id()];
160     $this->assertIdenticalResultset($view, $expected, $this->map);
161     $view->destroy();
162   }
163
164   /**
165    * Test full_date CCYYMMDD argument.
166    */
167   public function testDatetimeArgumentFullDate() {
168     $view = Views::getView('test_argument_datetime');
169     // The 'embed_5' display has CCYYMMDD argument.
170     $view->setDisplay('embed_5');
171
172     $this->executeView($view, ['20001010']);
173     $expected = [];
174     $expected[] = ['nid' => $this->nodes[0]->id()];
175     $this->assertIdenticalResultset($view, $expected, $this->map);
176     $view->destroy();
177
178     $view->setDisplay('embed_5');
179     $this->executeView($view, ['20020101']);
180     $expected = [];
181     $expected[] = ['nid' => $this->nodes[2]->id()];
182     $this->assertIdenticalResultset($view, $expected, $this->map);
183     $view->destroy();
184   }
185
186   /**
187    * Test year_month CCYYMM argument.
188    */
189   public function testDatetimeArgumentYearMonth() {
190     $view = Views::getView('test_argument_datetime');
191     // The 'embed_6' display has CCYYMM argument.
192     $view->setDisplay('embed_6');
193
194     $this->executeView($view, ['200010']);
195     $expected = [];
196     $expected[] = ['nid' => $this->nodes[0]->id()];
197     $this->assertIdenticalResultset($view, $expected, $this->map);
198     $view->destroy();
199
200     $view->setDisplay('embed_6');
201     $this->executeView($view, ['200201']);
202     $expected = [];
203     $expected[] = ['nid' => $this->nodes[2]->id()];
204     $this->assertIdenticalResultset($view, $expected, $this->map);
205     $view->destroy();
206   }
207
208 }