diff --git a/core/modules/file/tests/src/Kernel/FileUriItemTest.php b/core/modules/file/tests/src/Kernel/FileUriItemTest.php index c42591bfd3..5c38fa6441 100644 --- a/core/modules/file/tests/src/Kernel/FileUriItemTest.php +++ b/core/modules/file/tests/src/Kernel/FileUriItemTest.php @@ -29,7 +29,7 @@ public function testCustomFileUriField() { $file->save(); $this->assertSame($uri, $file->uri->value); - $this->assertSame(file_create_url($uri), $file->uri->url); + $this->assertSame(file_url_transform_relative(file_create_url($uri), $file->uri->url)); } } diff --git a/core/modules/file/tests/src/Unit/FileUrlTest.php b/core/modules/file/tests/src/Unit/FileUrlTest.php index ec0f22ce6f..93360a0b48 100644 --- a/core/modules/file/tests/src/Unit/FileUrlTest.php +++ b/core/modules/file/tests/src/Unit/FileUrlTest.php @@ -2,9 +2,9 @@ namespace Drupal\Tests\file\Unit; -use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Field\FieldItemInterface; use Drupal\Core\TypedData\DataDefinitionInterface; +use Drupal\file\FileInterface; use Drupal\file\FileUrl; use Drupal\Tests\UnitTestCase; @@ -20,14 +20,14 @@ class FileUrlTest extends UnitTestCase { * * @var string */ - protected $testUrl = 'https://localhost.test'; + protected $testUrl = 'public://path/to/file.txt'; /** * @covers ::getValue */ public function testGetValue() { - $entity = $this->prophesize(EntityInterface::class); - $entity->url() + $entity = $this->prophesize(FileInterface::class); + $entity->getFileUri() ->willReturn($this->testUrl); $parent = $this->prophesize(FieldItemInterface::class); @@ -39,10 +39,10 @@ public function testGetValue() { $typed_data = new FileUrl($definition->reveal(), 'test', $parent->reveal()); - $this->assertSame($this->testUrl, $typed_data->getValue()); + $this->assertSame('/path/to/file.txt', $typed_data->getValue()); // Do this a second time to confirm the same value is returned but the value // isn't retrieved from the parent entity again. - $this->assertSame($this->testUrl, $typed_data->getValue()); + $this->assertSame('/path/to/file.txt', $typed_data->getValue()); } /** diff --git a/core/modules/hal/hal.services.yml b/core/modules/hal/hal.services.yml index b2c898fc56..ca28f522b4 100644 --- a/core/modules/hal/hal.services.yml +++ b/core/modules/hal/hal.services.yml @@ -12,11 +12,6 @@ services: class: Drupal\hal\Normalizer\FieldNormalizer tags: - { name: normalizer, priority: 10 } - serializer.normalizer.file_entity.hal: - class: Drupal\hal\Normalizer\FileEntityNormalizer - tags: - - { name: normalizer, priority: 20 } - arguments: ['@entity.manager', '@http_client', '@hal.link_manager', '@module_handler'] serializer.normalizer.timestamp_item.hal: class: Drupal\hal\Normalizer\TimestampItemNormalizer tags: diff --git a/core/modules/hal/src/Normalizer/FileEntityNormalizer.php b/core/modules/hal/src/Normalizer/FileEntityNormalizer.php deleted file mode 100644 index 1b3ee6f782..0000000000 --- a/core/modules/hal/src/Normalizer/FileEntityNormalizer.php +++ /dev/null @@ -1,59 +0,0 @@ -httpClient = $http_client; - } - - /** - * {@inheritdoc} - */ - public function denormalize($data, $class, $format = NULL, array $context = []) { - $file_data = (string) $this->httpClient->get($data['uri'][0]['value'])->getBody(); - - $path = 'temporary://' . drupal_basename($data['uri'][0]['value']); - $data['uri'] = file_unmanaged_save_data($file_data, $path); - - return $this->entityManager->getStorage('file')->create($data); - } - -} diff --git a/core/modules/hal/tests/src/Functional/FileDenormalizeTest.php b/core/modules/hal/tests/src/Functional/FileDenormalizeTest.php deleted file mode 100644 index 05ee234893..0000000000 --- a/core/modules/hal/tests/src/Functional/FileDenormalizeTest.php +++ /dev/null @@ -1,75 +0,0 @@ - 'test_1.txt', - 'uri' => 'public://test_1.txt', - 'filemime' => 'text/plain', - 'status' => FILE_STATUS_PERMANENT, - ]; - // Create a new file entity. - $file = File::create($file_params); - file_put_contents($file->getFileUri(), 'hello world'); - $file->save(); - - $serializer = \Drupal::service('serializer'); - $normalized_data = $serializer->normalize($file, 'hal_json'); - $denormalized = $serializer->denormalize($normalized_data, 'Drupal\file\Entity\File', 'hal_json'); - - $this->assertTrue($denormalized instanceof File, 'A File instance was created.'); - - $this->assertIdentical('temporary://' . $file->getFilename(), $denormalized->getFileUri(), 'The expected file URI was found.'); - $this->assertTrue(file_exists($denormalized->getFileUri()), 'The temporary file was found.'); - - $this->assertIdentical($file->uuid(), $denormalized->uuid(), 'The expected UUID was found'); - $this->assertIdentical($file->getMimeType(), $denormalized->getMimeType(), 'The expected MIME type was found.'); - $this->assertIdentical($file->getFilename(), $denormalized->getFilename(), 'The expected filename was found.'); - $this->assertTrue($denormalized->isPermanent(), 'The file has a permanent status.'); - - // Try to denormalize with the file uri only. - $file_name = 'test_2.txt'; - $file_path = 'public://' . $file_name; - - file_put_contents($file_path, 'hello world'); - $file_uri = file_create_url($file_path); - - $data = [ - 'uri' => [ - ['value' => $file_uri], - ], - ]; - - $denormalized = $serializer->denormalize($data, 'Drupal\file\Entity\File', 'hal_json'); - - $this->assertIdentical('temporary://' . $file_name, $denormalized->getFileUri(), 'The expected file URI was found.'); - $this->assertTrue(file_exists($denormalized->getFileUri()), 'The temporary file was found.'); - - $this->assertIdentical('text/plain', $denormalized->getMimeType(), 'The expected MIME type was found.'); - $this->assertIdentical($file_name, $denormalized->getFilename(), 'The expected filename was found.'); - $this->assertFalse($denormalized->isPermanent(), 'The file has a permanent status.'); - } - -}