function SqlEntityLoadingTest::testViewWithNonDefaultPendingRevision

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/Plugin/SqlEntityLoadingTest.php \Drupal\Tests\views\Kernel\Plugin\SqlEntityLoadingTest::testViewWithNonDefaultPendingRevision()
  2. 8.9.x core/modules/views/tests/src/Kernel/Plugin/SqlEntityLoadingTest.php \Drupal\Tests\views\Kernel\Plugin\SqlEntityLoadingTest::testViewWithNonDefaultPendingRevision()
  3. 10 core/modules/views/tests/src/Kernel/Plugin/SqlEntityLoadingTest.php \Drupal\Tests\views\Kernel\Plugin\SqlEntityLoadingTest::testViewWithNonDefaultPendingRevision()

File

core/modules/views/tests/src/Kernel/Plugin/SqlEntityLoadingTest.php, line 42

Class

SqlEntityLoadingTest
Tests the loading of entities and entity revisions.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testViewWithNonDefaultPendingRevision() : void {
    $node_type = NodeType::create([
        'type' => 'page',
        'name' => 'Page',
    ]);
    $node_type->save();
    $node = Node::create([
        'type' => 'page',
        'title' => 'test title',
    ]);
    $node->save();
    // Creates the first revision, which is set as default.
    $revision = clone $node;
    $revision->setNewRevision(TRUE);
    $revision->isDefaultRevision(TRUE);
    $revision->save();
    // Creates the second revision, which is not set as default.
    $revision2 = clone $node;
    $revision2->setNewRevision(TRUE);
    $revision2->isDefaultRevision(FALSE);
    $revision2->save();
    $view = Views::getView('base_and_revision');
    $view->execute();
    $expected = [
        [
            'nid' => $node->id(),
            // The default revision ID.
'vid_1' => $revision->getRevisionId(),
            // The latest revision ID.
'vid' => $revision2->getRevisionId(),
        ],
    ];
    $this->assertIdenticalResultset($view, $expected, [
        'node_field_data_node_field_revision_nid' => 'nid',
        'vid_1' => 'vid_1',
        'vid' => 'vid',
    ]);
}

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