function EntityNormalizerTest::testDenormalizeWithNoFieldableEntityType

Same name and namespace in other branches
  1. 10 core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\EntityNormalizerTest::testDenormalizeWithNoFieldableEntityType()
  2. 9 core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\EntityNormalizerTest::testDenormalizeWithNoFieldableEntityType()
  3. 8.9.x core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\EntityNormalizerTest::testDenormalizeWithNoFieldableEntityType()
  4. main core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\EntityNormalizerTest::testDenormalizeWithNoFieldableEntityType()

Tests the denormalize method with no bundle defined.

File

core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php, line 379

Class

EntityNormalizerTest
Tests Drupal\serialization\Normalizer\EntityNormalizer.

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

public function testDenormalizeWithNoFieldableEntityType() : void {
  $test_data = [
    'key_1' => 'value_1',
    'key_2' => 'value_2',
  ];
  $entity_type = $this->createMock('Drupal\\Core\\Entity\\EntityTypeInterface');
  $entity_type->expects($this->once())
    ->method('entityClassImplements')
    ->with(FieldableEntityInterface::class)
    ->willReturn(FALSE);
  $entity_type->expects($this->never())
    ->method('getKey');
  $this->entityTypeManager
    ->expects($this->once())
    ->method('getDefinition')
    ->with('test')
    ->willReturn($entity_type);
  $storage = $this->createMock('Drupal\\Core\\Entity\\EntityStorageInterface');
  $storage->expects($this->once())
    ->method('create')
    ->with($test_data)
    ->willReturn($this->createMock(ContentEntityBaseMockableClass::class));
  $this->entityTypeManager
    ->expects($this->once())
    ->method('getStorage')
    ->with('test')
    ->willReturn($storage);
  $this->entityFieldManager
    ->expects($this->never())
    ->method('getBaseFieldDefinitions');
  $this->assertNotNull($this->entityNormalizer
    ->denormalize($test_data, ContentEntityBaseMockableClass::class, NULL, [
    'entity_type' => 'test',
  ]));
}

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