From cfbe530a76cbb5c9a15eccde6081d18db7cd665b Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Fri, 22 Feb 2013 11:09:10 +0000 Subject: [PATCH] Issue #1904404 by damiankloip, linclark: Fixed Update EntitySerializationTest to reflect actual Serializer setup. --- .../Tests/EntitySerializationTest.php | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.php b/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.php index c29f5527cf90..976ac582aa90 100644 --- a/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.php +++ b/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.php @@ -10,20 +10,20 @@ use Drupal\serialization\Encoder\JsonEncoder; use Drupal\serialization\Normalizer\ComplexDataNormalizer; use Drupal\serialization\Normalizer\TypedDataNormalizer; -use Drupal\simpletest\WebTestBase; +use Drupal\simpletest\DrupalUnitTestBase; use Symfony\Component\Serializer\Serializer; /** * Tests entity normalization and serialization of supported core formats. */ -class EntitySerializationTest extends WebTestBase { +class EntitySerializationTest extends DrupalUnitTestBase { /** * Modules to enable. * * @var array */ - public static $modules = array('entity_test', 'serialization'); + public static $modules = array('serialization'); /** * The test values. @@ -39,6 +39,13 @@ class EntitySerializationTest extends WebTestBase { */ protected $entity; + /** + * The serializer serivce. + * + * @var \Symfony\Component\Serializer\Serializer. + */ + protected $serializer; + public static function getInfo() { return array( 'name' => 'Entity serialization tests', @@ -50,6 +57,8 @@ public static function getInfo() { protected function setUp() { parent::setUp(); + $this->enableModules(array('system', 'field', 'field_sql_storage', 'text', 'entity_test')); + // Create a test entity to serialize. $this->values = array( 'name' => $this->randomName(), @@ -61,17 +70,14 @@ protected function setUp() { ); $this->entity = entity_create('entity_test_mulrev', $this->values); $this->entity->save(); + + $this->serializer = $this->container->get('serializer'); } /** * Test the normalize function. */ public function testNormalize() { - // Set up the serializer. - $encoders = array(new JsonEncoder()); - $normalizers = array(new ComplexDataNormalizer(), new TypedDataNormalizer()); - $serializer = new Serializer($normalizers, $encoders); - $expected = array( 'id' => array( array('value' => 1), @@ -85,7 +91,9 @@ public function testNormalize() { 'langcode' => array( array('value' => LANGUAGE_NOT_SPECIFIED), ), - 'default_langcode' => array(NULL), + 'default_langcode' => array( + array('value' => NULL), + ), 'name' => array( array('value' => $this->values['name']), ), @@ -100,7 +108,7 @@ 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."); @@ -112,21 +120,20 @@ public function testNormalize() { * Test registered Serializer's entity serialization for core's 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'. - $actual = $serializer->serialize($this->entity, 'json'); + $actual = $this->serializer->serialize($this->entity, 'json'); $this->assertIdentical($actual, $expected, 'Entity serializes to JSON when "json" is requested.'); - $actual = $serializer->serialize($normalized, 'json'); + $actual = $this->serializer->serialize($normalized, 'json'); $this->assertIdentical($actual, $expected, 'A normalized array serializes to JSON when "json" is requested'); // Test 'ajax'. - $actual = $serializer->serialize($this->entity, 'ajax'); + $actual = $this->serializer->serialize($this->entity, 'ajax'); $this->assertIdentical($actual, $expected, 'Entity serializes to JSON when "ajax" is requested.'); - $actual = $serializer->serialize($normalized, 'ajax'); + $actual = $this->serializer->serialize($normalized, 'ajax'); $this->assertIdentical($actual, $expected, 'A normalized array serializes to JSON when "ajax" is requested'); // Generate the expected xml in a way that allows changes to entity property @@ -149,9 +156,9 @@ public function testSerialize() { // Reduced the array to a string. $expected = implode('', $expected); // Test 'xml'. The output should match that of Symfony's XmlEncoder. - $actual = $serializer->serialize($this->entity, 'xml'); + $actual = $this->serializer->serialize($this->entity, 'xml'); $this->assertIdentical($actual, $expected); - $actual = $serializer->serialize($normalized, 'xml'); + $actual = $this->serializer->serialize($normalized, 'xml'); $this->assertIdentical($actual, $expected); } } -- GitLab