function ArgumentUidRevisionTest::testArgument

Same name in other branches
  1. 8.9.x core/modules/node/tests/src/Kernel/Views/ArgumentUidRevisionTest.php \Drupal\Tests\node\Kernel\Views\ArgumentUidRevisionTest::testArgument()
  2. 10 core/modules/node/tests/src/Kernel/Views/ArgumentUidRevisionTest.php \Drupal\Tests\node\Kernel\Views\ArgumentUidRevisionTest::testArgument()
  3. 11.x core/modules/node/tests/src/Kernel/Views/ArgumentUidRevisionTest.php \Drupal\Tests\node\Kernel\Views\ArgumentUidRevisionTest::testArgument()

Tests the node_uid_revision argument.

File

core/modules/node/tests/src/Kernel/Views/ArgumentUidRevisionTest.php, line 52

Class

ArgumentUidRevisionTest
Tests the argument_node_uid_revision handler.

Namespace

Drupal\Tests\node\Kernel\Views

Code

public function testArgument() {
    $expected_result = [];
    $author = $this->createUser();
    $no_author = $this->createUser();
    // Create one node, with the author as the node author.
    $node1 = Node::create([
        'type' => 'default',
        'title' => $this->randomMachineName(),
    ]);
    $node1->setOwner($author);
    $node1->save();
    $expected_result[] = [
        'nid' => $node1->id(),
    ];
    // Create one node of which an additional revision author will be the
    // author.
    $node2 = Node::create([
        'type' => 'default',
        'title' => $this->randomMachineName(),
    ]);
    $node2->setRevisionUserId($no_author->id());
    $node2->save();
    $expected_result[] = [
        'nid' => $node2->id(),
    ];
    // Force to add a new revision.
    $node2->setNewRevision(TRUE);
    $node2->setRevisionUserId($author->id());
    $node2->save();
    // Create one  node on which the author has neither authorship of revisions
    // or the main node.
    $node3 = Node::create([
        'type' => 'default',
        'title' => $this->randomMachineName(),
    ]);
    $node3->setOwner($no_author);
    $node3->save();
    $view = Views::getView('test_argument_node_uid_revision');
    $view->initHandlers();
    $view->setArguments([
        'uid_revision' => $author->id(),
    ]);
    $this->executeView($view);
    $this->assertIdenticalResultset($view, $expected_result, [
        'nid' => 'nid',
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.