Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / file / tests / src / Kernel / FileUriItemTest.php
1 <?php
2
3 namespace Drupal\Tests\file\Kernel;
4
5 use Drupal\file\Entity\File;
6
7 /**
8  * File URI field item test.
9  *
10  * @group file
11  *
12  * @see \Drupal\file\Plugin\Field\FieldType\FileUriItem
13  * @see \Drupal\file\FileUrl
14  */
15 class FileUriItemTest extends FileManagedUnitTestBase {
16
17   /**
18    * Tests the file entity override of the URI field.
19    */
20   public function testCustomFileUriField() {
21     $uri = 'public://druplicon.txt';
22
23     // Create a new file entity.
24     $file = File::create([
25       'uid' => 1,
26       'filename' => 'druplicon.txt',
27       'uri' => $uri,
28       'filemime' => 'text/plain',
29       'status' => FILE_STATUS_PERMANENT,
30     ]);
31     file_put_contents($file->getFileUri(), 'hello world');
32
33     $file->save();
34
35     $this->assertSame($uri, $file->uri->value);
36     $expected_url = base_path() . $this->siteDirectory . '/files/druplicon.txt';
37     $this->assertSame($expected_url, $file->uri->url);
38   }
39
40 }