FileUriItemTest.php

Same filename in other branches
  1. 9 core/modules/file/tests/src/Kernel/FileUriItemTest.php
  2. 8.9.x core/modules/file/tests/src/Kernel/FileUriItemTest.php
  3. 10 core/modules/file/tests/src/Kernel/FileUriItemTest.php

Namespace

Drupal\Tests\file\Kernel

File

core/modules/file/tests/src/Kernel/FileUriItemTest.php

View source
<?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);
    }

}

Classes

Title Deprecated Summary
FileUriItemTest File URI field item test.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.