You are here

protected function ImageReplaceTestBase::createTestFiles in Image Replace 8

Same name and namespace in other branches
  1. 7 src/Tests/ImageReplaceTestBase.php \Drupal\image_replace\Tests\ImageReplaceTestBase::createTestFiles()

Create a pair of test files.

Return value

array An array with two file objects (original_file, replacement_file).

3 calls to ImageReplaceTestBase::createTestFiles()
AdminTest::testFieldEditUi in src/Tests/AdminTest.php
Tests image replacement on node entities.
EntityTest::testNodeView in src/Tests/EntityTest.php
Tests image replacement on node entities.
ReplaceEffectTest::testReplaceEffect in src/Tests/ReplaceEffectTest.php
Tests functionality of the replace image effect.

File

src/Tests/ImageReplaceTestBase.php, line 100

Class

ImageReplaceTestBase
Tests functionality of the replace image effect.

Namespace

Drupal\image_replace\Tests

Code

protected function createTestFiles() {

  // Generate test images.
  $file_system = \Drupal::service('file_system');
  $original_uri = $file_system
    ->copy(__DIR__ . '/fixtures/original.png', 'public://', FileSystemInterface::EXISTS_RENAME);
  $this
    ->assertTrue($this
    ->imageIsOriginal($original_uri));
  $this
    ->assertFalse($this
    ->imageIsReplacement($original_uri));
  $original_file = File::create([
    'filename' => $file_system
      ->basename($original_uri),
    'uri' => $original_uri,
    'status' => FILE_STATUS_PERMANENT,
    'filemime' => \Drupal::service('file.mime_type.guesser')
      ->guess($original_uri),
  ]);
  $original_file
    ->save();
  $replacement_uri = $file_system
    ->copy(__DIR__ . '/fixtures/replacement.png', 'public://', FileSystemInterface::EXISTS_RENAME);
  $this
    ->assertTrue($this
    ->imageIsReplacement($replacement_uri));
  $this
    ->assertFalse($this
    ->imageIsOriginal($replacement_uri));
  $replacement_file = File::create([
    'filename' => $file_system
      ->basename($replacement_uri),
    'uri' => $replacement_uri,
    'status' => FILE_STATUS_PERMANENT,
    'filemime' => \Drupal::service('file.mime_type.guesser')
      ->guess($replacement_uri),
  ]);
  $replacement_file
    ->save();
  return [
    $original_file,
    $replacement_file,
  ];
}