public function EntityRevisionsTest::testIsLatestRevision in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionsTest.php \Drupal\KernelTests\Core\Entity\EntityRevisionsTest::testIsLatestRevision()
- 10 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\EntityCode
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());
}