function ViewsConfigUpdaterTest::testNeedsResponsiveImageLazyLoadFieldUpdate

@covers ::needsResponsiveImageLazyLoadFieldUpdate

File

core/modules/views/tests/src/Kernel/ViewsConfigUpdaterTest.php, line 39

Class

ViewsConfigUpdaterTest
@coversDefaultClass \Drupal\views\ViewsConfigUpdater

Namespace

Drupal\Tests\views\Kernel

Code

public function testNeedsResponsiveImageLazyLoadFieldUpdate() : void {
    $config_updater = $this->container
        ->get('class_resolver')
        ->getInstanceFromDefinition(ViewsConfigUpdater::class);
    assert($config_updater instanceof ViewsConfigUpdater);
    FieldStorageConfig::create([
        'field_name' => 'user_picture',
        'entity_type' => 'user',
        'type' => 'image',
    ])->save();
    FieldConfig::create([
        'entity_type' => 'user',
        'field_name' => 'user_picture',
        'file_directory' => 'pictures/[date:custom:Y]-[date:custom:m]',
        'bundle' => 'user',
    ])->save();
    // Create a responsive image style.
    ResponsiveImageStyle::create([
        'id' => ViewsIntegrationTest::RESPONSIVE_IMAGE_STYLE_ID,
        'label' => 'Foo',
        'breakpoint_group' => 'responsive_image_test_module',
    ]);
    // 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();
    $test_view = $this->loadTestView('views.view.test_responsive_images');
    $needs_update = $config_updater->needsResponsiveImageLazyLoadFieldUpdate($test_view);
    $test_view->save();
    $this->assertTrue($needs_update);
    $default_display = $test_view->getDisplay('default');
    self::assertEquals('eager', $default_display['display_options']['fields']['bar']['settings']['image_loading']['attribute']);
}

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