SqlEntityLoadingTest.php in Drupal 9
File
core/modules/views/tests/src/Kernel/Plugin/SqlEntityLoadingTest.php
View source
<?php
namespace Drupal\Tests\views\Kernel\Plugin;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Views;
class SqlEntityLoadingTest extends ViewsKernelTestBase {
protected static $modules = [
'node',
'user',
];
public static $testViews = [
'base_and_revision',
];
protected function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
$this
->installEntitySchema('node');
$this
->installEntitySchema('user');
$this
->installSchema('node', 'node_access');
}
public function testViewWithNonDefaultPendingRevision() {
$node_type = NodeType::create([
'type' => 'page',
]);
$node_type
->save();
$node = Node::create([
'type' => 'page',
'title' => 'test title',
]);
$node
->save();
$revision = clone $node;
$revision
->setNewRevision(TRUE);
$revision
->isDefaultRevision(TRUE);
$revision
->save();
$revision2 = clone $node;
$revision2
->setNewRevision(TRUE);
$revision2
->isDefaultRevision(FALSE);
$revision2
->save();
$view = Views::getView('base_and_revision');
$view
->execute();
$expected = [
[
'nid' => $node
->id(),
'vid_1' => $revision
->getRevisionId(),
'vid' => $revision2
->getRevisionId(),
],
];
$this
->assertIdenticalResultset($view, $expected, [
'node_field_data_node_field_revision_nid' => 'nid',
'vid_1' => 'vid_1',
'vid' => 'vid',
]);
}
}