Commit 8bd5ae4b authored by catch's avatar catch

Issue #2630886 by dawehner: Correct the join from revision data table to revision base table

parent f0869990
<?php
/**
* @file
* Contains \Drupal\node\Tests\Views\RevisionCreateTimestampTest.
*/
namespace Drupal\node\Tests\Views;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\views\Tests\ViewKernelTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
/**
* Ensures that the revision create time can be accessed in views.
*
* @group views
*/
class RevisionCreateTimestampTest extends ViewKernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['node_test_views', 'node', 'views', 'user'];
/**
* {@inheritdoc}
*/
public static $testViews = ['test_node_revision_timestamp'];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->installSchema('node', 'node_access');
$this->installEntitySchema('node');
$this->installEntitySchema('user');
if ($import_test_views) {
ViewTestData::createTestViews(get_class($this), ['node_test_views']);
}
}
public function testRevisionCreateTimestampView() {
$node_type = NodeType::create([
'type' => 'article',
'label' => 'Article',
]);
$node_type->save();
$node = Node::create([
'title' => 'Test node',
'type' => 'article',
'revision_timestamp' => 1000,
]);
$node->save();
$node->setRevisionCreationTime(1200);
$node->setNewRevision(TRUE);
$node->save();
$node->setRevisionCreationTime(1400);
$node->setNewRevision(TRUE);
$node->save();
$view = Views::getView('test_node_revision_timestamp');
$this->executeView($view);
$this->assertIdenticalResultset($view, [
['vid' => 3, 'revision_timestamp' => 1400],
['vid' => 2, 'revision_timestamp' => 1200],
['vid' => 1, 'revision_timestamp' => 1000],
], ['vid' => 'vid', 'revision_timestamp' => 'revision_timestamp']);
}
}
langcode: en
status: true
dependencies:
module:
- node
id: test_node_revision_timestamp
label: null
module: views
description: ''
tag: ''
base_table: node_field_revision
base_field: vid
core: '8'
display:
default:
display_options:
fields:
vid:
id: vid
table: node_field_revision
field: vid
plugin_id: field
entity_type: node
entity_field: vid
revision_timestamp:
id: revision_timestamp
table: node_revision
field: revision_timestamp
plugin_id: field
entity_type: node
entity_field: revision_timestamp
sorts:
revision_timestamp:
id: revision_timestamp
table: node_revision
field: revision_timestamp
order: DESC
plugin_id: field
entity_type: node
entity_field: revision_timestamp
display_plugin: default
display_title: Master
id: default
position: 0
......@@ -217,7 +217,7 @@ public function getViewsData() {
$data[$revision_data_table]['table']['group'] = $this->t('@entity_type revision', ['@entity_type' => $this->entityType->getLabel()]);
$data[$revision_data_table]['table']['entity revision'] = TRUE;
$data[$revision_data_table]['table']['join'][$revision_table] = array(
$data[$revision_table]['table']['join'][$revision_data_table] = array(
'left_field' => $revision_field,
'field' => $revision_field,
'type' => 'INNER',
......
......@@ -282,16 +282,21 @@ public function testRevisionTableWithRevisionDataTableAndDataTable() {
// Ensure the join information is set up properly.
// Tests the join definition between the base and the revision table.
$revision_data = $data['entity_test_mulrev_property_revision'];
$this->assertCount(2, $revision_data['table']['join']);
$revision_field_data = $data['entity_test_mulrev_property_revision'];
$this->assertCount(1, $revision_field_data['table']['join']);
$this->assertEquals([
'entity_test_mul_property_data' => [
'left_field' => 'revision_id', 'field' => 'revision_id', 'type' => 'INNER'
],
'entity_test_mulrev_revision' => [
], $revision_field_data['table']['join']);
$revision_base_data = $data['entity_test_mulrev_revision'];
$this->assertCount(1, $revision_base_data['table']['join']);
$this->assertEquals([
'entity_test_mulrev_property_revision' => [
'left_field' => 'revision_id', 'field' => 'revision_id', 'type' => 'INNER'
],
], $revision_data['table']['join']);
], $revision_base_data['table']['join']);
$this->assertFalse(isset($data['data_table']));
}
......@@ -321,12 +326,21 @@ public function testRevisionTableWithRevisionDataTable() {
// Ensure the join information is set up properly.
// Tests the join definition between the base and the revision table.
$revision_data = $data['entity_test_mulrev_property_revision'];
$this->assertCount(2, $revision_data['table']['join']);
$revision_field_data = $data['entity_test_mulrev_property_revision'];
$this->assertCount(1, $revision_field_data['table']['join']);
$this->assertEquals([
'entity_test_mulrev_field_data' => [
'left_field' => 'revision_id', 'field' => 'revision_id', 'type' => 'INNER'
],
], $revision_field_data['table']['join']);
$revision_base_data = $data['entity_test_mulrev_revision'];
$this->assertCount(1, $revision_base_data['table']['join']);
$this->assertEquals([
'entity_test_mulrev_field_data' => ['left_field' => 'revision_id', 'field' => 'revision_id', 'type' => 'INNER'],
'entity_test_mulrev_revision' => ['left_field' => 'revision_id', 'field' => 'revision_id', 'type' => 'INNER'],
], $revision_data['table']['join']);
'entity_test_mulrev_property_revision' => [
'left_field' => 'revision_id', 'field' => 'revision_id', 'type' => 'INNER'
],
], $revision_base_data['table']['join']);
$this->assertFalse(isset($data['data_table']));
}
......
......@@ -331,3 +331,19 @@ function views_update_8003() {
/**
* @} End of "addtogroup updates-8.0.0-rc".
*/
/**
* @addtogroup updates-8.0.4
* @{
*/
/**
* Clear caches due to updated entity views data.
*/
function views_update_8004() {
// Empty update to cause a cache flush so that views data is rebuilt.
}
/**
* @} End of "addtogroup updates-8.0.4".
*/
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