You are here

public function EntityRevisionsTest::testIsLatestRevision in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionsTest.php \Drupal\KernelTests\Core\Entity\EntityRevisionsTest::testIsLatestRevision()
  2. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionsTest.php \Drupal\KernelTests\Core\Entity\EntityRevisionsTest::testIsLatestRevision()

Tests that latest revisions are working as expected.

@covers ::isLatestRevision

File

core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionsTest.php, line 176

Class

EntityRevisionsTest
Tests the loaded Revision of an entity.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testIsLatestRevision() {

  // Create a basic EntityTestMulRev entity and save it.
  $entity = EntityTestMulRev::create();
  $entity
    ->save();
  $this
    ->assertTrue($entity
    ->isLatestRevision());

  // Load the created entity and create a new pending revision.
  $pending_revision = EntityTestMulRev::load($entity
    ->id());
  $pending_revision
    ->setNewRevision(TRUE);
  $pending_revision
    ->isDefaultRevision(FALSE);

  // The pending revision should still be marked as the latest one before it
  // is saved.
  $this
    ->assertTrue($pending_revision
    ->isLatestRevision());
  $pending_revision
    ->save();
  $this
    ->assertTrue($pending_revision
    ->isLatestRevision());

  // Load the default revision and check that it is not marked as the latest
  // revision.
  $default_revision = EntityTestMulRev::load($entity
    ->id());
  $this
    ->assertFalse($default_revision
    ->isLatestRevision());
}