function 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.

7 calls to FileTestBase::createUri()
FileManagedTestBase::createFile in drupal/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php
Create a file and save it to the files table and assert that it occurs correctly.
UnmanagedCopyTest::testNormal in drupal/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedCopyTest.php
Copy a normal file.
UnmanagedCopyTest::testOverwriteSelf in drupal/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedCopyTest.php
Copy a file onto itself.
UnmanagedDeleteTest::testNormal in drupal/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedDeleteTest.php
Delete a normal file.
UnmanagedMoveTest::testNormal in drupal/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedMoveTest.php
Move a normal file.

... See full list

File

drupal/core/modules/system/lib/Drupal/system/Tests/File/FileTestBase.php, line 187
Definition of Drupal\system\Tests\File\FileTestBase.

Class

FileTestBase
Base class for file tests that adds some additional file specific assertions and helper functions.

Namespace

Drupal\system\Tests\File

Code

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.
    $filepath = 'Файл для тестирования ' . $this
      ->randomName();
  }
  if (!isset($scheme)) {
    $scheme = file_default_scheme();
  }
  $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
    ->assertTrue(is_file($filepath), t('The test file exists on the disk.'), 'Create test file');
  return $filepath;
}