Commit 59d12bce authored by alexpott's avatar alexpott

Issue #2631958 by mpdonadio: Remove unnecessary query method in...

Issue #2631958 by mpdonadio: Remove unnecessary query method in \Drupal\datetime\Plugin\views\sort\Date
parent aac6a3f9
......@@ -27,22 +27,6 @@ public function getDateField() {
return "$this->tableAlias.$this->realField";
}
/**
* Override query to provide 'second' granularity.
*/
public function query() {
$this->ensureMyTable();
switch ($this->options['granularity']) {
case 'second':
$formula = $this->getDateFormat('YmdHis');
$this->query->addOrderBy(NULL, $formula, $this->options['order'], $this->tableAlias . '_' . $this->field . '_' . $this->options['granularity']);
return;
}
// All other granularities are handled by the numeric sort handler.
parent::query();
}
/**
* {@inheritdoc}
*
......
......@@ -33,6 +33,9 @@ public function setUp() {
'2000-10-10T00:01:00',
'2000-10-10T00:02:00',
'2000-10-10T00:03:00',
'2000-10-10T00:03:02',
'2000-10-10T00:03:01',
'2000-10-10T00:03:03',
];
foreach ($dates as $date) {
$this->nodes[] = $this->drupalCreateNode([
......@@ -50,7 +53,8 @@ public function testDateTimeSort() {
$field = static::$field_name . '_value';
$view = Views::getView('test_sort_datetime');
// Sort order is DESC.
// Set granularity to 'minute', and the secondary node ID order should
// define the order of nodes with the same minute.
$view->initHandlers();
$view->sort[$field]->options['granularity'] = 'minute';
$view->setDisplay('default');
......@@ -58,6 +62,9 @@ public function testDateTimeSort() {
$expected_result = [
['nid' => $this->nodes[0]->id()],
['nid' => $this->nodes[3]->id()],
['nid' => $this->nodes[4]->id()],
['nid' => $this->nodes[5]->id()],
['nid' => $this->nodes[6]->id()],
['nid' => $this->nodes[2]->id()],
['nid' => $this->nodes[1]->id()],
];
......@@ -74,6 +81,9 @@ public function testDateTimeSort() {
['nid' => $this->nodes[1]->id()],
['nid' => $this->nodes[2]->id()],
['nid' => $this->nodes[3]->id()],
['nid' => $this->nodes[5]->id()],
['nid' => $this->nodes[4]->id()],
['nid' => $this->nodes[6]->id()],
['nid' => $this->nodes[0]->id()],
];
$this->assertIdenticalResultset($view, $expected_result, $this->map);
......@@ -91,6 +101,27 @@ public function testDateTimeSort() {
['nid' => $this->nodes[1]->id()],
['nid' => $this->nodes[2]->id()],
['nid' => $this->nodes[3]->id()],
['nid' => $this->nodes[4]->id()],
['nid' => $this->nodes[5]->id()],
['nid' => $this->nodes[6]->id()],
];
$this->assertIdenticalResultset($view, $expected_result, $this->map);
$view->destroy();
// Change granularity to 'second'.
$view->initHandlers();
$view->sort[$field]->options['granularity'] = 'second';
$view->sort[$field]->options['order'] = 'DESC';
$view->setDisplay('default');
$this->executeView($view);
$expected_result = [
['nid' => $this->nodes[0]->id()],
['nid' => $this->nodes[6]->id()],
['nid' => $this->nodes[4]->id()],
['nid' => $this->nodes[5]->id()],
['nid' => $this->nodes[3]->id()],
['nid' => $this->nodes[2]->id()],
['nid' => $this->nodes[1]->id()],
];
$this->assertIdenticalResultset($view, $expected_result, $this->map);
$view->destroy();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment