function FileUriItemTest::testCustomFileUriField
Same name in other branches
- 9 core/modules/file/tests/src/Kernel/FileUriItemTest.php \Drupal\Tests\file\Kernel\FileUriItemTest::testCustomFileUriField()
- 8.9.x core/modules/file/tests/src/Kernel/FileUriItemTest.php \Drupal\Tests\file\Kernel\FileUriItemTest::testCustomFileUriField()
- 11.x core/modules/file/tests/src/Kernel/FileUriItemTest.php \Drupal\Tests\file\Kernel\FileUriItemTest::testCustomFileUriField()
Tests the file entity override of the URI field.
File
-
core/
modules/ file/ tests/ src/ Kernel/ FileUriItemTest.php, line 22
Class
- FileUriItemTest
- File URI field item test.
Namespace
Drupal\Tests\file\KernelCode
public function testCustomFileUriField() : void {
$uri = 'public://druplicon.txt';
// Create a new file entity.
$file = File::create([
'uid' => 1,
'filename' => 'druplicon.txt',
'uri' => $uri,
'filemime' => 'text/plain',
]);
$file->setPermanent();
file_put_contents($file->getFileUri(), 'hello world');
$file->save();
$this->assertSame($uri, $file->uri->value);
$expected_url = base_path() . $this->siteDirectory . '/files/druplicon.txt';
$this->assertSame($expected_url, $file->uri->url);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.