Newer
Older
<?php
/**
* @file
* Contains \Drupal\views\Tests\Handler\ArgumentDateTest.
*/
namespace Drupal\views\Tests\Handler;
Alex Pott
committed
use Drupal\views\Tests\ViewKernelTestBase;
catch
committed
use Drupal\views\Views;
/**
* Tests the core date argument handlers.
*
* @group views
* @see \Drupal\views\Plugin\views\argument\Date
*/
Alex Pott
committed
class ArgumentDateTest extends ViewKernelTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_argument_date');
/**
* Stores the column map for this testCase.
*
* @var array
*/
protected $columnMap = array(
'id' => 'id',
);
/**
* {@inheritdoc}
*/
public function viewsData() {
$data = parent::viewsData();
$date_plugins = array(
Angie Byron
committed
'date_fulldate',
'date_day',
'date_month',
'date_week',
'date_year',
'date_year_month',
);
foreach ($date_plugins as $plugin_id) {
$data['views_test_data'][$plugin_id] = $data['views_test_data']['created'];
$data['views_test_data'][$plugin_id]['real field'] = 'created';
$data['views_test_data'][$plugin_id]['argument']['id'] = $plugin_id;
}
return $data;
}
/**
* Tests the CreatedFullDate handler.
*
* @see \Drupal\node\Plugin\views\argument\CreatedFullDate
*/
public function testCreatedFullDateHandler() {
catch
committed
$view = Views::getView('test_argument_date');
$view->setDisplay('default');
$this->executeView($view, array('20000102'));
$expected = array();
$expected[] = array('id' => 2);
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
$view->destroy();
$view->setDisplay('default');
$this->executeView($view, array('20000101'));
$expected = array();
$expected[] = array('id' => 1);
$expected[] = array('id' => 3);
$expected[] = array('id' => 4);
$expected[] = array('id' => 5);
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
$view->destroy();
$view->setDisplay('default');
$this->executeView($view, array('20001023'));
$expected = array();
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
$view->destroy();
}
/**
* Tests the Day handler.
*
* @see \Drupal\node\Plugin\views\argument\CreatedDay
*/
public function testDayHandler() {
catch
committed
$view = Views::getView('test_argument_date');
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
$view->setDisplay('embed_1');
$this->executeView($view, array('02'));
$expected = array();
$expected[] = array('id' => 2);
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
$view->destroy();
$view->setDisplay('embed_1');
$this->executeView($view, array('01'));
$expected = array();
$expected[] = array('id' => 1);
$expected[] = array('id' => 3);
$expected[] = array('id' => 4);
$expected[] = array('id' => 5);
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
$view->destroy();
$view->setDisplay('embed_1');
$this->executeView($view, array('23'));
$expected = array();
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
}
/**
* Tests the Month handler.
*
* @see \Drupal\node\Plugin\views\argument\CreatedMonth
*/
public function testMonthHandler() {
catch
committed
$view = Views::getView('test_argument_date');
$view->setDisplay('embed_2');
$this->executeView($view, array('01'));
$expected = array();
$expected[] = array('id' => 1);
$expected[] = array('id' => 2);
$expected[] = array('id' => 3);
$expected[] = array('id' => 4);
$expected[] = array('id' => 5);
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
$view->destroy();
$view->setDisplay('embed_2');
catch
committed
$this->executeView($view, array('12'));
$expected = array();
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
}
/**
* Tests the Week handler.
*
* @see \Drupal\node\Plugin\views\argument\CreatedWeek
*/
public function testWeekHandler() {
$this->container->get('database')->update('views_test_data')
->fields(array('created' => gmmktime(0, 0, 0, 9, 26, 2008)))
->condition('id', 1)
->execute();
$this->container->get('database')->update('views_test_data')
->fields(array('created' => gmmktime(0, 0, 0, 2, 29, 2004)))
->condition('id', 2)
->execute();
$this->container->get('database')->update('views_test_data')
->fields(array('created' => gmmktime(0, 0, 0, 1, 1, 2000)))
->condition('id', 3)
->execute();
$this->container->get('database')->update('views_test_data')
->fields(array('created' => gmmktime(0, 0, 0, 1, 10, 2000)))
->condition('id', 4)
->execute();
$this->container->get('database')->update('views_test_data')
->fields(array('created' => gmmktime(0, 0, 0, 2, 1, 2000)))
->condition('id', 5)
->execute();
catch
committed
$view = Views::getView('test_argument_date');
$view->setDisplay('embed_3');
// Check the week calculation for a leap year.
// @see http://wikipedia.org/wiki/ISO_week_date#Calculation
$this->executeView($view, array('39'));
$expected = array();
$expected[] = array('id' => 1);
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
$view->destroy();
$view->setDisplay('embed_3');
// Check the week calculation for the 29th of February in a leap year.
// @see http://wikipedia.org/wiki/ISO_week_date#Calculation
$this->executeView($view, array('09'));
$expected = array();
$expected[] = array('id' => 2);
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
$view->destroy();
$view->setDisplay('embed_3');
// The first jan 2000 was still in the last week of the previous year.
$this->executeView($view, array('52'));
$expected = array();
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
$expected[] = array('id' => 3);
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
$view->destroy();
$view->setDisplay('embed_3');
$this->executeView($view, array('02'));
$expected = array();
$expected[] = array('id' => 4);
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
$view->destroy();
$view->setDisplay('embed_3');
$this->executeView($view, array('05'));
$expected = array();
$expected[] = array('id' => 5);
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
$view->destroy();
$view->setDisplay('embed_3');
$this->executeView($view, array('23'));
$expected = array();
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
}
/**
* Tests the Year handler.
*
* @see \Drupal\node\Plugin\views\argument\CreatedYear
*/
public function testYearHandler() {
$this->container->get('database')->update('views_test_data')
->fields(array('created' => gmmktime(0, 0, 0, 1, 1, 2001)))
->condition('id', 3)
->execute();
$this->container->get('database')->update('views_test_data')
->fields(array('created' => gmmktime(0, 0, 0, 1, 1, 2002)))
->condition('id', 4)
->execute();
$this->container->get('database')->update('views_test_data')
->fields(array('created' => gmmktime(0, 0, 0, 1, 1, 2002)))
->condition('id', 5)
->execute();
catch
committed
$view = Views::getView('test_argument_date');
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
$view->setDisplay('embed_4');
$this->executeView($view, array('2000'));
$expected = array();
$expected[] = array('id' => 1);
$expected[] = array('id' => 2);
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
$view->destroy();
$view->setDisplay('embed_4');
$this->executeView($view, array('2001'));
$expected = array();
$expected[] = array('id' => 3);
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
$view->destroy();
$view->setDisplay('embed_4');
$this->executeView($view, array('2002'));
$expected = array();
$expected[] = array('id' => 4);
$expected[] = array('id' => 5);
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
$view->destroy();
$view->setDisplay('embed_4');
$this->executeView($view, array('23'));
$expected = array();
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
}
/**
* Tests the YearMonth handler.
*
* @see \Drupal\node\Plugin\views\argument\CreatedYearMonth
*/
public function testYearMonthHandler() {
$this->container->get('database')->update('views_test_data')
->fields(array('created' => gmmktime(0, 0, 0, 1, 1, 2001)))
->condition('id', 3)
->execute();
$this->container->get('database')->update('views_test_data')
->fields(array('created' => gmmktime(0, 0, 0, 4, 1, 2001)))
->condition('id', 4)
->execute();
$this->container->get('database')->update('views_test_data')
->fields(array('created' => gmmktime(0, 0, 0, 4, 1, 2001)))
->condition('id', 5)
->execute();
catch
committed
$view = Views::getView('test_argument_date');
$view->setDisplay('embed_5');
$this->executeView($view, array('200001'));
$expected = array();
$expected[] = array('id' => 1);
$expected[] = array('id' => 2);
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
$view->destroy();
$view->setDisplay('embed_5');
$this->executeView($view, array('200101'));
$expected = array();
$expected[] = array('id' => 3);
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
$view->destroy();
$view->setDisplay('embed_5');
$this->executeView($view, array('200104'));
$expected = array();
$expected[] = array('id' => 4);
$expected[] = array('id' => 5);
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
$view->destroy();
$view->setDisplay('embed_5');
catch
committed
$this->executeView($view, array('201301'));
$expected = array();
$this->assertIdenticalResultset($view, $expected, $this->columnMap);
}
}