function ImageTest::getTestImage

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Image/ImageTest.php \Drupal\Tests\Core\Image\ImageTest::getTestImage()
  2. 10 core/tests/Drupal/Tests/Core/Image/ImageTest.php \Drupal\Tests\Core\Image\ImageTest::getTestImage()
  3. 11.x core/tests/Drupal/Tests/Core/Image/ImageTest.php \Drupal\Tests\Core\Image\ImageTest::getTestImage()

Get an image with a mocked toolkit, for testing.

Parameters

bool $load_expected: (optional) Whether the load() method is expected to be called. Defaults to TRUE.

array $stubs: (optional) Array containing toolkit methods to be replaced with stubs.

Return value

\Drupal\Core\Image\Image An image object.

10 calls to ImageTest::getTestImage()
ImageTest::testChmodFails in core/tests/Drupal/Tests/Core/Image/ImageTest.php
Tests \Drupal\Core\Image\Image::save().
ImageTest::testGetFileSize in core/tests/Drupal/Tests/Core/Image/ImageTest.php
Tests \Drupal\Core\Image\Image::getFileSize.
ImageTest::testGetHeight in core/tests/Drupal/Tests/Core/Image/ImageTest.php
Tests \Drupal\Core\Image\Image::getHeight().
ImageTest::testGetMimeType in core/tests/Drupal/Tests/Core/Image/ImageTest.php
Tests \Drupal\Core\Image\Image::getMimeType().
ImageTest::testGetToolkitId in core/tests/Drupal/Tests/Core/Image/ImageTest.php
Tests \Drupal\Core\Image\Image::getToolkitId().

... See full list

File

core/tests/Drupal/Tests/Core/Image/ImageTest.php, line 102

Class

ImageTest
Tests the image class.

Namespace

Drupal\Tests\Core\Image

Code

protected function getTestImage($load_expected = TRUE, array $stubs = []) {
    if (!$load_expected && !in_array('load', $stubs)) {
        $stubs = array_merge([
            'load',
        ], $stubs);
    }
    $this->toolkit = $this->getToolkitMock($stubs);
    $this->toolkit
        ->expects($this->any())
        ->method('getPluginId')
        ->willReturn('gd');
    if (!$load_expected) {
        $this->toolkit
            ->expects($this->never())
            ->method('load');
    }
    $this->image = new Image($this->toolkit, $this->source);
    return $this->image;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.