updated core to 8.6.1 via composer
This commit is contained in:
+1
-1
@@ -29,7 +29,7 @@ class TextItemSillyNormalizer extends FieldItemNormalizer {
|
||||
*/
|
||||
protected function constructValue($data, $context) {
|
||||
$value = parent::constructValue($data, $context);
|
||||
$value['value'] = str_replace('::silly_suffix', '', $value['value']);
|
||||
$value['value'] = str_replace('::silly_suffix', '', $value['value']);
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace Drupal\Tests\serialization\Kernel;
|
||||
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\entity_test\Entity\EntityTestMulRev;
|
||||
use Drupal\filter\Entity\FilterFormat;
|
||||
use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
|
||||
@@ -48,7 +48,7 @@ class EntitySerializationTest extends NormalizerTestBase {
|
||||
/**
|
||||
* The serializer service.
|
||||
*
|
||||
* @var \Symfony\Component\Serializer\Serializer.
|
||||
* @var \Symfony\Component\Serializer\Serializer
|
||||
*/
|
||||
protected $serializer;
|
||||
|
||||
@@ -253,7 +253,7 @@ class EntitySerializationTest extends NormalizerTestBase {
|
||||
|
||||
foreach (['json', 'xml'] as $type) {
|
||||
$denormalized = $this->serializer->denormalize($normalized, $this->entityClass, $type, ['entity_type' => 'entity_test_mulrev']);
|
||||
$this->assertTrue($denormalized instanceof $this->entityClass, SafeMarkup::format('Denormalized entity is an instance of @class', ['@class' => $this->entityClass]));
|
||||
$this->assertTrue($denormalized instanceof $this->entityClass, new FormattableMarkup('Denormalized entity is an instance of @class', ['@class' => $this->entityClass]));
|
||||
$this->assertIdentical($denormalized->getEntityTypeId(), $this->entity->getEntityTypeId(), 'Expected entity type found.');
|
||||
$this->assertIdentical($denormalized->bundle(), $this->entity->bundle(), 'Expected entity bundle found.');
|
||||
$this->assertIdentical($denormalized->uuid(), $this->entity->uuid(), 'Expected entity UUID found.');
|
||||
|
||||
@@ -43,7 +43,7 @@ class FieldItemSerializationTest extends NormalizerTestBase {
|
||||
/**
|
||||
* The serializer service.
|
||||
*
|
||||
* @var \Symfony\Component\Serializer\Serializer.
|
||||
* @var \Symfony\Component\Serializer\Serializer
|
||||
*/
|
||||
protected $serializer;
|
||||
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\serialization\Kernel;
|
||||
|
||||
use Drupal\Core\TypedData\DataDefinition;
|
||||
use Drupal\Core\TypedData\MapDataDefinition;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
||||
/**
|
||||
* @group typedData
|
||||
*/
|
||||
class MapDataNormalizerTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['system', 'serialization'];
|
||||
|
||||
/**
|
||||
* The serializer service.
|
||||
*
|
||||
* @var \Symfony\Component\Serializer\Serializer
|
||||
*/
|
||||
protected $serializer;
|
||||
|
||||
/**
|
||||
* The typed data manager.
|
||||
*
|
||||
* @var \Drupal\Core\TypedData\TypedDataManagerInterface
|
||||
*/
|
||||
protected $typedDataManager;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->serializer = \Drupal::service('serializer');
|
||||
$this->typedDataManager = \Drupal::typedDataManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether map data can be normalized.
|
||||
*/
|
||||
public function testMapNormalize() {
|
||||
$typed_data = $this->buildExampleTypedData();
|
||||
$data = $this->serializer->normalize($typed_data, 'json');
|
||||
$expect_value = [
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2',
|
||||
'key3' => 3,
|
||||
'key4' => [
|
||||
0 => TRUE,
|
||||
1 => 'value6',
|
||||
'key7' => 'value7',
|
||||
],
|
||||
];
|
||||
$this->assertSame($expect_value, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether map data with properties can be normalized.
|
||||
*/
|
||||
public function testMapWithPropertiesNormalize() {
|
||||
$typed_data = $this->buildExampleTypedDataWithProperties();
|
||||
$data = $this->serializer->normalize($typed_data, 'json');
|
||||
$expect_value = [
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2',
|
||||
'key3' => 3,
|
||||
'key4' => [
|
||||
0 => TRUE,
|
||||
1 => 'value6',
|
||||
'key7' => 'value7',
|
||||
],
|
||||
];
|
||||
$this->assertSame($expect_value, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds some example typed data object with no properties.
|
||||
*/
|
||||
protected function buildExampleTypedData() {
|
||||
$tree = [
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2',
|
||||
'key3' => 3,
|
||||
'key4' => [
|
||||
0 => TRUE,
|
||||
1 => 'value6',
|
||||
'key7' => 'value7',
|
||||
],
|
||||
];
|
||||
$map_data_definition = MapDataDefinition::create();
|
||||
$typed_data = $this->typedDataManager->create(
|
||||
$map_data_definition,
|
||||
$tree,
|
||||
'test name'
|
||||
);
|
||||
return $typed_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds some example typed data object with properties.
|
||||
*/
|
||||
protected function buildExampleTypedDataWithProperties() {
|
||||
$tree = [
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2',
|
||||
'key3' => 3,
|
||||
'key4' => [
|
||||
0 => TRUE,
|
||||
1 => 'value6',
|
||||
'key7' => 'value7',
|
||||
],
|
||||
];
|
||||
$map_data_definition = MapDataDefinition::create()
|
||||
->setPropertyDefinition('key1', DataDefinition::create('string'))
|
||||
->setPropertyDefinition('key2', DataDefinition::create('string'))
|
||||
->setPropertyDefinition('key3', DataDefinition::create('integer'))
|
||||
->setPropertyDefinition('key4', MapDataDefinition::create()
|
||||
->setPropertyDefinition(0, DataDefinition::create('boolean'))
|
||||
->setPropertyDefinition(1, DataDefinition::create('string'))
|
||||
->setPropertyDefinition('key7', DataDefinition::create('string'))
|
||||
);
|
||||
|
||||
$typed_data = $this->typedDataManager->create(
|
||||
$map_data_definition,
|
||||
$tree,
|
||||
'test name'
|
||||
);
|
||||
|
||||
return $typed_data;
|
||||
}
|
||||
|
||||
}
|
||||
+24
-12
@@ -21,26 +21,38 @@ class RegisterSerializationClassesCompilerPassTest extends UnitTestCase {
|
||||
$container = new ContainerBuilder();
|
||||
$container->setDefinition('serializer', new Definition(Serializer::class, [[], []]));
|
||||
|
||||
$definition = new Definition('TestClass');
|
||||
$definition->addTag('encoder', ['format' => 'xml']);
|
||||
$definition->addTag('_provider', ['provider' => 'test_provider_a']);
|
||||
$container->setDefinition('encoder_1', $definition);
|
||||
$encoder_1_definition = new Definition('TestClass');
|
||||
$encoder_1_definition->addTag('encoder', ['format' => 'xml']);
|
||||
$encoder_1_definition->addTag('_provider', ['provider' => 'test_provider_a']);
|
||||
$container->setDefinition('encoder_1', $encoder_1_definition);
|
||||
|
||||
$definition = new Definition('TestClass');
|
||||
$definition->addTag('encoder', ['format' => 'json']);
|
||||
$definition->addTag('_provider', ['provider' => 'test_provider_a']);
|
||||
$container->setDefinition('encoder_2', $definition);
|
||||
$encoder_2_definition = new Definition('TestClass');
|
||||
$encoder_2_definition->addTag('encoder', ['format' => 'json']);
|
||||
$encoder_2_definition->addTag('_provider', ['provider' => 'test_provider_a']);
|
||||
$container->setDefinition('encoder_2', $encoder_2_definition);
|
||||
|
||||
$definition = new Definition('TestClass');
|
||||
$definition->addTag('encoder', ['format' => 'hal_json']);
|
||||
$definition->addTag('_provider', ['provider' => 'test_provider_b']);
|
||||
$container->setDefinition('encoder_3', $definition);
|
||||
$encoder_3_definition = new Definition('TestClass');
|
||||
$encoder_3_definition->addTag('encoder', ['format' => 'hal_json']);
|
||||
$encoder_3_definition->addTag('_provider', ['provider' => 'test_provider_b']);
|
||||
$container->setDefinition('encoder_3', $encoder_3_definition);
|
||||
|
||||
$normalizer_1_definition = new Definition('TestClass');
|
||||
$normalizer_1_definition->addTag('normalizer');
|
||||
$container->setDefinition('normalizer_1', $normalizer_1_definition);
|
||||
|
||||
$compiler_pass = new RegisterSerializationClassesCompilerPass();
|
||||
$compiler_pass->process($container);
|
||||
|
||||
// Check registration of formats and providers.
|
||||
$this->assertEquals(['xml', 'json', 'hal_json'], $container->getParameter('serializer.formats'));
|
||||
$this->assertEquals(['xml' => 'test_provider_a', 'json' => 'test_provider_a', 'hal_json' => 'test_provider_b'], $container->getParameter('serializer.format_providers'));
|
||||
|
||||
// Check all encoder and normalizer service definitions are marked private.
|
||||
$this->assertFalse($encoder_1_definition->isPublic());
|
||||
$this->assertFalse($encoder_2_definition->isPublic());
|
||||
$this->assertFalse($encoder_3_definition->isPublic());
|
||||
|
||||
$this->assertFalse($normalizer_1_definition->isPublic());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ class XmlEncoderTest extends UnitTestCase {
|
||||
}
|
||||
|
||||
class TestObject {
|
||||
|
||||
public function getA() {
|
||||
return 'A';
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Drupal\Tests\serialization\Unit\EntityResolver;
|
||||
|
||||
use Drupal\Core\Entity\EntityRepositoryInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\serialization\EntityResolver\UuidResolver;
|
||||
|
||||
@@ -29,7 +30,7 @@ class UuidResolverTest extends UnitTestCase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->entityManager = $this->getMockBuilder('Drupal\Core\Entity\EntityManager')
|
||||
$this->entityManager = $this->getMockBuilder(EntityRepositoryInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ class EntityNormalizerTest extends UnitTestCase {
|
||||
->with('bundle')
|
||||
->will($this->returnValue('test_type'));
|
||||
$entity_type->expects($this->once())
|
||||
->method('isSubClassOf')
|
||||
->method('entityClassImplements')
|
||||
->with(FieldableEntityInterface::class)
|
||||
->willReturn(TRUE);
|
||||
|
||||
@@ -240,7 +240,7 @@ class EntityNormalizerTest extends UnitTestCase {
|
||||
->with('bundle')
|
||||
->will($this->returnValue('test_type'));
|
||||
$entity_type->expects($this->once())
|
||||
->method('isSubClassOf')
|
||||
->method('entityClassImplements')
|
||||
->with(FieldableEntityInterface::class)
|
||||
->willReturn(TRUE);
|
||||
|
||||
@@ -303,7 +303,7 @@ class EntityNormalizerTest extends UnitTestCase {
|
||||
|
||||
$entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
|
||||
$entity_type->expects($this->once())
|
||||
->method('isSubClassOf')
|
||||
->method('entityClassImplements')
|
||||
->with(FieldableEntityInterface::class)
|
||||
->willReturn(TRUE);
|
||||
$entity_type->expects($this->once())
|
||||
@@ -376,7 +376,7 @@ class EntityNormalizerTest extends UnitTestCase {
|
||||
|
||||
$entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
|
||||
$entity_type->expects($this->once())
|
||||
->method('isSubClassOf')
|
||||
->method('entityClassImplements')
|
||||
->with(FieldableEntityInterface::class)
|
||||
->willReturn(FALSE);
|
||||
|
||||
|
||||
+94
@@ -4,12 +4,14 @@ namespace Drupal\Tests\serialization\Unit\Normalizer;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\TypedData\Type\IntegerInterface;
|
||||
use Drupal\Core\TypedData\TypedDataInterface;
|
||||
use Drupal\Core\Entity\EntityRepositoryInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Field\FieldItemInterface;
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem;
|
||||
use Drupal\locale\StringInterface;
|
||||
use Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizer;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Prophecy\Argument;
|
||||
@@ -120,6 +122,13 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
|
||||
->willReturn($entity->reveal())
|
||||
->shouldBeCalled();
|
||||
|
||||
$field_definition = $this->prophesize(FieldDefinitionInterface::class);
|
||||
$field_definition->getSetting('target_type')
|
||||
->willReturn('test_type');
|
||||
|
||||
$this->fieldItem->getFieldDefinition()
|
||||
->willReturn($field_definition->reveal());
|
||||
|
||||
$this->fieldItem->get('entity')
|
||||
->willReturn($entity_reference)
|
||||
->shouldBeCalled();
|
||||
@@ -139,6 +148,46 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
|
||||
$this->assertSame($expected, $normalized);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::normalize
|
||||
*/
|
||||
public function testNormalizeWithEmptyTaxonomyTermReference() {
|
||||
// Override the serializer prophecy from setUp() to return a zero value.
|
||||
$this->serializer = $this->prophesize(Serializer::class);
|
||||
// Set up the serializer to return an entity property.
|
||||
$this->serializer->normalize(Argument::cetera())
|
||||
->willReturn(0);
|
||||
|
||||
$this->normalizer->setSerializer($this->serializer->reveal());
|
||||
|
||||
$entity_reference = $this->prophesize(TypedDataInterface::class);
|
||||
$entity_reference->getValue()
|
||||
->willReturn(NULL)
|
||||
->shouldBeCalled();
|
||||
|
||||
$field_definition = $this->prophesize(FieldDefinitionInterface::class);
|
||||
$field_definition->getSetting('target_type')
|
||||
->willReturn('taxonomy_term');
|
||||
|
||||
$this->fieldItem->getFieldDefinition()
|
||||
->willReturn($field_definition->reveal());
|
||||
|
||||
$this->fieldItem->get('entity')
|
||||
->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' => NULL,
|
||||
];
|
||||
$this->assertSame($expected, $normalized);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::normalize
|
||||
*/
|
||||
@@ -148,6 +197,13 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
|
||||
->willReturn(NULL)
|
||||
->shouldBeCalled();
|
||||
|
||||
$field_definition = $this->prophesize(FieldDefinitionInterface::class);
|
||||
$field_definition->getSetting('target_type')
|
||||
->willReturn('test_type');
|
||||
|
||||
$this->fieldItem->getFieldDefinition()
|
||||
->willReturn($field_definition->reveal());
|
||||
|
||||
$this->fieldItem->get('entity')
|
||||
->willReturn($entity_reference->reveal())
|
||||
->shouldBeCalled();
|
||||
@@ -183,6 +239,9 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
|
||||
->willReturn($entity)
|
||||
->shouldBeCalled();
|
||||
|
||||
$this->fieldItem->getProperties()->willReturn([
|
||||
'target_id' => $this->prophesize(IntegerInterface::class),
|
||||
]);
|
||||
$this->fieldItem->setValue(['target_id' => 'test'])->shouldBeCalled();
|
||||
|
||||
$this->assertDenormalize($data);
|
||||
@@ -206,6 +265,9 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
|
||||
->willReturn($entity)
|
||||
->shouldBeCalled();
|
||||
|
||||
$this->fieldItem->getProperties()->willReturn([
|
||||
'target_id' => $this->prophesize(IntegerInterface::class),
|
||||
]);
|
||||
$this->fieldItem->setValue(['target_id' => 'test'])->shouldBeCalled();
|
||||
|
||||
$this->assertDenormalize($data);
|
||||
@@ -307,4 +369,36 @@ class EntityReferenceFieldItemNormalizerTest extends UnitTestCase {
|
||||
$this->assertSame($context['target_instance'], $denormalized);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::constructValue
|
||||
*/
|
||||
public function testConstructValueProperties() {
|
||||
$data = [
|
||||
'target_id' => 'test',
|
||||
'target_type' => 'test_type',
|
||||
'target_uuid' => '080e3add-f9d5-41ac-9821-eea55b7b42fb',
|
||||
'extra_property' => 'extra_value',
|
||||
];
|
||||
|
||||
$entity = $this->prophesize(FieldableEntityInterface::class);
|
||||
$entity->id()
|
||||
->willReturn('test')
|
||||
->shouldBeCalled();
|
||||
$this->entityRepository
|
||||
->loadEntityByUuid($data['target_type'], $data['target_uuid'])
|
||||
->willReturn($entity)
|
||||
->shouldBeCalled();
|
||||
|
||||
$this->fieldItem->getProperties()->willReturn([
|
||||
'target_id' => $this->prophesize(IntegerInterface::class),
|
||||
'extra_property' => $this->prophesize(StringInterface::class),
|
||||
]);
|
||||
$this->fieldItem->setValue([
|
||||
'target_id' => 'test',
|
||||
'extra_property' => 'extra_value',
|
||||
])->shouldBeCalled();
|
||||
|
||||
$this->assertDenormalize($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user