function ContentEntityBaseUnitTest::testTypedData
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php \Drupal\Tests\Core\Entity\ContentEntityBaseUnitTest::testTypedData()
- 11.x core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php \Drupal\Tests\Core\Entity\ContentEntityBaseUnitTest::testTypedData()
Tests each condition in EntityBase::getTypedData().
@covers ::getTypedData @dataProvider providerTestTypedData
File
-
core/
tests/ Drupal/ Tests/ Core/ Entity/ ContentEntityBaseUnitTest.php, line 388
Class
- ContentEntityBaseUnitTest
- @coversDefaultClass \Drupal\Core\Entity\ContentEntityBase @group Entity @group Access
Namespace
Drupal\Tests\Core\EntityCode
public function testTypedData(bool $bundle_typed_data_definition, bool $entity_type_typed_data_definition) : void {
$expected = EntityAdapter::class;
$typedDataManager = $this->createMock(TypedDataManagerInterface::class);
$typedDataManager->expects($this->once())
->method('getDefinition')
->willReturnMap([
[
"entity:{$this->entityTypeId}:{$this->bundle}",
FALSE,
$bundle_typed_data_definition ? [
'class' => $expected,
] : NULL,
],
[
"entity:{$this->entityTypeId}",
FALSE,
$entity_type_typed_data_definition ? [
'class' => $expected,
] : NULL,
],
[
'entity',
TRUE,
[
'class' => $expected,
],
],
]);
// Temporarily replace the appropriate services in the container.
$container = \Drupal::getContainer();
$container->set('typed_data_manager', $typedDataManager);
\Drupal::setContainer($container);
// Create a mock entity used to retrieve typed data.
$entity = $this->getMockBuilder(ContentEntityBaseMockableClass::class)
->setConstructorArgs([
[],
$this->entityTypeId,
$this->bundle,
])
->onlyMethods([
'isNew',
])
->getMock();
// Assert that the returned data type is an instance of EntityAdapter.
$this->assertInstanceOf($expected, $entity->getTypedData());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.