View source
<?php
namespace Drupal\Tests\node\Kernel\Views;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\views\Tests\ViewResultAssertionTrait;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
class FilterUidRevisionTest extends KernelTestBase {
use NodeCreationTrait;
use UserCreationTrait;
use ViewResultAssertionTrait;
protected static $modules = [
'filter',
'node',
'node_test_views',
'system',
'user',
'views',
];
public static $testViews = [
'test_filter_node_uid_revision',
];
public function testFilter() {
$this
->installEntitySchema('user');
$this
->installEntitySchema('node');
$this
->installEntitySchema('view');
$this
->installSchema('system', [
'sequences',
]);
$this
->installSchema('node', [
'node_access',
]);
$this
->installConfig([
'filter',
]);
ViewTestData::createTestViews(static::class, [
'node_test_views',
]);
$author = $this
->createUser();
$no_author = $this
->createUser();
$expected_result = [];
$node = $this
->createNode([
'uid' => $author
->id(),
]);
$expected_result[] = [
'nid' => $node
->id(),
];
$node = $this
->createNode([
'revision_uid' => $no_author
->id(),
]);
$expected_result[] = [
'nid' => $node
->id(),
];
$revision = clone $node;
$revision
->set('vid', NULL);
$revision
->set('revision_uid', $author
->id());
$revision
->save();
$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.');
}
}