- <?php
-
- * @file
- * Definition of ViewsHandlerSortDateTest.
- */
-
- require_once BACKDROP_ROOT . '/core/modules/views/tests/views_query.test';
-
- * Tests for core views_handler_sort_date handler.
- */
- class ViewsHandlerSortDateTest extends ViewsSqlTest {
- protected function setUp() {
- parent::setUp();
-
-
-
- config_set('system.date', 'default_timezone', 'UTC');
- config_set('system.date', 'user_configurable_timezones', 0);
- }
- protected function expectedResultSet($granularity, $reverse = TRUE) {
- $expected = array();
- if (!$reverse) {
- switch ($granularity) {
- case 'second':
- $expected = array(
- array('name' => 'John'),
- array('name' => 'Paul'),
- array('name' => 'Meredith'),
- array('name' => 'Ringo'),
- array('name' => 'George'),
- );
- break;
- case 'minute':
- $expected = array(
- array('name' => 'John'),
- array('name' => 'Paul'),
- array('name' => 'Ringo'),
- array('name' => 'Meredith'),
- array('name' => 'George'),
- );
- break;
- case 'hour':
- $expected = array(
- array('name' => 'John'),
- array('name' => 'Ringo'),
- array('name' => 'Paul'),
- array('name' => 'Meredith'),
- array('name' => 'George'),
- );
- break;
- case 'day':
- $expected = array(
- array('name' => 'John'),
- array('name' => 'Ringo'),
- array('name' => 'Paul'),
- array('name' => 'Meredith'),
- array('name' => 'George'),
- );
- break;
- case 'month':
- $expected = array(
- array('name' => 'John'),
- array('name' => 'George'),
- array('name' => 'Ringo'),
- array('name' => 'Paul'),
- array('name' => 'Meredith'),
- );
- break;
- case 'year':
- $expected = array(
- array('name' => 'John'),
- array('name' => 'George'),
- array('name' => 'Ringo'),
- array('name' => 'Paul'),
- array('name' => 'Meredith'),
- );
- break;
- }
- }
- else {
- switch ($granularity) {
- case 'second':
- $expected = array(
- array('name' => 'George'),
- array('name' => 'Ringo'),
- array('name' => 'Meredith'),
- array('name' => 'Paul'),
- array('name' => 'John'),
- );
- break;
- case 'minute':
- $expected = array(
- array('name' => 'George'),
- array('name' => 'Ringo'),
- array('name' => 'Meredith'),
- array('name' => 'Paul'),
- array('name' => 'John'),
- );
- break;
- case 'hour':
- $expected = array(
- array('name' => 'George'),
- array('name' => 'Ringo'),
- array('name' => 'Paul'),
- array('name' => 'Meredith'),
- array('name' => 'John'),
- );
- break;
- case 'day':
- $expected = array(
- array('name' => 'George'),
- array('name' => 'John'),
- array('name' => 'Ringo'),
- array('name' => 'Paul'),
- array('name' => 'Meredith'),
- );
- break;
- case 'month':
- $expected = array(
- array('name' => 'John'),
- array('name' => 'George'),
- array('name' => 'Ringo'),
- array('name' => 'Paul'),
- array('name' => 'Meredith'),
- );
- break;
- case 'year':
- $expected = array(
- array('name' => 'John'),
- array('name' => 'George'),
- array('name' => 'Ringo'),
- array('name' => 'Paul'),
- array('name' => 'Meredith'),
- );
- break;
- }
- }
-
- return $expected;
- }
-
-
- * Tests numeric ordering of the result set.
- */
- public function testDateOrdering() {
- foreach (array('second', 'minute', 'hour', 'day', 'month', 'year') as $granularity) {
- foreach (array(FALSE, TRUE) as $reverse) {
- $view = $this->getBasicView();
-
-
- $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',
- ),
- ));
-
-
- $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',
- ),
- ));
-
-
- $this->executeView($view);
-
-
- $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);
- }
- }
- }
- }