summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/file/tests/src/Kernel/FileUriItemTest.php
blob: 529048316771dcde49d8418bd72f88c54a778512 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php

declare(strict_types=1);

namespace Drupal\Tests\file\Kernel;

use Drupal\file\Entity\File;

/**
 * File URI field item test.
 *
 * @group file
 *
 * @see \Drupal\file\Plugin\Field\FieldType\FileUriItem
 * @see \Drupal\file\FileUrl
 */
class FileUriItemTest extends FileManagedUnitTestBase {

  /**
   * Tests the file entity override of the URI field.
   */
  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);
  }

}