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');
31 * Tests the normalize function.
33 public function testNormalize() {
35 'filename' => 'test_1.txt',
36 'uri' => 'public://test_1.txt',
37 'filemime' => 'text/plain',
38 'status' => FILE_STATUS_PERMANENT,
40 // Create a new file entity.
41 $file = File::create($file_params);
42 file_put_contents($file->getFileUri(), 'hello world');
47 ['value' => file_create_url($file->getFileUri())],
51 $normalized = $this->serializer->normalize($file, $this->format);
52 $this->assertEqual($normalized['uri'], $expected_array['uri'], 'URI is normalized.');