You are here

protected function ImageStyleTest::getImageStyleMock in Drupal 8

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

Class

ImageStyleTest
@coversDefaultClass \Drupal\image\Entity\ImageStyle

Namespace

Drupal\Tests\image\Unit

Code

protected function getImageStyleMock($image_effect_id, $image_effect, $stubs = []) {
  $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 = [
    'getImageEffectPluginManager',
    'fileUriScheme',
    'fileUriTarget',
    'fileDefaultScheme',
  ];
  $image_style = $this
    ->getMockBuilder('\\Drupal\\image\\Entity\\ImageStyle')
    ->setConstructorArgs([
    [
      'effects' => [
        $image_effect_id => [
          '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('fileDefaultScheme')
    ->will($this
    ->returnCallback([
    $this,
    'fileDefaultScheme',
  ]));
  return $image_style;
}