public function FileTestBase::createUri in Drupal 9
Same name and namespace in other branches
- 8 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
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.
File
- core/
tests/ Drupal/ KernelTests/ Core/ File/ FileTestBase.php, line 186
Class
- FileTestBase
- Base class for file tests that adds some additional file specific assertions and helper functions.
Namespace
Drupal\KernelTests\Core\FileCode
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;
}