*/
class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
+ use InternalTypedDataTestTrait;
+
/**
* The mock serializer.
*
$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());
->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,
->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);
}
*/
public function testDenormalizeWithTypeAndUuid() {
$data = [
- 'target_id' => ['value' => 'test'],
+ 'target_id' => 'test',
'target_type' => 'test_type',
'target_uuid' => '080e3add-f9d5-41ac-9821-eea55b7b42fb',
];
*/
public function testDenormalizeWithUuidWithoutType() {
$data = [
- 'target_id' => ['value' => 'test'],
+ 'target_id' => 'test',
'target_uuid' => '080e3add-f9d5-41ac-9821-eea55b7b42fb',
];
$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',
];
$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',
];
$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' => '',
];
*/
public function testDenormalizeWithId() {
$data = [
- 'target_id' => ['value' => 'test'],
+ 'target_id' => 'test',
];
$this->fieldItem->setValue($data)->shouldBeCalled();