You are here

public function EntitySerializationTest::testNormalize in Zircon Profile 8

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

Test the normalize function.

File

core/modules/serialization/src/Tests/EntitySerializationTest.php, line 95
Contains \Drupal\serialization\Tests\EntitySerializationTest.

Class

EntitySerializationTest
Tests that entities can be serialized to supported core formats.

Namespace

Drupal\serialization\Tests

Code

public function testNormalize() {
  $expected = array(
    'id' => array(
      array(
        'value' => 1,
      ),
    ),
    'uuid' => array(
      array(
        'value' => $this->entity
          ->uuid(),
      ),
    ),
    'langcode' => array(
      array(
        'value' => 'en',
      ),
    ),
    'name' => array(
      array(
        'value' => $this->values['name'],
      ),
    ),
    'type' => array(
      array(
        'value' => 'entity_test_mulrev',
      ),
    ),
    'created' => array(
      array(
        'value' => $this->entity->created->value,
      ),
    ),
    'user_id' => array(
      array(
        'target_id' => $this->user
          ->id(),
        'url' => $this->user
          ->url(),
      ),
    ),
    'revision_id' => array(
      array(
        'value' => 1,
      ),
    ),
    'default_langcode' => array(
      array(
        'value' => TRUE,
      ),
    ),
    'field_test_text' => array(
      array(
        'value' => $this->values['field_test_text']['value'],
        'format' => $this->values['field_test_text']['format'],
      ),
    ),
  );
  $normalized = $this->serializer
    ->normalize($this->entity);
  foreach (array_keys($expected) as $fieldName) {
    $this
      ->assertEqual($expected[$fieldName], $normalized[$fieldName], "ComplexDataNormalizer produces expected array for {$fieldName}.");
  }
  $this
    ->assertEqual(array_diff_key($normalized, $expected), array(), 'No unexpected data is added to the normalized array.');
}