diff -u b/core/modules/system/lib/Drupal/system/Tests/Serialization/EntitySerializationTest.php b/core/modules/system/lib/Drupal/system/Tests/Serialization/EntitySerializationTest.php
--- b/core/modules/system/lib/Drupal/system/Tests/Serialization/EntitySerializationTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Serialization/EntitySerializationTest.php
@@ -10,7 +10,6 @@
use Drupal\simpletest\WebTestBase;
use Symfony\Component\Serializer\Serializer;
use Drupal\Core\Serialization\JsonEncoder;
-use Symfony\Component\Serializer\Encoder\XmlEncoder as BaseXmlEncoder;
use Drupal\Core\Serialization\ComplexDataNormalizer;
use Drupal\Core\Serialization\TypedDataNormalizer;
@@ -130,12 +129,33 @@
$actual = $serializer->serialize($normalized, 'ajax');
$this->assertIdentical($actual, $expected, 'A normalized array serializes to JSON when "ajax" is requested');
- // Test 'xml'. The expected output should match that of Symfony's XmlEncoder.
- $expected ='
-11' . $this->entity->uuid() . 'und' . $this->values['name'] . '1' . $this->values['field_test_text']['value'] . 'full_html
-';
+
+ // Generate the expected xml in a way that allows changes to entity property
+ // order.
+ $expected = array(
+ 'id' => '' . $this->entity->id() . '',
+ 'revision_id' => '' . $this->entity->getRevisionId() . '',
+ 'uuid' => '' . $this->entity->uuid() . '',
+ 'langcode' => '' . LANGUAGE_NOT_SPECIFIED . '',
+ 'default_langcode' => '',
+ 'name' => '' . $this->values['name'] . '',
+ 'user_id' => '' . $this->values['user_id'] . '',
+ 'field_test_text' => '' . $this->values['field_test_text']['value'] . '' . $this->values['field_test_text']['format'] . '',
+ );
+ // Sort it in the same order as normalised.
+ $expected = array_merge(array_flip(array_keys($normalized)), $expected);
+ // Add header and footer.
+ array_unshift($expected, '' . PHP_EOL . '');
+ $expected[] = '' . PHP_EOL;
+ // Reduced the array to a string.
+ $expected = array_reduce($expected, function($result, $item) {
+ $result .= $item;
+ return $result;
+ });
+
+ // Test 'xml'. The output should match that of Symfony's XmlEncoder.
$actual = $serializer->serialize($this->entity, 'xml');
- $this->assertIdentical($actual, $expected, 'Entity serializes to XML when "xml" is requested.');
+ $this->assertIdentical($actual, $expected);
$actual = $serializer->serialize($normalized, 'xml');
- $this->assertIdentical($actual, $expected, 'A normalized array serializes to XML when "xml" is requested');
+ $this->assertIdentical($actual, $expected);
}
}