function EntityRevisionsTest::testLoadedRevisionIdWithNoNewRevision

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionsTest.php \Drupal\KernelTests\Core\Entity\EntityRevisionsTest::testLoadedRevisionIdWithNoNewRevision()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionsTest.php \Drupal\KernelTests\Core\Entity\EntityRevisionsTest::testLoadedRevisionIdWithNoNewRevision()
  3. 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityRevisionsTest.php \Drupal\KernelTests\Core\Entity\EntityRevisionsTest::testLoadedRevisionIdWithNoNewRevision()

Tests the loaded revision ID after an entity re-save, clone and duplicate.

File

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

Class

EntityRevisionsTest
Tests the loaded Revision of an entity.

Namespace

Drupal\KernelTests\Core\Entity

Code

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');
    // The revision id and loaded Revision id should still be the same.
    $this->assertEquals($loaded->getRevisionId(), $loaded->getLoadedRevisionId());
    $loaded->save();
    // After saving, the loaded Revision id set in entity_test_entity_update()
    // 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.
    $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.
    $clone = clone $loaded;
    $this->assertSame($loaded->getLoadedRevisionId(), $clone->getLoadedRevisionId());
    // Creating a duplicate should set a NULL loaded Revision ID.
    $duplicate = $loaded->createDuplicate();
    $this->assertSame(NULL, $duplicate->getLoadedRevisionId());
}

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