diff --git a/core/modules/image/src/Tests/ImageStyleTest.php b/core/modules/image/src/Tests/ImageStyleTest.php index 2628485..b00c724 100644 --- a/core/modules/image/src/Tests/ImageStyleTest.php +++ b/core/modules/image/src/Tests/ImageStyleTest.php @@ -69,8 +69,8 @@ public static function getInfo() { * {@inheritdoc} */ public function setUp() { - $this->entityTypeId = $this->randomName(); - $this->provider = $this->randomName(); + $this->entityTypeId = $this->randomMachineName(); + $this->provider = $this->randomMachineName(); $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); $this->entityType->expects($this->any()) ->method('getProvider') @@ -91,7 +91,7 @@ public function setUp() { * @covers ::transformMimeType */ public function testTransformMimeType() { - $image_effect_id = $this->randomName(); + $image_effect_id = $this->randomMachineName(); $image_effect = $this->getMockBuilder('\Drupal\image\ImageEffectBase') ->setConstructorArgs(array(array(), $image_effect_id, array())) ->getMock(); diff --git a/core/modules/responsive_image/tests/src/ResponsiveImageMappingConfigEntityUnitTest.php b/core/modules/responsive_image/tests/src/ResponsiveImageMappingConfigEntityUnitTest.php index 169ed6e..9b18e11 100644 --- a/core/modules/responsive_image/tests/src/ResponsiveImageMappingConfigEntityUnitTest.php +++ b/core/modules/responsive_image/tests/src/ResponsiveImageMappingConfigEntityUnitTest.php @@ -132,13 +132,26 @@ public function testHasMappings() { /** * @covers ::addMapping - * @covers ::getImageStyle + * @covers ::getMappingDefinition */ - public function testGetImageStyle() { + public function testGetMappingDefinition() { $entity = new ResponsiveImageMapping(array('')); - $entity->addMapping('test_breakpoint', '1x', 'test_style'); - $this->assertEquals('test_style', $entity->getImageStyle('test_breakpoint', '1x')); - $this->assertNull($entity->getImageStyle('test_unknown_breakpoint', '1x')); + $entity->addMapping('test_breakpoint', '1x', array( + 'mapping_type' => 'image_style', + 'image_style' => 'large', + 'sizes' => '', + 'sizes_image_styles' => array(), + )); + $expected = array( + 'breakpoint_id' => 'test_breakpoint', + 'multiplier' => '1x', + 'mapping_type' => 'image_style', + 'image_style' => 'large', + 'sizes' => '', + 'sizes_image_styles' => array(), + ); + $this->assertEquals($expected, $entity->getMappingDefinition('test_breakpoint', '1x')); + $this->assertNull($entity->getMappingDefinition('test_unknown_breakpoint', '1x')); } /** @@ -147,24 +160,76 @@ public function testGetImageStyle() { */ public function testGetKeyedMappings() { $entity = new ResponsiveImageMapping(array('')); - $entity->addMapping('test_breakpoint', '1x', 'test_style'); - $entity->addMapping('test_breakpoint', '2x', 'test_style2'); - $entity->addMapping('test_breakpoint2', '1x', 'test_style3'); + $entity->addMapping('test_breakpoint', '1x', array( + 'mapping_type' => 'image_style', + 'image_style' => 'large', + 'sizes' => '', + 'sizes_image_styles' => array(), + )); + $entity->addMapping('test_breakpoint', '2x', array( + 'mapping_type' => 'sizes', + 'image_style' => '', + 'sizes' => '(min-width:700px) 700px, 100vw', + 'sizes_image_styles' => array( + 'large' => 'large', + ), + )); + $entity->addMapping('test_breakpoint2', '1x', array( + 'mapping_type' => 'image_style', + 'image_style' => 'thumbnail', + 'sizes' => '', + 'sizes_image_styles' => array(), + )); $expected = array( 'test_breakpoint' => array( - '1x' => 'test_style', - '2x' => 'test_style2', + '1x' => array( + 'breakpoint_id' => 'test_breakpoint', + 'multiplier' => '1x', + 'mapping_type' => 'image_style', + 'image_style' => 'large', + 'sizes' => '', + 'sizes_image_styles' => array(), + ), + '2x' => array( + 'breakpoint_id' => 'test_breakpoint', + 'multiplier' => '2x', + 'mapping_type' => 'sizes', + 'image_style' => '', + 'sizes' => '(min-width:700px) 700px, 100vw', + 'sizes_image_styles' => array( + 'large' => 'large', + ), + ), ), 'test_breakpoint2' => array( - '1x' => 'test_style3', + '1x' => array( + 'breakpoint_id' => 'test_breakpoint2', + 'multiplier' => '1x', + 'mapping_type' => 'image_style', + 'image_style' => 'thumbnail', + 'sizes' => '', + 'sizes_image_styles' => array(), + ), ) ); $this->assertEquals($expected, $entity->getKeyedMappings()); // Add another mapping to ensure keyed mapping static cache is rebuilt. - $entity->addMapping('test_breakpoint2', '2x', 'test_style4'); - $expected['test_breakpoint2']['2x'] = 'test_style4'; + $entity->addMapping('test_breakpoint2', '2x', array( + 'mapping_type' => 'image_style', + 'image_style' => 'medium', + 'sizes' => '', + 'sizes_image_styles' => array(), + )); + $expected['test_breakpoint2']['2x'] = array( + 'breakpoint_id' => 'test_breakpoint2', + 'multiplier' => '2x', + 'mapping_type' => 'image_style', + 'image_style' => 'medium', + 'sizes' => '', + 'sizes_image_styles' => array(), + ); $this->assertEquals($expected, $entity->getKeyedMappings()); } @@ -174,25 +239,53 @@ public function testGetKeyedMappings() { */ public function testGetMappings() { $entity = new ResponsiveImageMapping(array('')); - $entity->addMapping('test_breakpoint', '1x', 'test_style'); - $entity->addMapping('test_breakpoint', '2x', 'test_style2'); - $entity->addMapping('test_breakpoint2', '1x', 'test_style3'); + $entity->addMapping('test_breakpoint', '1x', array( + 'mapping_type' => 'image_style', + 'image_style' => 'large', + 'sizes' => '', + 'sizes_image_styles' => array(), + )); + $entity->addMapping('test_breakpoint', '2x', array( + 'mapping_type' => 'sizes', + 'image_style' => '', + 'sizes' => '(min-width:700px) 700px, 100vw', + 'sizes_image_styles' => array( + 'large' => 'large', + ), + )); + $entity->addMapping('test_breakpoint2', '1x', array( + 'mapping_type' => 'image_style', + 'image_style' => 'thumbnail', + 'sizes' => '', + 'sizes_image_styles' => array(), + )); $expected = array( array( 'breakpoint_id' => 'test_breakpoint', 'multiplier' => '1x', - 'image_style' => 'test_style', + 'mapping_type' => 'image_style', + 'image_style' => 'large', + 'sizes' => '', + 'sizes_image_styles' => array(), ), array( 'breakpoint_id' => 'test_breakpoint', 'multiplier' => '2x', - 'image_style' => 'test_style2', + 'mapping_type' => 'sizes', + 'image_style' => '', + 'sizes' => '(min-width:700px) 700px, 100vw', + 'sizes_image_styles' => array( + 'large' => 'large', + ), ), array( 'breakpoint_id' => 'test_breakpoint2', 'multiplier' => '1x', - 'image_style' => 'test_style3', + 'mapping_type' => 'image_style', + 'image_style' => 'thumbnail', + 'sizes' => '', + 'sizes_image_styles' => array(), ), ); $this->assertEquals($expected, $entity->getMappings()); @@ -204,9 +297,26 @@ public function testGetMappings() { */ public function testRemoveMappings() { $entity = new ResponsiveImageMapping(array('')); - $entity->addMapping('test_breakpoint', '1x', 'test_style'); - $entity->addMapping('test_breakpoint', '2x', 'test_style2'); - $entity->addMapping('test_breakpoint2', '1x', 'test_style3'); + $entity->addMapping('test_breakpoint', '1x', array( + 'mapping_type' => 'image_style', + 'image_style' => 'large', + 'sizes' => '', + 'sizes_image_styles' => array(), + )); + $entity->addMapping('test_breakpoint', '2x', array( + 'mapping_type' => 'sizes', + 'image_style' => '', + 'sizes' => '(min-width:700px) 700px, 100vw', + 'sizes_image_styles' => array( + 'large' => 'large', + ), + )); + $entity->addMapping('test_breakpoint2', '1x', array( + 'mapping_type' => 'image_style', + 'image_style' => 'thumbnail', + 'sizes' => '', + 'sizes_image_styles' => array(), + )); $this->assertTrue($entity->hasMappings()); $entity->removeMappings(); @@ -221,9 +331,26 @@ public function testRemoveMappings() { */ public function testSetBreakpointGroup() { $entity = new ResponsiveImageMapping(array('breakpointGroup' => 'test_group')); - $entity->addMapping('test_breakpoint', '1x', 'test_style'); - $entity->addMapping('test_breakpoint', '2x', 'test_style2'); - $entity->addMapping('test_breakpoint2', '1x', 'test_style3'); + $entity->addMapping('test_breakpoint', '1x', array( + 'mapping_type' => 'image_style', + 'image_style' => 'large', + 'sizes' => '', + 'sizes_image_styles' => array(), + )); + $entity->addMapping('test_breakpoint', '2x', array( + 'mapping_type' => 'sizes', + 'image_style' => '', + 'sizes' => '(min-width:700px) 700px, 100vw', + 'sizes_image_styles' => array( + 'large' => 'large', + ), + )); + $entity->addMapping('test_breakpoint2', '1x', array( + 'mapping_type' => 'image_style', + 'image_style' => 'thumbnail', + 'sizes' => '', + 'sizes_image_styles' => array(), + )); // Ensure that setting to same group does not remove mappings. $entity->setBreakpointGroup('test_group');