You are here

protected function ImageStyleTest::getImageStyleMock in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/image/tests/src/Unit/ImageStyleTest.php \Drupal\Tests\image\Unit\ImageStyleTest::getImageStyleMock()

Gets a mocked image style for testing.

Parameters

string $image_effect_id: The image effect ID.

\Drupal\image\ImageEffectInterface|\PHPUnit_Framework_MockObject_MockObject $image_effect: The image effect used for testing.

Return value

\Drupal\image\ImageStyleInterface|\Drupal\image\ImageStyleInterface The mocked image style.

3 calls to ImageStyleTest::getImageStyleMock()
ImageStyleTest::testBuildUri in core/modules/image/tests/src/Unit/ImageStyleTest.php
@covers ::buildUri
ImageStyleTest::testGetDerivativeExtension in core/modules/image/tests/src/Unit/ImageStyleTest.php
@covers ::getDerivativeExtension
ImageStyleTest::testGetPathToken in core/modules/image/tests/src/Unit/ImageStyleTest.php
@covers ::getPathToken

File

core/modules/image/tests/src/Unit/ImageStyleTest.php, line 52
Contains \Drupal\Tests\image\Unit\ImageStyleTest.

Class

ImageStyleTest
@coversDefaultClass \Drupal\image\Entity\ImageStyle

Namespace

Drupal\Tests\image\Unit

Code

protected function getImageStyleMock($image_effect_id, $image_effect, $stubs = array()) {
  $effectManager = $this
    ->getMockBuilder('\\Drupal\\image\\ImageEffectManager')
    ->disableOriginalConstructor()
    ->getMock();
  $effectManager
    ->expects($this
    ->any())
    ->method('createInstance')
    ->with($image_effect_id)
    ->will($this
    ->returnValue($image_effect));
  $default_stubs = array(
    'getImageEffectPluginManager',
    'fileUriScheme',
    'fileUriTarget',
    'fileDefaultScheme',
  );
  $image_style = $this
    ->getMockBuilder('\\Drupal\\image\\Entity\\ImageStyle')
    ->setConstructorArgs(array(
    array(
      'effects' => array(
        $image_effect_id => array(
          'id' => $image_effect_id,
        ),
      ),
    ),
    $this->entityTypeId,
  ))
    ->setMethods(array_merge($default_stubs, $stubs))
    ->getMock();
  $image_style
    ->expects($this
    ->any())
    ->method('getImageEffectPluginManager')
    ->will($this
    ->returnValue($effectManager));
  $image_style
    ->expects($this
    ->any())
    ->method('fileUriScheme')
    ->will($this
    ->returnCallback(array(
    $this,
    'fileUriScheme',
  )));
  $image_style
    ->expects($this
    ->any())
    ->method('fileUriTarget')
    ->will($this
    ->returnCallback(array(
    $this,
    'fileUriTarget',
  )));
  $image_style
    ->expects($this
    ->any())
    ->method('fileDefaultScheme')
    ->will($this
    ->returnCallback(array(
    $this,
    'fileDefaultScheme',
  )));
  return $image_style;
}