You are here

protected function ImageReplaceTestBase::createTestFiles in Image Replace 7

Same name and namespace in other branches
  1. 8 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 80

Class

ImageReplaceTestBase
Tests functionality of the replace image effect.

Namespace

Drupal\image_replace\Tests

Code

protected function createTestFiles() {

  // Generate test images.
  $original_uri = file_unmanaged_copy(__DIR__ . '/fixtures/original.png', 'public://', FILE_EXISTS_RENAME);
  $this
    ->assertTrue($this
    ->imageIsOriginal($original_uri));
  $this
    ->assertFalse($this
    ->imageIsReplacement($original_uri));
  $original_file = file_save((object) array(
    'filename' => drupal_basename($original_uri),
    'uri' => $original_uri,
    'status' => FILE_STATUS_PERMANENT,
    'filemime' => file_get_mimetype($original_uri),
  ));
  $replacement_uri = file_unmanaged_copy(__DIR__ . '/fixtures/replacement.png', 'public://', FILE_EXISTS_RENAME);
  $this
    ->assertTrue($this
    ->imageIsReplacement($replacement_uri));
  $this
    ->assertFalse($this
    ->imageIsOriginal($replacement_uri));
  $replacement_file = file_save((object) array(
    'filename' => drupal_basename($replacement_uri),
    'uri' => $replacement_uri,
    'status' => FILE_STATUS_PERMANENT,
    'filemime' => file_get_mimetype($replacement_uri),
  ));
  return array(
    $original_file,
    $replacement_file,
  );
}