FileUriItemTest.php in Drupal 10
File
core/modules/file/tests/src/Kernel/FileUriItemTest.php
View source
<?php
namespace Drupal\Tests\file\Kernel;
use Drupal\file\Entity\File;
class FileUriItemTest extends FileManagedUnitTestBase {
public function testCustomFileUriField() {
$uri = 'public://druplicon.txt';
$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);
}
}