FileNormalizeTest.php

Same filename in other branches
  1. 8.9.x core/modules/hal/tests/src/Kernel/FileNormalizeTest.php

Namespace

Drupal\Tests\hal\Kernel

File

core/modules/hal/tests/src/Kernel/FileNormalizeTest.php

View source
<?php

namespace Drupal\Tests\hal\Kernel;

use Drupal\file\Entity\File;

/**
 * Tests that file entities can be normalized in HAL.
 *
 * @group hal
 * @group legacy
 */
class FileNormalizeTest extends NormalizerTestBase {
    
    /**
     * Modules to enable.
     *
     * @var array
     */
    protected static $modules = [
        'file',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        parent::setUp();
        $this->installEntitySchema('file');
    }
    
    /**
     * Tests the normalize function.
     */
    public function testNormalize() {
        $file_params = [
            'filename' => 'test_1.txt',
            'uri' => 'public://test_1.txt',
            'filemime' => 'text/plain',
        ];
        // Create a new file entity.
        $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.');
    }

}

Classes

Title Deprecated Summary
FileNormalizeTest Tests that file entities can be normalized in HAL.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.