You are here

public function ContentEntityNormalizerTest::testNormalize in Zircon Profile 8

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

Tests the normalize() method.

@covers ::normalize

File

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

Class

ContentEntityNormalizerTest
@coversDefaultClass \Drupal\serialization\Normalizer\ContentEntityNormalizer @group serialization

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

public function testNormalize() {
  $this->serializer
    ->expects($this
    ->any())
    ->method('normalize')
    ->with($this
    ->containsOnlyInstancesOf('Drupal\\Core\\Field\\FieldItemListInterface'), 'test_format', [
    'account' => NULL,
  ])
    ->will($this
    ->returnValue('test'));
  $definitions = array(
    'field_1' => $this
      ->createMockFieldListItem(),
    'field_2' => $this
      ->createMockFieldListItem(FALSE),
  );
  $content_entity_mock = $this
    ->createMockForContentEntity($definitions);
  $normalized = $this->contentEntityNormalizer
    ->normalize($content_entity_mock, 'test_format');
  $this
    ->assertArrayHasKey('field_1', $normalized);
  $this
    ->assertEquals('test', $normalized['field_1']);
  $this
    ->assertArrayNotHasKey('field_2', $normalized);
}