3 namespace Drupal\Tests\views\Kernel;
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\field\Entity\FieldStorageConfig;
7 use Drupal\image\Entity\ImageStyle;
8 use Drupal\views\Entity\View;
11 * Tests integration of views with other modules.
15 class ViewsConfigDependenciesIntegrationTest extends ViewsKernelTestBase {
20 public static $modules = ['field', 'file', 'image', 'entity_test'];
25 public static $testViews = ['entity_test_fields'];
28 * Tests integration with image module.
30 public function testImage() {
31 /** @var \Drupal\image\ImageStyleInterface $style */
32 $style = ImageStyle::create(['name' => 'foo']);
35 // Create a new image field 'bar' to be used in 'entity_test_fields' view.
36 FieldStorageConfig::create([
37 'entity_type' => 'entity_test',
38 'field_name' => 'bar',
42 'entity_type' => 'entity_test',
43 'bundle' => 'entity_test',
44 'field_name' => 'bar',
47 /** @var \Drupal\views\ViewEntityInterface $view */
48 $view = View::load('entity_test_fields');
49 $display =& $view->getDisplay('default');
51 // Add the 'bar' image field to 'entity_test_fields' view.
52 $display['display_options']['fields']['bar'] = [
55 'plugin_id' => 'field',
56 'table' => 'entity_test__bar',
57 'entity_type' => 'entity_test',
58 'entity_field' => 'bar',
60 'settings' => ['image_style' => 'foo', 'image_link' => ''],
64 $dependencies = $view->getDependencies() + ['config' => []];
66 // Checks that style 'foo' is a dependency of view 'entity_test_fields'.
67 $this->assertTrue(in_array('image.style.foo', $dependencies['config']));
69 // Delete the 'foo' image style.
72 // Checks that the view has been deleted too.
73 $this->assertNull(View::load('entity_test_fields'));