3 namespace Drupal\Tests\hal\Kernel;
5 use Drupal\file\Entity\File;
8 * Tests that file entities can be normalized in HAL.
12 class FileNormalizeTest extends NormalizerTestBase {
19 public static $modules = ['file'];
24 protected function setUp() {
26 $this->installEntitySchema('file');
30 * Tests the normalize function.
32 public function testNormalize() {
34 'filename' => 'test_1.txt',
35 'uri' => 'public://test_1.txt',
36 'filemime' => 'text/plain',
37 'status' => FILE_STATUS_PERMANENT,
39 // Create a new file entity.
40 $file = File::create($file_params);
41 file_put_contents($file->getFileUri(), 'hello world');
47 'value' => $file->getFileUri(),
48 'url' => file_url_transform_relative(file_create_url($file->getFileUri())),
53 $normalized = $this->serializer->normalize($file, $this->format);
54 $this->assertEqual($normalized['uri'], $expected_array['uri'], 'URI is normalized.');