diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/UriNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/UriNormalizerTest.php index 0986796..23f55c8 100644 --- a/core/modules/serialization/tests/src/Unit/Normalizer/UriNormalizerTest.php +++ b/core/modules/serialization/tests/src/Unit/Normalizer/UriNormalizerTest.php @@ -9,13 +9,10 @@ use Symfony\Component\Serializer\Serializer; /** - * @coversDefaultClass \Drupal\serialization\Normalizer\UriItemNormalizer - * - * + * Tests the normalizer for URI field items. * - * Drupal\Core\TypedData\Plugin\DataType\Uri + * @coversDefaultClass \Drupal\serialization\Normalizer\UriItemNormalizer * - * Drupal\Core\Field\Plugin\Field\FieldType\UriItem * @group serialization */ class UriNormalizerTest extends UnitTestCase { @@ -38,26 +35,27 @@ class UriNormalizerTest extends UnitTestCase { * {@inheritdoc} */ protected function setUp() { - $this->normalizer = new UriItemNormalizer(); + parent::setUp(); - $this->serializer = $this->prophesize(Serializer::class); - $this->normalizer->setSerializer($this->serializer->reveal()); + $this->normalizer = new UriItemNormalizer(); } /** * @covers ::supportsNormalization * @dataProvider dataProviderUriData */ - public function testSupportsNormalization($uri_data, $expected) { - $this->assertTrue($this->normalizer->supportsNormalization($uri_data)); + public function testSupportsNormalization($file_uri) { + $uri_item = $this->prepareUriItem($file_uri); + $this->assertTrue($this->normalizer->supportsNormalization($uri_item->reveal())); } /** * @covers ::normalize * @dataProvider dataProviderUriData */ - public function testNormalize($uri_data, $expected) { - $this->assertSame($expected, $this->normalizer->normalize($uri_data)); + public function testNormalize($file_uri, $expected) { + $uri_item = $this->prepareUriItem($file_uri); + $this->assertSame($expected, $this->normalizer->normalize($uri_item->reveal())); } /** @@ -67,7 +65,7 @@ public function dataProviderUriData() { $data = []; $data['uri'] = [ - $this->prophesizeDefinition('public://some-file.pdf')->reveal(), + 'public://some-file.pdf', [ 'value' => 'public://some-file.pdf', 'url' => 'file_create_url:public://some-file.pdf', @@ -75,7 +73,7 @@ public function dataProviderUriData() { ]; $data['uri-null'] = [ - $this->prophesizeDefinition(NULL)->reveal(), + NULL, [ 'value' => NULL, ], @@ -84,23 +82,29 @@ public function dataProviderUriData() { } /** - * Helper to define prophecies. + * Prepares a URI field item for a specific file URI. * * @param string $file_uri + * The file URI to prepare the URI field item for. * - * @return \Prophecy\Prophecy\ObjectProphecy + * @return \Prophecy\Prophecy\ProphecyInterface + * A prophecy for the URI field item. */ - protected function prophesizeDefinition($file_uri) { - $uri_prophecy = $this->prophesize(Uri::class); - $uri_prophecy->getValue()->willReturn($file_uri); - $uri = $uri_prophecy->reveal(); + protected function prepareUriItem($file_uri) { + $uri_property = $this->prophesize(Uri::class); + $uri_property->getValue()->willReturn($file_uri); + + $this->serializer = $this->prophesize(Serializer::class); + $this->serializer->normalize($uri_property->reveal(), NULL, [])->willReturn($file_uri); + $this->normalizer->setSerializer($this->serializer->reveal()); - $uri_item_prophecy = $this->prophesize(UriItem::class); - $uri_item_prophecy->get('value')->willReturn($uri); - $uri_item_prophecy->getIterator()->willReturn(new \ArrayIterator(['value' => $uri])); + $uri_item = $this->prophesize(UriItem::class); + $uri_item->get('value')->willReturn($uri_property->reveal()); + $uri_item->getIterator()->willReturn(new \ArrayIterator(['value' => $uri_property->reveal()])); - return $uri_item_prophecy; + return $uri_item; } + } namespace Drupal\serialization\Normalizer;