Commit a7984df2 authored by alexpott's avatar alexpott

Issue #2769289 by idebr, dww, vacho, Madis, brahmjeet789, benjifisher,...

Issue #2769289 by idebr, dww, vacho, Madis, brahmjeet789, benjifisher, Lendude, Shabbir: Can't show 'revision author' on views of type 'Content'
parent ef16feda
......@@ -243,8 +243,12 @@ public function getViewsData() {
$data['node_field_revision']['langcode']['help'] = $this->t('The language the original content is in.');
$data['node_revision']['revision_uid']['help'] = $this->t('Relate a content revision to the user who created the revision.');
$data['node_revision']['revision_uid']['help'] = $this->t('The user who created the revision.');
$data['node_revision']['revision_uid']['relationship']['label'] = $this->t('revision user');
$data['node_revision']['revision_uid']['filter']['id'] = 'user_name';
$data['node_revision']['table']['join']['node_field_data']['left_field'] = 'vid';
$data['node_revision']['table']['join']['node_field_data']['field'] = 'vid';
$data['node_field_revision']['table']['wizard_id'] = 'node_field_revision';
......
<?php
namespace Drupal\Tests\node\Kernel\Views;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Tests\ViewResultAssertionTrait;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
/**
* Tests the node_revision_uid field.
*
* @group node
*/
class RevisionUidTest extends ViewsKernelTestBase {
use UserCreationTrait;
use ViewResultAssertionTrait;
/**
* {@inheritdoc}
*/
public static $modules = [
'node',
'node_test_views',
'system',
'user',
'views',
];
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_node_revision_uid'];
/**
* Map column names.
*
* @var array
*/
public static $columnMap = [
'nid' => 'nid',
'vid' => 'vid',
'uid' => 'uid',
'revision_uid' => 'revision_uid',
];
/**
* {@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']);
}
}
/**
* Tests the node_revision_uid relationship.
*/
public function testRevisionUid() {
$primary_author = $this->createUser();
$secondary_author = $this->createUser();
$node_type = NodeType::create([
'type' => 'page',
]);
$node_type->save();
$node = Node::create([
'title' => 'Test node',
'type' => 'page',
'uid' => $primary_author->id(),
]);
$node->save();
$view = Views::getView('test_node_revision_uid');
$this->executeView($view);
$this->assertIdenticalResultset($view, [
[
'nid' => 1,
'vid' => 1,
'uid' => $primary_author->id(),
'revision_uid' => $primary_author->id(),
],
], static::$columnMap);
// Test results shows the original author as well as the revision author.
$node->setRevisionUser($secondary_author);
$node->setNewRevision();
$node->save();
$view = Views::getView('test_node_revision_uid');
$this->executeView($view);
$this->assertIdenticalResultset($view, [
[
'nid' => 1,
'vid' => 2,
'uid' => $primary_author->id(),
'revision_uid' => $secondary_author->id(),
],
], static::$columnMap);
// Build a larger dataset to allow filtering.
$node2_title = $this->randomString();
$node2 = Node::create([
'title' => $node2_title,
'type' => 'page',
'uid' => $primary_author->id(),
]);
$node2->save();
$node2->setRevisionUser($primary_author);
$node2->setNewRevision();
$node2->save();
$view = Views::getView('test_node_revision_uid');
$this->executeView($view);
$this->assertIdenticalResultset($view, [
[
'nid' => 1,
'vid' => 2,
'uid' => $primary_author->id(),
'revision_uid' => $secondary_author->id(),
],
[
'nid' => 2,
'vid' => 4,
'uid' => $primary_author->id(),
'revision_uid' => $primary_author->id(),
],
], static::$columnMap);
// Test filter by revision_uid.
$view = Views::getView('test_node_revision_uid');
$view->initHandlers();
$view->filter['revision_uid']->value = [$secondary_author->id()];
$this->executeView($view);
$this->assertIdenticalResultset($view, [
[
'nid' => 1,
'vid' => 2,
'uid' => $primary_author->id(),
'revision_uid' => $secondary_author->id(),
],
], static::$columnMap);
}
}
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