class FileNormalizeTest
Tests that file entities can be normalized in HAL.
@group hal @group legacy
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\hal\Kernel\NormalizerTestBase implements \Drupal\KernelTests\KernelTestBase
- class \Drupal\Tests\hal\Kernel\FileNormalizeTest implements \Drupal\Tests\hal\Kernel\NormalizerTestBase
- class \Drupal\Tests\hal\Kernel\NormalizerTestBase implements \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of FileNormalizeTest
File
-
core/
modules/ hal/ tests/ src/ Kernel/ FileNormalizeTest.php, line 13
Namespace
Drupal\Tests\hal\KernelView source
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.');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.