function ResponsiveImageIntegrationTest::testEntityViewDisplayDependency

Same name in other branches
  1. 9 core/modules/responsive_image/tests/src/Kernel/ResponsiveImageIntegrationTest.php \Drupal\Tests\responsive_image\Kernel\ResponsiveImageIntegrationTest::testEntityViewDisplayDependency()
  2. 10 core/modules/responsive_image/tests/src/Kernel/ResponsiveImageIntegrationTest.php \Drupal\Tests\responsive_image\Kernel\ResponsiveImageIntegrationTest::testEntityViewDisplayDependency()
  3. 11.x core/modules/responsive_image/tests/src/Kernel/ResponsiveImageIntegrationTest.php \Drupal\Tests\responsive_image\Kernel\ResponsiveImageIntegrationTest::testEntityViewDisplayDependency()

Tests integration with entity view display.

File

core/modules/responsive_image/tests/src/Kernel/ResponsiveImageIntegrationTest.php, line 43

Class

ResponsiveImageIntegrationTest
Tests the integration of responsive image with other components.

Namespace

Drupal\Tests\responsive_image\Kernel

Code

public function testEntityViewDisplayDependency() {
    // Create a responsive image style.
    ResponsiveImageStyle::create([
        'id' => 'foo',
        'label' => 'Foo',
        'breakpoint_group' => 'responsive_image_test_module',
    ])->save();
    // Create an image field to be used with a responsive image formatter.
    FieldStorageConfig::create([
        'type' => 'image',
        'entity_type' => 'entity_test',
        'field_name' => 'bar',
    ])->save();
    FieldConfig::create([
        'entity_type' => 'entity_test',
        'bundle' => 'entity_test',
        'field_name' => 'bar',
    ])->save();
    
    /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
    $display = EntityViewDisplay::create([
        'targetEntityType' => 'entity_test',
        'bundle' => 'entity_test',
        'mode' => 'default',
    ]);
    $display->setComponent('bar', [
        'type' => 'responsive_image',
        'label' => 'hidden',
        'settings' => [
            'responsive_image_style' => 'foo',
            'image_link' => '',
        ],
        'third_party_settings' => [],
    ])
        ->save();
    // Check that the 'foo' field is on the display.
    $this->assertNotNull($display = EntityViewDisplay::load('entity_test.entity_test.default'));
    $this->assertNotEmpty($display->getComponent('bar'));
    $this->assertArrayNotHasKey('bar', $display->get('hidden'));
    // Delete the responsive image style.
    ResponsiveImageStyle::load('foo')->delete();
    // Check that the view display was not deleted.
    $this->assertNotNull($display = EntityViewDisplay::load('entity_test.entity_test.default'));
    // Check that the 'foo' field was disabled.
    $this->assertNull($display->getComponent('bar'));
    $this->assertArrayHasKey('bar', $display->get('hidden'));
}

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