You are here

public function RevisionUidTest::testRevisionUid in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/node/tests/src/Kernel/Views/RevisionUidTest.php \Drupal\Tests\node\Kernel\Views\RevisionUidTest::testRevisionUid()
  2. 10 core/modules/node/tests/src/Kernel/Views/RevisionUidTest.php \Drupal\Tests\node\Kernel\Views\RevisionUidTest::testRevisionUid()

Tests the node_revision_uid relationship.

File

core/modules/node/tests/src/Kernel/Views/RevisionUidTest.php, line 71

Class

RevisionUidTest
Tests the node_revision_uid field.

Namespace

Drupal\Tests\node\Kernel\Views

Code

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);
}