function FileTestBase::createUri

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/File/FileTestBase.php \Drupal\KernelTests\Core\File\FileTestBase::createUri()
  2. 10 core/tests/Drupal/KernelTests/Core/File/FileTestBase.php \Drupal\KernelTests\Core\File\FileTestBase::createUri()
  3. 11.x core/tests/Drupal/KernelTests/Core/File/FileTestBase.php \Drupal\KernelTests\Core\File\FileTestBase::createUri()

Create a file and return the URI of it.

Parameters

$filepath: Optional string specifying the file path. If none is provided then a randomly named file will be created in the site's files directory.

$contents: Optional contents to save into the file. If a NULL value is provided an arbitrary string will be used.

$scheme: Optional string indicating the stream scheme to use. Drupal core includes public, private, and temporary. The public wrapper is the default.

Return value

string File URI.

14 calls to FileTestBase::createUri()
DownloadTest::testNonDestructiveDownload in core/modules/migrate/tests/src/Kernel/process/DownloadTest.php
Tests a download that renames the downloaded file if there's a collision.
DownloadTest::testOverwritingDownload in core/modules/migrate/tests/src/Kernel/process/DownloadTest.php
Tests a download that overwrites an existing local file.
DownloadTest::testWriteProtectedDestination in core/modules/migrate/tests/src/Kernel/process/DownloadTest.php
Tests that an exception is thrown if the destination URI is not writable.
FileCopyTest::testNonWritableDestination in core/modules/migrate/tests/src/Kernel/process/FileCopyTest.php
Tests that non-writable destination throw an exception.
FileCopyTest::testNormal in core/tests/Drupal/KernelTests/Core/File/FileCopyTest.php
Copy a normal file.

... See full list

File

core/tests/Drupal/KernelTests/Core/File/FileTestBase.php, line 188

Class

FileTestBase
Provides file-specific assertions and helper functions.

Namespace

Drupal\KernelTests\Core\File

Code

public function createUri($filepath = NULL, $contents = NULL, $scheme = NULL) {
    if (!isset($filepath)) {
        // Prefix with non-latin characters to ensure that all file-related
        // tests work with international filenames.
        // cSpell:disable-next-line
        $filepath = 'Файл для тестирования ' . $this->randomMachineName();
    }
    if (!isset($scheme)) {
        $scheme = 'public';
    }
    $filepath = $scheme . '://' . $filepath;
    if (!isset($contents)) {
        $contents = "file_put_contents() doesn't seem to appreciate empty strings so let's put in some data.";
    }
    file_put_contents($filepath, $contents);
    $this->assertFileExists($filepath);
    return $filepath;
}

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