ArgumentUidRevisionTest.php in Drupal 10
File
core/modules/node/tests/src/Kernel/Views/ArgumentUidRevisionTest.php
View source
<?php
namespace Drupal\Tests\node\Kernel\Views;
use Drupal\node\Entity\Node;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
class ArgumentUidRevisionTest extends ViewsKernelTestBase {
use UserCreationTrait;
protected static $modules = [
'node',
'field',
'text',
'user',
'node_test_views',
];
public static $testViews = [
'test_argument_node_uid_revision',
];
protected function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
$this
->installEntitySchema('node');
$this
->installSchema('node', [
'node_access',
]);
$this
->installEntitySchema('user');
$this
->installConfig([
'node',
'field',
]);
ViewTestData::createTestViews(static::class, [
'node_test_views',
]);
}
public function testArgument() {
$expected_result = [];
$author = $this
->createUser();
$no_author = $this
->createUser();
$node1 = Node::create([
'type' => 'default',
'title' => $this
->randomMachineName(),
]);
$node1
->setOwner($author);
$node1
->save();
$expected_result[] = [
'nid' => $node1
->id(),
];
$node2 = Node::create([
'type' => 'default',
'title' => $this
->randomMachineName(),
]);
$node2
->setRevisionUserId($no_author
->id());
$node2
->save();
$expected_result[] = [
'nid' => $node2
->id(),
];
$node2
->setNewRevision(TRUE);
$node2
->setRevisionUserId($author
->id());
$node2
->save();
$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',
]);
}
}