function ResponsiveImageStyleConfigEntityUnitTest::testGetKeyedImageStyleMappings

Same name in other branches
  1. 9 core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php \Drupal\Tests\responsive_image\Unit\ResponsiveImageStyleConfigEntityUnitTest::testGetKeyedImageStyleMappings()
  2. 8.9.x core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php \Drupal\Tests\responsive_image\Unit\ResponsiveImageStyleConfigEntityUnitTest::testGetKeyedImageStyleMappings()
  3. 11.x core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php \Drupal\Tests\responsive_image\Unit\ResponsiveImageStyleConfigEntityUnitTest::testGetKeyedImageStyleMappings()

@covers ::addImageStyleMapping @covers ::getKeyedImageStyleMappings

File

core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php, line 198

Class

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

Namespace

Drupal\Tests\responsive_image\Unit

Code

public function testGetKeyedImageStyleMappings() : void {
    $entity = new ResponsiveImageStyle([
        '',
    ]);
    $entity->addImageStyleMapping('test_breakpoint', '1x', [
        'image_mapping_type' => 'image_style',
        'image_mapping' => 'large',
    ]);
    $entity->addImageStyleMapping('test_breakpoint', '2x', [
        'image_mapping_type' => 'sizes',
        'image_mapping' => [
            'sizes' => '(min-width:700px) 700px, 100vw',
            'sizes_image_styles' => [
                'large' => 'large',
            ],
        ],
    ]);
    $entity->addImageStyleMapping('test_breakpoint2', '1x', [
        'image_mapping_type' => 'image_style',
        'image_mapping' => 'thumbnail',
    ]);
    $entity->addImageStyleMapping('test_breakpoint2', '2x', [
        'image_mapping_type' => 'image_style',
        'image_mapping' => '_original image_',
    ]);
    $expected = [
        'test_breakpoint' => [
            '1x' => [
                'breakpoint_id' => 'test_breakpoint',
                'multiplier' => '1x',
                'image_mapping_type' => 'image_style',
                'image_mapping' => 'large',
            ],
            '2x' => [
                'breakpoint_id' => 'test_breakpoint',
                'multiplier' => '2x',
                'image_mapping_type' => 'sizes',
                'image_mapping' => [
                    'sizes' => '(min-width:700px) 700px, 100vw',
                    'sizes_image_styles' => [
                        'large' => 'large',
                    ],
                ],
            ],
        ],
        'test_breakpoint2' => [
            '1x' => [
                'breakpoint_id' => 'test_breakpoint2',
                'multiplier' => '1x',
                'image_mapping_type' => 'image_style',
                'image_mapping' => 'thumbnail',
            ],
            '2x' => [
                'breakpoint_id' => 'test_breakpoint2',
                'multiplier' => '2x',
                'image_mapping_type' => 'image_style',
                'image_mapping' => '_original image_',
            ],
        ],
    ];
    $this->assertEquals($expected, $entity->getKeyedImageStyleMappings());
    // Add another mapping to ensure keyed mapping static cache is rebuilt.
    $entity->addImageStyleMapping('test_breakpoint2', '2x', [
        'image_mapping_type' => 'image_style',
        'image_mapping' => 'medium',
    ]);
    $expected['test_breakpoint2']['2x'] = [
        'breakpoint_id' => 'test_breakpoint2',
        'multiplier' => '2x',
        'image_mapping_type' => 'image_style',
        'image_mapping' => 'medium',
    ];
    $this->assertEquals($expected, $entity->getKeyedImageStyleMappings());
    // Overwrite a mapping to ensure keyed mapping static cache is rebuilt.
    $entity->addImageStyleMapping('test_breakpoint2', '2x', [
        'image_mapping_type' => 'image_style',
        'image_mapping' => 'large',
    ]);
    $expected['test_breakpoint2']['2x'] = [
        'breakpoint_id' => 'test_breakpoint2',
        'multiplier' => '2x',
        'image_mapping_type' => 'image_style',
        'image_mapping' => 'large',
    ];
    $this->assertEquals($expected, $entity->getKeyedImageStyleMappings());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.