diff --git a/core/modules/system/lib/Drupal/system/Tests/Serialization/EntityNormalizerTest.php b/core/modules/system/lib/Drupal/system/Tests/Serialization/EntityNormalizerTest.php index edaf552..e884335 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Serialization/EntityNormalizerTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Serialization/EntityNormalizerTest.php @@ -9,7 +9,6 @@ use Drupal\Core\Serialization\EntityNormalizer; use Drupal\simpletest\WebTestBase; -use Symfony\Component\Serializer\Exception\UnexpectedValueException; class EntityNormalizerTest extends WebTestBase { @@ -45,42 +44,28 @@ public function testNormalize() { $entity = entity_create('entity_test', $values); $entity->save(); - $expectedArray = array ( - 'id' => array ( - array ( - 'value' => 1, - ), + $expected = array( + 'id' => array( + array('value' => 1), ), - 'revision_id' => array ( - array ( - 'value' => 1, - ), + 'revision_id' => array( + array('value' => 1), ), - 'uuid' => array ( - array ( - 'value' => $entity->uuid(), - ), + 'uuid' => array( + array('value' => $entity->uuid()), ), - 'langcode' => array ( - array ( - 'value' => LANGUAGE_NOT_SPECIFIED, - ), + 'langcode' => array( + array('value' => LANGUAGE_NOT_SPECIFIED), ), - 'default_langcode' => array ( - NULL, + 'default_langcode' => array(NULL), + 'name' => array( + array('value' => $values['name']), ), - 'name' => array ( - array ( - 'value' => $values['name'], - ), + 'user_id' => array( + array('value' => $values['user_id']), ), - 'user_id' => array ( - array ( - 'value' => $values['user_id'], - ), - ), - 'field_test_text' => array ( - array ( + 'field_test_text' => array( + array( 'value' => $values['field_test_text']['value'], 'format' => $values['field_test_text']['format'], ), @@ -88,8 +73,9 @@ public function testNormalize() { ); $normalized = $normalizer->normalize($entity); - //@todo Expand this to check each value individually and then check the - // array keys to ensure no other properties are added. - $this->assertEqual($expectedArray, $normalized, 'Normalized array.'); + $this->assertEqual($expected, $normalized); + + // Test with the serializer. + $serializer = drupal_container()->get('serializer'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Serialization/EntitySerializationTest.php b/core/modules/system/lib/Drupal/system/Tests/Serialization/EntitySerializationTest.php new file mode 100644 index 0000000..cf33531 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Serialization/EntitySerializationTest.php @@ -0,0 +1,63 @@ + 'Entity serialization tests', + 'description' => 'Tests that entities can be serialized to JSON and XML formats.', + 'group' => 'Serialization', + ); + } + + /** + * Tests the normalize function. + */ + public function testSerialize() { + $serializer = drupal_container()->get('serializer'); + $normalizer = new EntityNormalizer(); + + $values = array( + 'name' => $this->randomName(), + 'user_id' => $GLOBALS['user']->uid, + 'field_test_text' => array( + 'value' => $this->randomName(), + 'format' => 'full_html', + ), + ); + $entity = entity_create('entity_test', $values); + $entity->save(); + + // Get a normalized array to use for assertions. + $normalized = $normalizer->normalize($entity); + + // Test the JSON output. + $expected = json_encode($normalized); + $actual = $serializer->serialize($entity, 'json'); + $this->assertIdentical($actual, $expected); + + // Test the XML output. + $xml_encoder = new XmlEncoder(); + $expected = $xml_encoder->encode($normalized, 'xml'); + $actual = $serializer->serialize($entity, 'xml'); + $this->assertIdentical($actual, $expected); + } +}