diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalRevisionTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalRevisionTest.php index 138dbef..1694dad 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalRevisionTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalRevisionTest.php @@ -29,21 +29,49 @@ protected function setUp() { } public function testPreviousProperty() { + // Create a basic EntityTestMulRev entity and save it. $entity = EntityTestMulRev::create(); $entity->save(); + // Load the created entity and create a new revision. $loaded = EntityTestMulRev::load($entity->id()); $loaded->setNewRevision(TRUE); + + // Before saving the original revision ID should be the same as the created + // entity, not the same as the loaded entity (which won't have a revision id + // yet). + $this->assertEquals($entity->getRevisionId(), $loaded->getOriginalRevisionId()); + $this->assertNotEquals($loaded->getRevisionId(), $loaded->getOriginalRevisionId()); + $this->assertTrue($loaded->getRevisionId() === NULL); + $loaded->save(); + // In hook_update the original revision id was stored in state. This should + // be the same as we had before calling $loaded->save(). /** @var \Drupal\Core\Entity\ContentEntityInterface $loaded_original */ $originalRevisionId = \Drupal::state()->get('entity_test.originalRevisionId'); $this->assertEquals($entity->getRevisionId(), $originalRevisionId); $this->assertNotEquals($loaded->getRevisionId(), $originalRevisionId); + // The revision ID and original revision ID should be different for the two + // versions of the entity, but the same for a saved entity. + $this->assertNotEquals($loaded->getRevisionId(), $entity->getRevisionId()); + $this->assertNotEquals($loaded->getOriginalRevisionId(), $entity->getOriginalRevisionId()); + $this->assertEquals($entity->getRevisionId(), $entity->getOriginalRevisionId()); + $this->assertEquals($loaded->getRevisionId(), $loaded->getOriginalRevisionId()); + + // Make a change to the loaded entity. $loaded->set('name', 'dublin'); + + // The revision id and original revision id should still be the same. + $this->assertEquals($loaded->getRevisionId(), $loaded->getOriginalRevisionId()); + $loaded->save(); + + // After saving the original revision id set in hook_update, and returned + // from the entity should be the same and the entity's revision id. $originalRevisionId2 = \Drupal::state()->get('entity_test.originalRevisionId'); $this->assertEquals($loaded->getRevisionId(), $originalRevisionId2); + $this->assertEquals($loaded->getRevisionId(), $loaded->getOriginalRevisionId()); } }