Commit 2a6d8d71 authored by catch's avatar catch

Issue #3046281 by claudiu.cristea: Convert FilterUidRevisionTest into a Kernel test

parent a40b3879
<?php <?php
namespace Drupal\Tests\node\Functional\Views; namespace Drupal\Tests\node\Kernel\Views;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\views\Tests\ViewResultAssertionTrait;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views; use Drupal\views\Views;
/** /**
...@@ -9,7 +14,23 @@ ...@@ -9,7 +14,23 @@
* *
* @group node * @group node
*/ */
class FilterUidRevisionTest extends NodeTestBase { class FilterUidRevisionTest extends KernelTestBase {
use NodeCreationTrait;
use UserCreationTrait;
use ViewResultAssertionTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'filter',
'node',
'node_test_views',
'system',
'user',
'views',
];
/** /**
* Views used by this test. * Views used by this test.
...@@ -22,16 +43,24 @@ class FilterUidRevisionTest extends NodeTestBase { ...@@ -22,16 +43,24 @@ class FilterUidRevisionTest extends NodeTestBase {
* Tests the node_uid_revision filter. * Tests the node_uid_revision filter.
*/ */
public function testFilter() { public function testFilter() {
$author = $this->drupalCreateUser(); $this->installEntitySchema('user');
$no_author = $this->drupalCreateUser(); $this->installEntitySchema('node');
$this->installEntitySchema('view');
$this->installSchema('system', ['sequences']);
$this->installSchema('node', ['node_access']);
$this->installConfig(['filter']);
ViewTestData::createTestViews(static::class, ['node_test_views']);
$author = $this->createUser();
$no_author = $this->createUser();
$expected_result = []; $expected_result = [];
// Create one node, with the author as the node author. // Create one node, with the author as the node author.
$node = $this->drupalCreateNode(['uid' => $author->id()]); $node = $this->createNode(['uid' => $author->id()]);
$expected_result[] = ['nid' => $node->id()]; $expected_result[] = ['nid' => $node->id()];
// Create one node of which an additional revision author will be the // Create one node of which an additional revision author will be the
// author. // author.
$node = $this->drupalCreateNode(['revision_uid' => $no_author->id()]); $node = $this->createNode(['revision_uid' => $no_author->id()]);
$expected_result[] = ['nid' => $node->id()]; $expected_result[] = ['nid' => $node->id()];
$revision = clone $node; $revision = clone $node;
// Force to add a new revision. // Force to add a new revision.
...@@ -41,13 +70,13 @@ public function testFilter() { ...@@ -41,13 +70,13 @@ public function testFilter() {
// Create one node on which the author has neither authorship of revisions // Create one node on which the author has neither authorship of revisions
// or the main node. // or the main node.
$this->drupalCreateNode(['uid' => $no_author->id()]); $this->createNode(['uid' => $no_author->id()]);
$view = Views::getView('test_filter_node_uid_revision'); $view = Views::getView('test_filter_node_uid_revision');
$view->initHandlers(); $view->initHandlers();
$view->filter['uid_revision']->value = [$author->id()]; $view->filter['uid_revision']->value = [$author->id()];
$this->executeView($view); $view->preview();
$this->assertIdenticalResultset($view, $expected_result, ['nid' => 'nid'], 'Make sure that the view only returns nodes which match either the node or the revision author.'); $this->assertIdenticalResultset($view, $expected_result, ['nid' => 'nid'], 'Make sure that the view only returns nodes which match either the node or the revision author.');
} }
......
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