function ResponsiveImageStyleConfigEntityUnitTest::testCalculateDependencies
Same name in other branches
- 8.9.x core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php \Drupal\Tests\responsive_image\Unit\ResponsiveImageStyleConfigEntityUnitTest::testCalculateDependencies()
- 10 core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php \Drupal\Tests\responsive_image\Unit\ResponsiveImageStyleConfigEntityUnitTest::testCalculateDependencies()
- 11.x 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 64
Class
- ResponsiveImageStyleConfigEntityUnitTest
- @coversDefaultClass \Drupal\responsive_image\Entity\ResponsiveImageStyle @group block
Namespace
Drupal\Tests\responsive_image\UnitCode
public function testCalculateDependencies() {
// Set up image style loading mock.
$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);
$styles[$style] = $mock;
}
$storage = $this->createMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorageInterface');
$storage->expects($this->any())
->method('loadMultiple')
->with(array_keys($styles))
->willReturn($styles);
$this->entityTypeManager
->expects($this->any())
->method('getStorage')
->with('image_style')
->willReturn($storage);
$entity_type_repository = $this->getMockForAbstractClass(EntityTypeRepositoryInterface::class);
$entity_type_repository->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([
'olivero' => 'theme',
'toolbar' => 'module',
]);
\Drupal::getContainer()->set('entity_type.repository', $entity_type_repository);
$dependencies = $entity->calculateDependencies()
->getDependencies();
$this->assertEquals([
'toolbar',
], $dependencies['module']);
$this->assertEquals([
'olivero',
], $dependencies['theme']);
$this->assertEquals([
'image.style.fallback',
'image.style.large',
'image.style.medium',
'image.style.small',
], $dependencies['config']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.