class EntityDuplicateTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityDuplicateTest.php \Drupal\KernelTests\Core\Entity\EntityDuplicateTest
Test entity duplication.
@group Entity
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\Entity\EntityKernelTestBase uses \Drupal\Tests\user\Traits\UserCreationTrait implements \Drupal\KernelTests\KernelTestBase
- class \Drupal\KernelTests\Core\Entity\EntityDuplicateTest implements \Drupal\KernelTests\Core\Entity\EntityKernelTestBase
- class \Drupal\KernelTests\Core\Entity\EntityKernelTestBase uses \Drupal\Tests\user\Traits\UserCreationTrait implements \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of EntityDuplicateTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityDuplicateTest.php, line 12
Namespace
Drupal\KernelTests\Core\EntityView source
class EntityDuplicateTest extends EntityKernelTestBase {
/**
* @var \Drupal\Core\Entity\ContentEntityStorageInterface
*/
protected $entityTestRevStorage;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->installEntitySchema('entity_test_rev');
$this->entityTestRevStorage = $this->container
->get('entity_type.manager')
->getStorage('entity_test_rev');
}
/**
* Tests duplicating a non-default revision.
*/
public function testDuplicateNonDefaultRevision() {
$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.