function FilterUidRevisionTest::testFilter

Same name and namespace in other branches
  1. 9 core/modules/node/tests/src/Kernel/Views/FilterUidRevisionTest.php \Drupal\Tests\node\Kernel\Views\FilterUidRevisionTest::testFilter()
  2. 8.9.x core/modules/node/tests/src/Kernel/Views/FilterUidRevisionTest.php \Drupal\Tests\node\Kernel\Views\FilterUidRevisionTest::testFilter()
  3. 11.x core/modules/node/tests/src/Kernel/Views/FilterUidRevisionTest.php \Drupal\Tests\node\Kernel\Views\FilterUidRevisionTest::testFilter()

Tests the node_uid_revision filter.

File

core/modules/node/tests/src/Kernel/Views/FilterUidRevisionTest.php, line 47

Class

FilterUidRevisionTest
Tests the node_uid_revision handler.

Namespace

Drupal\Tests\node\Kernel\Views

Code

public function testFilter() : void {
  $this->installEntitySchema('user');
  $this->installEntitySchema('node');
  $this->installSchema('node', [
    'node_access',
  ]);
  $this->installConfig([
    'filter',
  ]);
  ViewTestData::createTestViews(static::class, [
    'node_test_views',
  ]);
  $author = $this->createUser();
  $no_author = $this->createUser();
  $expected_result = [];
  // Create one node, with the author as the node author.
  $node = $this->createNode([
    'uid' => $author->id(),
  ]);
  $expected_result[] = [
    'nid' => $node->id(),
  ];
  // Create one node of which an additional revision author will be the
  // author.
  $node = $this->createNode([
    'revision_uid' => $no_author->id(),
  ]);
  $expected_result[] = [
    'nid' => $node->id(),
  ];
  $revision = clone $node;
  // Force to add a new revision.
  $revision->set('vid', NULL);
  $revision->set('revision_uid', $author->id());
  $revision->save();
  // Create one  node on which the author has neither authorship of revisions
  // or the main node.
  $this->createNode([
    'uid' => $no_author->id(),
  ]);
  $view = Views::getView('test_filter_node_uid_revision');
  $view->initHandlers();
  $view->filter['uid_revision']->value = [
    $author->id(),
  ];
  $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.');
}

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