You are here

public function ImageOptimizePipelineTest::createUri in Image Optimize (or ImageAPI Optimize) 8.3

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/ImageOptimizePipelineTest.php \Drupal\Tests\imageapi_optimize\Kernel\ImageOptimizePipelineTest::createUri()
  2. 4.x tests/src/Kernel/ImageOptimizePipelineTest.php \Drupal\Tests\imageapi_optimize\Kernel\ImageOptimizePipelineTest::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.

4 calls to ImageOptimizePipelineTest::createUri()
ImageOptimizePipelineTest::testCompoundFailureImagePipeline in tests/src/Kernel/ImageOptimizePipelineTest.php
Test using image pipeline that should not change the image.
ImageOptimizePipelineTest::testCompoundImagePipeline in tests/src/Kernel/ImageOptimizePipelineTest.php
Test procesors are cumulative.
ImageOptimizePipelineTest::testFailureImagePipeline in tests/src/Kernel/ImageOptimizePipelineTest.php
Test using image pipeline that should not change the image.
ImageOptimizePipelineTest::testValidImagePipeline in tests/src/Kernel/ImageOptimizePipelineTest.php
Test using image pipeline

File

tests/src/Kernel/ImageOptimizePipelineTest.php, line 177

Class

ImageOptimizePipelineTest
Tests Image Optimize pipelines.

Namespace

Drupal\Tests\imageapi_optimize\Kernel

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.
    $filepath = 'Файл для тестирования ' . $this
      ->randomMachineName();
  }
  if (!isset($scheme)) {
    $scheme = \Drupal::config('system.file')
      ->get('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.'));
  return $filepath;
}