View source
<?php
namespace Drupal\Tests\responsive_image\Kernel;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\KernelTestBase;
use Drupal\responsive_image\Entity\ResponsiveImageStyle;
class ResponsiveImageIntegrationTest extends KernelTestBase {
protected static $modules = [
'responsive_image',
'field',
'image',
'file',
'entity_test',
'breakpoint',
'responsive_image_test_module',
'user',
];
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('entity_test');
}
public function testEntityViewDisplayDependency() {
ResponsiveImageStyle::create([
'id' => 'foo',
'label' => 'Foo',
'breakpoint_group' => 'responsive_image_test_module',
])
->save();
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();
$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();
$this
->assertNotNull($display = EntityViewDisplay::load('entity_test.entity_test.default'));
$this
->assertNotEmpty($display
->getComponent('bar'));
$this
->assertArrayNotHasKey('bar', $display
->get('hidden'));
ResponsiveImageStyle::load('foo')
->delete();
$this
->assertNotNull($display = EntityViewDisplay::load('entity_test.entity_test.default'));
$this
->assertNull($display
->getComponent('bar'));
$this
->assertArrayHasKey('bar', $display
->get('hidden'));
}
}