You are here

class FileUriItemTest in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/file/tests/src/Kernel/FileUriItemTest.php \Drupal\Tests\file\Kernel\FileUriItemTest
  2. 9 core/modules/file/tests/src/Kernel/FileUriItemTest.php \Drupal\Tests\file\Kernel\FileUriItemTest

File URI field item test.

@group file

Hierarchy

Expanded class hierarchy of FileUriItemTest

See also

\Drupal\file\Plugin\Field\FieldType\FileUriItem

\Drupal\file\FileUrl

File

core/modules/file/tests/src/Kernel/FileUriItemTest.php, line 15

Namespace

Drupal\Tests\file\Kernel
View source
class FileUriItemTest extends FileManagedUnitTestBase {

  /**
   * Tests the file entity override of the URI field.
   */
  public function testCustomFileUriField() {
    $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);
  }

}

Members