Version 1
[yaffs-website] / web / core / modules / views / tests / src / Kernel / ViewsConfigDependenciesIntegrationTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Kernel;
4
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\field\Entity\FieldStorageConfig;
7 use Drupal\image\Entity\ImageStyle;
8 use Drupal\views\Entity\View;
9
10 /**
11  * Tests integration of views with other modules.
12  *
13  * @group views
14  */
15 class ViewsConfigDependenciesIntegrationTest extends ViewsKernelTestBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public static $modules = ['field', 'file', 'image', 'entity_test'];
21
22   /**
23    * {@inheritdoc}
24    */
25   public static $testViews = ['entity_test_fields'];
26
27   /**
28    * Tests integration with image module.
29    */
30   public function testImage() {
31     /** @var \Drupal\image\ImageStyleInterface $style */
32     $style = ImageStyle::create(['name' => 'foo']);
33     $style->save();
34
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',
39       'type' => 'image',
40     ])->save();
41     FieldConfig::create([
42       'entity_type' => 'entity_test',
43       'bundle' => 'entity_test',
44       'field_name' => 'bar',
45     ])->save();
46
47     /** @var \Drupal\views\ViewEntityInterface $view */
48     $view = View::load('entity_test_fields');
49     $display =& $view->getDisplay('default');
50
51     // Add the 'bar' image field to 'entity_test_fields' view.
52     $display['display_options']['fields']['bar'] = [
53       'id' => 'bar',
54       'field' => 'bar',
55       'plugin_id' => 'field',
56       'table' => 'entity_test__bar',
57       'entity_type' => 'entity_test',
58       'entity_field' => 'bar',
59       'type' => 'image',
60       'settings' => ['image_style' => 'foo', 'image_link' => ''],
61     ];
62     $view->save();
63
64     $dependencies = $view->getDependencies() + ['config' => []];
65
66     // Checks that style 'foo' is a dependency of view 'entity_test_fields'.
67     $this->assertTrue(in_array('image.style.foo', $dependencies['config']));
68
69     // Delete the 'foo' image style.
70     $style->delete();
71
72     // Checks that the view has been deleted too.
73     $this->assertNull(View::load('entity_test_fields'));
74   }
75
76 }