You are here

public function EntityNormalizerTest::testDenormalizeWithNoBundle in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\EntityNormalizerTest::testDenormalizeWithNoBundle()

Tests the denormalize method with no bundle defined.

@covers ::denormalize

File

core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php, line 259
Contains \Drupal\Tests\serialization\Unit\Normalizer\EntityNormalizerTest.

Class

EntityNormalizerTest
@coversDefaultClass \Drupal\serialization\Normalizer\EntityNormalizer @group serialization

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

public function testDenormalizeWithNoBundle() {
  $test_data = array(
    'key_1' => 'value_1',
    'key_2' => 'value_2',
  );
  $entity_type = $this
    ->getMock('Drupal\\Core\\Entity\\EntityTypeInterface');
  $entity_type
    ->expects($this
    ->once())
    ->method('hasKey')
    ->with('bundle')
    ->will($this
    ->returnValue(FALSE));
  $entity_type
    ->expects($this
    ->never())
    ->method('getKey');
  $this->entityManager
    ->expects($this
    ->once())
    ->method('getDefinition')
    ->with('test')
    ->will($this
    ->returnValue($entity_type));
  $storage = $this
    ->getMock('Drupal\\Core\\Entity\\EntityStorageInterface');
  $storage
    ->expects($this
    ->once())
    ->method('create')
    ->with($test_data)
    ->will($this
    ->returnValue($this
    ->getMock('Drupal\\Core\\Entity\\EntityInterface')));
  $this->entityManager
    ->expects($this
    ->once())
    ->method('getStorage')
    ->with('test')
    ->will($this
    ->returnValue($storage));
  $this->entityManager
    ->expects($this
    ->never())
    ->method('getBaseFieldDefinitions');
  $this
    ->assertNotNull($this->entityNormalizer
    ->denormalize($test_data, 'Drupal\\Core\\Entity\\ContentEntityBase', NULL, array(
    'entity_type' => 'test',
  )));
}