Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / hal / tests / src / Kernel / FileNormalizeTest.php
1 <?php
2
3 namespace Drupal\Tests\hal\Kernel;
4
5 use Drupal\file\Entity\File;
6
7 /**
8  * Tests that file entities can be normalized in HAL.
9  *
10  * @group hal
11  */
12 class FileNormalizeTest extends NormalizerTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = ['file'];
20
21   /**
22    * {@inheritdoc}
23    */
24   protected function setUp() {
25     parent::setUp();
26     $this->installEntitySchema('file');
27   }
28
29
30   /**
31    * Tests the normalize function.
32    */
33   public function testNormalize() {
34     $file_params = [
35       'filename' => 'test_1.txt',
36       'uri' => 'public://test_1.txt',
37       'filemime' => 'text/plain',
38       'status' => FILE_STATUS_PERMANENT,
39     ];
40     // Create a new file entity.
41     $file = File::create($file_params);
42     file_put_contents($file->getFileUri(), 'hello world');
43     $file->save();
44
45     $expected_array = [
46       'uri' => [
47         ['value' => file_create_url($file->getFileUri())],
48       ],
49     ];
50
51     $normalized = $this->serializer->normalize($file, $this->format);
52     $this->assertEqual($normalized['uri'], $expected_array['uri'], 'URI is normalized.');
53
54   }
55
56 }