Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / serialization / tests / src / Unit / Normalizer / EntityReferenceFieldItemNormalizerTest.php
index c2c62210defd384af29a32bc5264e55d657f198c..5cc6467e8b6e2d3714ea79bf45ea4c63a4986186 100644 (file)
@@ -23,6 +23,8 @@ use Symfony\Component\Serializer\Serializer;
  */
 class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
 
+  use InternalTypedDataTestTrait;
+
   /**
    * The mock serializer.
    *
@@ -68,7 +70,7 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
     $this->serializer = $this->prophesize(Serializer::class);
     // Set up the serializer to return an entity property.
     $this->serializer->normalize(Argument::cetera())
-      ->willReturn(['value' => 'test']);
+      ->willReturn('test');
 
     $this->normalizer->setSerializer($this->serializer->reveal());
 
@@ -122,10 +124,14 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
       ->willReturn($entity_reference)
       ->shouldBeCalled();
 
+    $this->fieldItem->getProperties(TRUE)
+      ->willReturn(['target_id' => $this->getTypedDataProperty(FALSE)])
+      ->shouldBeCalled();
+
     $normalized = $this->normalizer->normalize($this->fieldItem->reveal());
 
     $expected = [
-      'target_id' => ['value' => 'test'],
+      'target_id' => 'test',
       'target_type' => 'test_type',
       'target_uuid' => '080e3add-f9d5-41ac-9821-eea55b7b42fb',
       'url' => $test_url,
@@ -146,10 +152,14 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
       ->willReturn($entity_reference->reveal())
       ->shouldBeCalled();
 
+    $this->fieldItem->getProperties(TRUE)
+      ->willReturn(['target_id' => $this->getTypedDataProperty(FALSE)])
+      ->shouldBeCalled();
+
     $normalized = $this->normalizer->normalize($this->fieldItem->reveal());
 
     $expected = [
-      'target_id' => ['value' => 'test'],
+      'target_id' => 'test',
     ];
     $this->assertSame($expected, $normalized);
   }
@@ -159,7 +169,7 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
    */
   public function testDenormalizeWithTypeAndUuid() {
     $data = [
-      'target_id' => ['value' => 'test'],
+      'target_id' => 'test',
       'target_type' => 'test_type',
       'target_uuid' => '080e3add-f9d5-41ac-9821-eea55b7b42fb',
     ];
@@ -183,7 +193,7 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
    */
   public function testDenormalizeWithUuidWithoutType() {
     $data = [
-      'target_id' => ['value' => 'test'],
+      'target_id' => 'test',
       'target_uuid' => '080e3add-f9d5-41ac-9821-eea55b7b42fb',
     ];
 
@@ -208,7 +218,7 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
     $this->setExpectedException(UnexpectedValueException::class, 'The field "field_reference" property "target_type" must be set to "test_type" or omitted.');
 
     $data = [
-      'target_id' => ['value' => 'test'],
+      'target_id' => 'test',
       'target_type' => 'wrong_type',
       'target_uuid' => '080e3add-f9d5-41ac-9821-eea55b7b42fb',
     ];
@@ -228,7 +238,7 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
     $this->setExpectedException(InvalidArgumentException::class, 'No "test_type" entity found with UUID "unique-but-none-non-existent" for field "field_reference"');
 
     $data = [
-      'target_id' => ['value' => 'test'],
+      'target_id' => 'test',
       'target_type' => 'test_type',
       'target_uuid' => 'unique-but-none-non-existent',
     ];
@@ -251,7 +261,7 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
     $this->setExpectedException(InvalidArgumentException::class, 'If provided "target_uuid" cannot be empty for field "test_type".');
 
     $data = [
-      'target_id' => ['value' => 'test'],
+      'target_id' => 'test',
       'target_type' => 'test_type',
       'target_uuid' => '',
     ];
@@ -268,7 +278,7 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
    */
   public function testDenormalizeWithId() {
     $data = [
-      'target_id' => ['value' => 'test'],
+      'target_id' => 'test',
     ];
     $this->fieldItem->setValue($data)->shouldBeCalled();