FileNormalizeTest.php in Drupal 9
File
core/modules/hal/tests/src/Kernel/FileNormalizeTest.php
View source
<?php
namespace Drupal\Tests\hal\Kernel;
use Drupal\file\Entity\File;
class FileNormalizeTest extends NormalizerTestBase {
protected static $modules = [
'file',
];
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('file');
}
public function testNormalize() {
$file_params = [
'filename' => 'test_1.txt',
'uri' => 'public://test_1.txt',
'filemime' => 'text/plain',
];
$file = File::create($file_params);
$file
->setPermanent();
file_put_contents($file
->getFileUri(), 'hello world');
$file
->save();
$expected_array = [
'uri' => [
[
'value' => $file
->getFileUri(),
'url' => $file
->createFileUrl(),
],
],
];
$normalized = $this->serializer
->normalize($file, $this->format);
$this
->assertEquals($expected_array['uri'], $normalized['uri'], 'URI is normalized.');
}
}