function EntityBaseTest::testGetTypedData

Same name and namespace in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Entity/EntityBaseTest.php \Drupal\KernelTests\Core\Entity\EntityBaseTest::testGetTypedData()
  2. 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityBaseTest.php \Drupal\KernelTests\Core\Entity\EntityBaseTest::testGetTypedData()

Tests that the correct entity adapter is returned.

@covers ::getTypedData @covers ::getClass

File

core/tests/Drupal/KernelTests/Core/Entity/EntityBaseTest.php, line 34

Class

EntityBaseTest
Tests the functionality provided by <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21EntityBase.php/class/EntityBase/9" title="Defines a base entity class." class="local">\Drupal\Core\Entity\EntityBase</a>.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testGetTypedData() {
    $bundle = EntityTestBundle::create([
        'id' => $this->randomMachineName(),
    ]);
    $bundle->save();
    $entity = EntityTestWithBundle::create([
        'type' => $bundle->id(),
        'name' => $this->randomString(),
    ]);
    $entity->save();
    $this->assertInstanceOf(ConfigEntityAdapter::class, $bundle->getTypedData());
    $this->assertInstanceOf(EntityAdapter::class, $entity->getTypedData());
}

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