function EntityOriginalDeprecationTest::testOriginalMagicGetSet

Tests deprecation of the original property.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalDeprecationTest.php, line 20

Class

EntityOriginalDeprecationTest
Tests the deprecations of the original property.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testOriginalMagicGetSet() : void {
    $this->expectDeprecation('Setting the original property is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use \\Drupal\\Core\\Entity\\EntityInterface::setOriginal() instead. See https://www.drupal.org/node/3295826');
    $entity = EntityTest::create([
        'name' => 'original is deprecated',
    ]);
    $entity->original = clone $entity;
    $this->assertInstanceOf(EntityTest::class, $entity->getOriginal());
    $this->expectDeprecation('Getting the original property is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use \\Drupal\\Core\\Entity\\EntityInterface::getOriginal() instead. See https://www.drupal.org/node/3295826');
    $entity = EntityTest::create([
        'name' => 'original is deprecated',
    ]);
    $entity->setOriginal(clone $entity);
    $this->assertInstanceOf(EntityTest::class, $entity->original);
    $this->expectDeprecation('Checking for the original property is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use \\Drupal\\Core\\Entity\\EntityInterface::getOriginal() instead. See https://www.drupal.org/node/3295826');
    $entity = EntityTest::create([
        'name' => 'original is deprecated',
    ]);
    $this->assertFalse(isset($entity->original));
    $entity->setOriginal(clone $entity);
    $this->assertTrue(isset($entity->original));
    $this->expectDeprecation('Unsetting the original property is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use \\Drupal\\Core\\Entity\\EntityInterface::setOriginal() instead. See https://www.drupal.org/node/3295826');
    $entity = EntityTest::create([
        'name' => 'original is deprecated',
    ]);
    $entity->setOriginal(clone $entity);
    unset($entity->original);
    $this->assertNull($entity->getOriginal());
}

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