diff --git a/core/modules/serialization/lib/Drupal/serialization/Normalizer/EntityReferenceItemNormalizer.php b/core/modules/serialization/lib/Drupal/serialization/Normalizer/EntityReferenceItemNormalizer.php index f921b19..c2f021c 100644 --- a/core/modules/serialization/lib/Drupal/serialization/Normalizer/EntityReferenceItemNormalizer.php +++ b/core/modules/serialization/lib/Drupal/serialization/Normalizer/EntityReferenceItemNormalizer.php @@ -33,6 +33,7 @@ public function normalize($object, $format = NULL, array $context = array()) { if ($target_entity = $object->entity) { $attributes['target_uuid'] = $target_entity->uuid(); } + return $attributes; } diff --git a/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.php b/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.php index c8a4862..bde69ed 100644 --- a/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.php +++ b/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.php @@ -19,6 +19,8 @@ */ class EntitySerializationTest extends NormalizerTestBase { + public static $modules = array('user'); + /** * The test values. * @@ -51,10 +53,18 @@ public static function getInfo() { protected function setUp() { parent::setUp(); + $this->installSchema('user', array('users', 'users_roles')); + $this->installSchema('system', array('sequences')); + + $this->user = $this->container->get('entity.manager')->getStorageController('user')->create(array( + 'name' => $this->randomName(), + )); + $this->user->save(); + // Create a test entity to serialize. $this->values = array( 'name' => $this->randomName(), - 'user_id' => $GLOBALS['user']->id(), + 'user_id' => $this->user->id(), 'field_test_text' => array( 'value' => $this->randomName(), 'format' => 'full_html', @@ -95,7 +105,10 @@ public function testNormalize() { array('value' => 'entity_test_mulrev'), ), 'user_id' => array( - array('target_id' => $this->values['user_id']), + array( + 'target_id' => $this->user->id(), + 'target_uuid' => $this->user->uuid(), + ), ), 'field_test_text' => array( array( @@ -108,7 +121,7 @@ public function testNormalize() { $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($expected[$fieldName], $normalized[$fieldName]); } $this->assertEqual(array_diff_key($normalized, $expected), array(), 'No unexpected data is added to the normalized array.'); } @@ -143,7 +156,7 @@ public function testSerialize() { 'default_langcode' => '', 'name' => '' . $this->values['name'] . '', 'type' => 'entity_test_mulrev', - 'user_id' => '' . $this->values['user_id'] . '', + 'user_id' => '' . $this->user->id() . '' . $this->user->uuid() . '', 'field_test_text' => '' . $this->values['field_test_text']['value'] . '' . $this->values['field_test_text']['format'] . '', ); // Sort it in the same order as normalised.