diff --git a/core/lib/Drupal/Core/Serialization/ComplexDataNormalizer.php b/core/lib/Drupal/Core/Serialization/ComplexDataNormalizer.php index d358935..233103f 100644 --- a/core/lib/Drupal/Core/Serialization/ComplexDataNormalizer.php +++ b/core/lib/Drupal/Core/Serialization/ComplexDataNormalizer.php @@ -2,7 +2,7 @@ /** * @file - * Contains Drupal\Core\Serialization\ComplexDataNormalizer. + * Contains \Drupal\Core\Serialization\ComplexDataNormalizer. */ namespace Drupal\Core\Serialization; diff --git a/core/lib/Drupal/Core/Serialization/TypedDataNormalizer.php b/core/lib/Drupal/Core/Serialization/TypedDataNormalizer.php index 8e75c41..0376771 100644 --- a/core/lib/Drupal/Core/Serialization/TypedDataNormalizer.php +++ b/core/lib/Drupal/Core/Serialization/TypedDataNormalizer.php @@ -2,7 +2,7 @@ /** * @file - * Contains Drupal\Core\Serialization\TypedDataNormalizer. + * Contains \Drupal\Core\Serialization\TypedDataNormalizer. */ namespace Drupal\Core\Serialization; diff --git a/core/modules/system/lib/Drupal/system/Tests/Serialization/EntitySerializationTest.php b/core/modules/system/lib/Drupal/system/Tests/Serialization/EntitySerializationTest.php index cc1b76d..6f83441 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Serialization/EntitySerializationTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Serialization/EntitySerializationTest.php @@ -2,13 +2,20 @@ /** * @file - * Definition of Drupal\system\Tests\Serialization\EntitySerializationTest. + * Contains \Drupal\system\Tests\Serialization\EntitySerializationTest. */ namespace Drupal\system\Tests\Serialization; use Drupal\simpletest\WebTestBase; +use Symfony\Component\Serializer\Serializer; +use Drupal\Core\Serialization\JsonEncoder; +use Drupal\Core\Serialization\ComplexDataNormalizer; +use Drupal\Core\Serialization\TypedDataNormalizer; +/** + * Tests entity normalization and serialization of supported core formats. + */ class EntitySerializationTest extends WebTestBase { /** @@ -26,6 +33,13 @@ class EntitySerializationTest extends WebTestBase { protected $values; /** + * The Serializer object. + * + * @var \Symfony\Component\Serializer\Serializer. + */ + protected $serializer; + + /** * The test entity. * * @var \Drupal\Core\Entity\EntityNG @@ -35,13 +49,20 @@ class EntitySerializationTest extends WebTestBase { public static function getInfo() { return array( 'name' => 'Entity serialization tests', - 'description' => 'Tests that entities can be serialized to JSON and XML formats.', + 'description' => 'Tests that entities can be serialized to supported core formats.', 'group' => 'Serialization', ); } protected function setUp() { parent::setUp(); + + // Set up the serializer. + $encoders = array(new JsonEncoder()); + $normalizers = array(new ComplexDataNormalizer(), new TypedDataNormalizer()); + $this->serializer = new Serializer($normalizers, $encoders); + + // Create a test entity to serialize. $this->values = array( 'name' => $this->randomName(), 'user_id' => $GLOBALS['user']->uid, @@ -58,8 +79,6 @@ protected function setUp() { * Test the normalize function. */ public function testNormalize() { - $serializer = drupal_container()->get('serializer'); - $expected = array( 'id' => array( array('value' => 1), @@ -88,7 +107,8 @@ public function testNormalize() { ), ); - $normalized = $serializer->normalize($this->entity); + $normalized = $this->serializer->normalize($this->entity); + foreach (array_keys($expected) as $fieldName) { $this->assertEqual($expected[$fieldName], $normalized[$fieldName], "ComplexDataNormalizer produces expected array for $fieldName."); } @@ -99,18 +119,16 @@ public function testNormalize() { * Test Serializer's entity serialization for core's registered formats. */ public function testSerialize() { - $serializer = drupal_container()->get('serializer'); - // Test that Serializer responds using the ComplexDataNormalizer and // JsonEncoder. The output of ComplexDataNormalizer::normalize() is tested // elsewhere, so we can just assume that it works properly here. - $normalized = $serializer->normalize($this->entity, 'json'); + $normalized = $this->serializer->normalize($this->entity, 'json'); $expected = json_encode($normalized); // Test 'json'. - $actualJson = $serializer->serialize($this->entity, 'json'); - $this->assertIdentical($actualJson, $expected, 'Entity serializes to JSON when json is requested.'); + $actual = $this->serializer->serialize($this->entity, 'json'); + $this->assertIdentical($actual, $expected, 'Entity serializes to JSON when json is requested.'); // Test 'ajax'. - $actualAjax = $serializer->serialize($this->entity, 'ajax'); - $this->assertIdentical($actualAjax, $expected, 'Entity serializes to JSON when ajax is requested.'); + $actual = $this->serializer->serialize($this->entity, 'ajax'); + $this->assertIdentical($actual, $expected, 'Entity serializes to JSON when ajax is requested.'); } }