You are here

public function ContentEntityNormalizerTest::testNormalize in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/serialization/tests/src/Unit/Normalizer/ContentEntityNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ContentEntityNormalizerTest::testNormalize()
  2. 9 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 66

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 = [
    'field_accessible_external' => $this
      ->createMockFieldListItem(TRUE, FALSE),
    'field_non-accessible_external' => $this
      ->createMockFieldListItem(FALSE, FALSE),
    'field_accessible_internal' => $this
      ->createMockFieldListItem(TRUE, TRUE),
    'field_non-accessible_internal' => $this
      ->createMockFieldListItem(FALSE, TRUE),
  ];
  $content_entity_mock = $this
    ->createMockForContentEntity($definitions);
  $normalized = $this->contentEntityNormalizer
    ->normalize($content_entity_mock, 'test_format');
  $this
    ->assertArrayHasKey('field_accessible_external', $normalized);
  $this
    ->assertEquals('test', $normalized['field_accessible_external']);
  $this
    ->assertArrayNotHasKey('field_non-accessible_external', $normalized);
  $this
    ->assertArrayNotHasKey('field_accessible_internal', $normalized);
  $this
    ->assertArrayNotHasKey('field_non-accessible_internal', $normalized);
}