You are here

public function ResponsiveImageStyleConfigEntityUnitTest::testCalculateDependencies in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php \Drupal\Tests\responsive_image\Unit\ResponsiveImageStyleConfigEntityUnitTest::testCalculateDependencies()

@covers ::calculateDependencies

File

core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php, line 67
Contains \Drupal\Tests\responsive_image\Unit\ResponsiveImageStyleConfigEntityUnitTest.

Class

ResponsiveImageStyleConfigEntityUnitTest
@coversDefaultClass \Drupal\responsive_image\Entity\ResponsiveImageStyle @group block

Namespace

Drupal\Tests\responsive_image\Unit

Code

public function testCalculateDependencies() {

  // Set up image style loading mock.
  $styles = [];
  foreach ([
    'fallback',
    'small',
    'medium',
    'large',
  ] as $style) {
    $mock = $this
      ->getMock('Drupal\\Core\\Config\\Entity\\ConfigEntityInterface');
    $mock
      ->expects($this
      ->any())
      ->method('getConfigDependencyName')
      ->willReturn('image.style.' . $style);
    $styles[$style] = $mock;
  }
  $storage = $this
    ->getMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorageInterface');
  $storage
    ->expects($this
    ->any())
    ->method('loadMultiple')
    ->with(array_keys($styles))
    ->willReturn($styles);
  $this->entityManager
    ->expects($this
    ->any())
    ->method('getStorage')
    ->with('image_style')
    ->willReturn($storage);
  $this->entityManager
    ->expects($this
    ->any())
    ->method('getEntityTypeFromClass')
    ->with('Drupal\\image\\Entity\\ImageStyle')
    ->willReturn('image_style');
  $entity = new ResponsiveImageStyle([
    'breakpoint_group' => 'test_group',
  ]);
  $entity
    ->setBreakpointGroup('test_group');
  $entity
    ->setFallbackImageStyle('fallback');
  $entity
    ->addImageStyleMapping('test_breakpoint', '1x', [
    'image_mapping_type' => 'image_style',
    'image_mapping' => 'small',
  ]);
  $entity
    ->addImageStyleMapping('test_breakpoint', '2x', [
    'image_mapping_type' => 'sizes',
    'image_mapping' => [
      'sizes' => '(min-width:700px) 700px, 100vw',
      'sizes_image_styles' => [
        'medium' => 'medium',
        'large' => 'large',
      ],
    ],
  ]);
  $this->breakpointManager
    ->expects($this
    ->any())
    ->method('getGroupProviders')
    ->with('test_group')
    ->willReturn(array(
    'bartik' => 'theme',
    'toolbar' => 'module',
  ));
  $dependencies = $entity
    ->calculateDependencies()
    ->getDependencies();
  $this
    ->assertEquals([
    'toolbar',
  ], $dependencies['module']);
  $this
    ->assertEquals([
    'bartik',
  ], $dependencies['theme']);
  $this
    ->assertEquals([
    'image.style.fallback',
    'image.style.large',
    'image.style.medium',
    'image.style.small',
  ], $dependencies['config']);
}