function ViewsHandlerSortDateTest::testDateOrdering
Tests numeric ordering of the result set.
File
-
tests/
handlers/ views_handler_sort_date.test, line 162
Class
- ViewsHandlerSortDateTest
- Tests for core views_handler_sort_date handler.
Code
public function testDateOrdering() {
foreach (array(
'second',
'minute',
'hour',
'day',
'month',
'year',
) as $granularity) {
foreach (array(
FALSE,
TRUE,
) as $reverse) {
$view = $this->getBasicView();
// Change the fields.
$view->display['default']->handler
->override_option('fields', array(
'name' => array(
'id' => 'name',
'table' => 'views_test',
'field' => 'name',
'relationship' => 'none',
),
'created' => array(
'id' => 'created',
'table' => 'views_test',
'field' => 'created',
'relationship' => 'none',
),
));
// Change the ordering.
$view->display['default']->handler
->override_option('sorts', array(
'created' => array(
'id' => 'created',
'table' => 'views_test',
'field' => 'created',
'relationship' => 'none',
'granularity' => $granularity,
'order' => $reverse ? 'DESC' : 'ASC',
),
'id' => array(
'id' => 'id',
'table' => 'views_test',
'field' => 'id',
'relationship' => 'none',
'order' => 'ASC',
),
));
// Execute the view.
$this->executeView($view);
// Verify the result.
$this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
$this->assertIdenticalResultset($view, $this->expectedResultSet($granularity, $reverse), array(
'views_test_name' => 'name',
), t('Result is returned correctly when ordering by granularity @granularity, @reverse.', array(
'@granularity' => $granularity,
'@reverse' => $reverse ? t('reverse') : t('forward'),
)));
$view->destroy();
unset($view);
}
}
}