diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityLoadedRevisionTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityLoadedRevisionTest.php index 26c163a..f4f1d43 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityLoadedRevisionTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityLoadedRevisionTest.php @@ -38,8 +38,6 @@ protected function setUp() { * Test getLoadedRevisionId() returns the correct ID throughout the process. */ public function testLoadedRevisionId() { - ConfigurableLanguage::createFromLangcode('fr')->save(); - // Create a basic EntityTestMulRev entity and save it. $entity = EntityTestMulRev::create(); $entity->save(); @@ -76,6 +74,17 @@ public function testLoadedRevisionId() { $this->assertNotEquals($loaded->getLoadedRevisionId(), $entity->getLoadedRevisionId()); $this->assertEquals($entity->getRevisionId(), $entity->getLoadedRevisionId()); $this->assertEquals($loaded->getRevisionId(), $loaded->getLoadedRevisionId()); + } + + public function testLoadedRevisionIdWithNoNewRevision() { + // 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); + $loaded->save(); // Make a change to the loaded entity. $loaded->set('name', 'dublin'); @@ -89,8 +98,8 @@ public function testLoadedRevisionId() { // and returned from the entity should be the same as the entity's revision // id because a new revision wasn't created, the existing revision was // updated. - $loadedRevisionId2 = \Drupal::state()->get('entity_test.loadedRevisionId'); - $this->assertEquals($loaded->getRevisionId(), $loadedRevisionId2); + $loadedRevisionId = \Drupal::state()->get('entity_test.loadedRevisionId'); + $this->assertEquals($loaded->getRevisionId(), $loadedRevisionId); $this->assertEquals($loaded->getRevisionId(), $loaded->getLoadedRevisionId()); // Creating a clone should keep the loaded Revision ID. @@ -100,6 +109,22 @@ public function testLoadedRevisionId() { // Creating a duplicate should set a NULL loaded Revision ID. $duplicate = $loaded->createDuplicate(); $this->assertSame(NULL, $duplicate->getLoadedRevisionId()); + } + + /** + * Tests the loaded revision ID works on a multilingual site. + */ + public function testTranslatedLoadedRevisionId() { + ConfigurableLanguage::createFromLangcode('fr')->save(); + + // 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); + $loaded->save(); // Check it all works with translations. $french = $loaded->addTranslation('fr'); @@ -125,13 +150,18 @@ public function testLoadedRevisionId() { // Saving the new revision will reset the origin revision ID again. $this->assertEquals($french->getRevisionId(), $french->getLoadedRevisionId()); $this->assertEquals($loaded->getRevisionId(), $loaded->getLoadedRevisionId()); + } + /** + * Test calling save() in entity_test_entity_insert() sets the correct ID. + */ + public function testSaveInHookEntityInsert() { // Create an entity which will be saved again in entity_test_entity_insert(). - $entity2 = EntityTestMulRev::create(['name' => 'EntityLoadedRevisionTest']); - $entity2->save(); - $loadedRevisionId3 = \Drupal::state()->get('entity_test.loadedRevisionId'); - $this->assertEquals($entity2->getLoadedRevisionId(), $loadedRevisionId3); - $this->assertEquals($entity2->getRevisionId(), $entity2->getLoadedRevisionId()); + $entity = EntityTestMulRev::create(['name' => 'EntityLoadedRevisionTest']); + $entity->save(); + $loadedRevisionId = \Drupal::state()->get('entity_test.loadedRevisionId'); + $this->assertEquals($entity->getLoadedRevisionId(), $loadedRevisionId); + $this->assertEquals($entity->getRevisionId(), $entity->getLoadedRevisionId()); } }