You are here

protected function BlazyManagerUnitTestTrait::setUpResponsiveImageStyle in Blazy 8

Same name and namespace in other branches
  1. 8.2 tests/src/Traits/BlazyManagerUnitTestTrait.php \Drupal\Tests\blazy\Traits\BlazyManagerUnitTestTrait::setUpResponsiveImageStyle()

Prepare Responsive image styles.

File

tests/src/Traits/BlazyManagerUnitTestTrait.php, line 110

Class

BlazyManagerUnitTestTrait
A Trait common for Blazy related service managers.

Namespace

Drupal\Tests\blazy\Traits

Code

protected function setUpResponsiveImageStyle() {
  $styles = $image_styles = [];
  foreach ([
    'fallback',
    'small',
    'medium',
    'large',
  ] as $style) {
    $mock = $this
      ->createMock('Drupal\\Core\\Config\\Entity\\ConfigEntityInterface');
    $mock
      ->expects($this
      ->any())
      ->method('getConfigDependencyName')
      ->willReturn('image.style.' . $style);
    $mock
      ->expects($this
      ->any())
      ->method('getCacheTags')
      ->willReturn([]);
    $image_styles[$style] = $mock;
  }
  foreach ([
    'blazy_picture_test',
    'blazy_responsive_test',
  ] as $style) {
    $mock = $this
      ->createMock('Drupal\\responsive_image\\ResponsiveImageStyleInterface');
    $mock
      ->expects($this
      ->any())
      ->method('getImageStyleIds')
      ->willReturn(array_keys($image_styles));
    $mock
      ->expects($this
      ->any())
      ->method('getCacheTags')
      ->willReturn([]);
    $styles[$style] = $mock;
  }
  $ids = array_keys($styles);
  $storage = $this
    ->createMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorageInterface');
  $storage
    ->expects($this
    ->any())
    ->method('loadMultiple')
    ->with($ids)
    ->willReturn($styles);
  $style = 'blazy_picture_test';
  $storage
    ->expects($this
    ->any())
    ->method('load')
    ->with($style)
    ->willReturn($styles[$style]);
  $this->entityTypeManager
    ->expects($this
    ->any())
    ->method('getStorage')
    ->with('responsive_image_style')
    ->willReturn($storage);
  $this->entityTypeManager
    ->expects($this
    ->any())
    ->method('getEntityTypeFromClass')
    ->with('Drupal\\image\\Entity\\ImageStyle')
    ->willReturn('image_style');
  return $styles;
}