Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / node / tests / src / Kernel / Views / ArgumentUidRevisionTest.php
1 <?php
2
3 namespace Drupal\Tests\node\Kernel\Views;
4
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;
10
11 /**
12  * Tests the argument_node_uid_revision handler.
13  *
14  * @group node
15  */
16 class ArgumentUidRevisionTest extends ViewsKernelTestBase {
17   use UserCreationTrait;
18
19   /**
20    * {@inheritdoc}
21    */
22   public static $modules = ['node', 'field', 'text', 'user', 'node_test_views'];
23
24   /**
25    * {@inheritdoc}
26    */
27   public static $testViews = ['test_argument_node_uid_revision'];
28
29   /**
30    * {@inheritdoc}
31    */
32   protected function setUp($import_test_views = TRUE) {
33     parent::setUp($import_test_views);
34
35     $this->installEntitySchema('node');
36     $this->installSchema('node', ['node_access']);
37     $this->installEntitySchema('user');
38     $this->installConfig(['node', 'field']);
39
40     ViewTestData::createTestViews(get_class($this), ['node_test_views']);
41   }
42
43   /**
44    * Tests the node_uid_revision argument.
45    */
46   public function testArgument() {
47     $expected_result = [];
48
49     $author = $this->createUser();
50     $no_author = $this->createUser();
51
52     // Create one node, with the author as the node author.
53     $node1 = Node::create([
54       'type' => 'default',
55       'title' => $this->randomMachineName(),
56     ]);
57     $node1->setOwner($author);
58     $node1->save();
59     $expected_result[] = ['nid' => $node1->id()];
60
61     // Create one node of which an additional revision author will be the
62     // author.
63     $node2 = Node::create([
64       'type' => 'default',
65       'title' => $this->randomMachineName(),
66     ]);
67     $node2->setRevisionAuthorId($no_author->id());
68     $node2->save();
69     $expected_result[] = ['nid' => $node2->id()];
70
71     // Force to add a new revision.
72     $node2->setNewRevision(TRUE);
73     $node2->setRevisionAuthorId($author->id());
74     $node2->save();
75
76     // Create one  node on which the author has neither authorship of revisions
77     // or the main node.
78     $node3 = Node::create([
79       'type' => 'default',
80       'title' => $this->randomMachineName(),
81     ]);
82     $node3->setOwner($no_author);
83     $node3->save();
84
85     $view = Views::getView('test_argument_node_uid_revision');
86     $view->initHandlers();
87     $view->setArguments(['uid_revision' => $author->id()]);
88
89     $this->executeView($view);
90     $this->assertIdenticalResultset($view, $expected_result, ['nid' => 'nid']);
91   }
92
93 }