function EntityDuplicateTest::testDuplicateNonDefaultRevision

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

Tests duplicating a non-default revision.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityDuplicateTest.php, line 33

Class

EntityDuplicateTest
Test entity duplication.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testDuplicateNonDefaultRevision() : void {
    $entity = EntityTestRev::create([
        'name' => 'First Revision',
    ]);
    $entity->save();
    $first_revision_id = $entity->getRevisionId();
    $entity->setNewRevision(TRUE);
    $entity->name = 'Second Revision';
    $entity->save();
    $duplicate_first_revision = $this->entityTestRevStorage
        ->loadRevision($first_revision_id)
        ->createDuplicate();
    $this->assertTrue($duplicate_first_revision->isDefaultRevision(), 'Duplicating a non-default revision creates a default revision.');
    $this->assertEquals('First Revision', $duplicate_first_revision->label());
    $duplicate_first_revision->save();
    $duplicate_first_revision->name = 'Updated name';
    $duplicate_first_revision->save();
    $this->entityTestRevStorage
        ->resetCache();
    $duplicate_first_revision = EntityTestRev::load($duplicate_first_revision->id());
    $this->assertEquals('Updated name', $duplicate_first_revision->label());
}

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