function EntityNormalizerTest::testDenormalizeWithInvalidBundle
Same name in other branches
- 8.9.x core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\EntityNormalizerTest::testDenormalizeWithInvalidBundle()
- 10 core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\EntityNormalizerTest::testDenormalizeWithInvalidBundle()
- 11.x core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\EntityNormalizerTest::testDenormalizeWithInvalidBundle()
Tests the denormalize method with a bundle property.
@covers ::denormalize
File
-
core/
modules/ serialization/ tests/ src/ Unit/ Normalizer/ EntityNormalizerTest.php, line 239
Class
- EntityNormalizerTest
- @coversDefaultClass \Drupal\serialization\Normalizer\EntityNormalizer @group serialization
Namespace
Drupal\Tests\serialization\Unit\NormalizerCode
public function testDenormalizeWithInvalidBundle() {
$test_data = [
'key_1' => 'value_1',
'key_2' => 'value_2',
'test_type' => [
[
'name' => 'test_bundle',
],
],
];
$entity_type = $this->createMock('Drupal\\Core\\Entity\\EntityTypeInterface');
$entity_type->expects($this->once())
->method('id')
->willReturn('test');
$entity_type->expects($this->once())
->method('hasKey')
->with('bundle')
->willReturn(TRUE);
$entity_type->expects($this->once())
->method('getKey')
->with('bundle')
->willReturn('test_type');
$entity_type->expects($this->once())
->method('entityClassImplements')
->with(FieldableEntityInterface::class)
->willReturn(TRUE);
$entity_type->expects($this->once())
->method('getBundleEntityType')
->willReturn('test_bundle');
$entity_type_storage_definition = $this->createMock('Drupal\\Core\\Field\\FieldStorageDefinitionInterface');
$entity_type_storage_definition->expects($this->once())
->method('getMainPropertyName')
->willReturn('name');
$entity_type_definition = $this->createMock('Drupal\\Core\\Field\\FieldDefinitionInterface');
$entity_type_definition->expects($this->once())
->method('getFieldStorageDefinition')
->willReturn($entity_type_storage_definition);
$base_definitions = [
'test_type' => $entity_type_definition,
];
$this->entityTypeManager
->expects($this->once())
->method('getDefinition')
->with('test')
->willReturn($entity_type);
$this->entityFieldManager
->expects($this->once())
->method('getBaseFieldDefinitions')
->with('test')
->willReturn($base_definitions);
$entity_query_mock = $this->createMock('Drupal\\Core\\Entity\\Query\\QueryInterface');
$entity_query_mock->expects($this->once())
->method('execute')
->willReturn([
'test_bundle_other' => 'test_bundle_other',
]);
$entity_type_storage = $this->createMock('Drupal\\Core\\Entity\\EntityStorageInterface');
$entity_type_storage->expects($this->once())
->method('getQuery')
->willReturn($entity_query_mock);
$this->entityTypeManager
->expects($this->once())
->method('getStorage')
->with('test_bundle')
->willReturn($entity_type_storage);
$this->expectException(UnexpectedValueException::class);
$this->entityNormalizer
->denormalize($test_data, 'Drupal\\Core\\Entity\\ContentEntityBase', NULL, [
'entity_type' => 'test',
]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.