3 namespace Drupal\Tests\node\Kernel\Views;
5 use Drupal\node\Entity\Node;
6 use Drupal\simpletest\UserCreationTrait;
7 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
8 use Drupal\views\Tests\ViewTestData;
9 use Drupal\views\Views;
12 * Tests the argument_node_uid_revision handler.
16 class ArgumentUidRevisionTest extends ViewsKernelTestBase {
17 use UserCreationTrait;
22 public static $modules = ['node', 'field', 'text', 'user', 'node_test_views'];
27 public static $testViews = ['test_argument_node_uid_revision'];
32 protected function setUp($import_test_views = TRUE) {
33 parent::setUp($import_test_views);
35 $this->installEntitySchema('node');
36 $this->installSchema('node', ['node_access']);
37 $this->installEntitySchema('user');
38 $this->installConfig(['node', 'field']);
40 ViewTestData::createTestViews(get_class($this), ['node_test_views']);
44 * Tests the node_uid_revision argument.
46 public function testArgument() {
47 $expected_result = [];
49 $author = $this->createUser();
50 $no_author = $this->createUser();
52 // Create one node, with the author as the node author.
53 $node1 = Node::create([
55 'title' => $this->randomMachineName(),
57 $node1->setOwner($author);
59 $expected_result[] = ['nid' => $node1->id()];
61 // Create one node of which an additional revision author will be the
63 $node2 = Node::create([
65 'title' => $this->randomMachineName(),
67 $node2->setRevisionAuthorId($no_author->id());
69 $expected_result[] = ['nid' => $node2->id()];
71 // Force to add a new revision.
72 $node2->setNewRevision(TRUE);
73 $node2->setRevisionAuthorId($author->id());
76 // Create one node on which the author has neither authorship of revisions
78 $node3 = Node::create([
80 'title' => $this->randomMachineName(),
82 $node3->setOwner($no_author);
85 $view = Views::getView('test_argument_node_uid_revision');
86 $view->initHandlers();
87 $view->setArguments(['uid_revision' => $author->id()]);
89 $this->executeView($view);
90 $this->assertIdenticalResultset($view, $expected_result, ['nid' => 'nid']);