Chris@0: installEntitySchema('entity_test'); Chris@0: $this->installEntitySchema('user'); Chris@0: $this->installSchema('user', ['users_data']); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests integration with image module. Chris@0: */ Chris@0: public function testImage() { Chris@0: /** @var \Drupal\image\ImageStyleInterface $style */ Chris@0: $style = ImageStyle::create(['name' => 'foo']); Chris@0: $style->save(); Chris@0: Chris@0: // Create a new image field 'bar' to be used in 'entity_test_fields' view. Chris@0: FieldStorageConfig::create([ Chris@0: 'entity_type' => 'entity_test', Chris@0: 'field_name' => 'bar', Chris@0: 'type' => 'image', Chris@0: ])->save(); Chris@0: FieldConfig::create([ Chris@0: 'entity_type' => 'entity_test', Chris@0: 'bundle' => 'entity_test', Chris@0: 'field_name' => 'bar', Chris@0: ])->save(); Chris@0: Chris@0: /** @var \Drupal\views\ViewEntityInterface $view */ Chris@0: $view = View::load('entity_test_fields'); Chris@0: $display =& $view->getDisplay('default'); Chris@0: Chris@0: // Add the 'bar' image field to 'entity_test_fields' view. Chris@0: $display['display_options']['fields']['bar'] = [ Chris@0: 'id' => 'bar', Chris@0: 'field' => 'bar', Chris@0: 'plugin_id' => 'field', Chris@0: 'table' => 'entity_test__bar', Chris@0: 'entity_type' => 'entity_test', Chris@0: 'entity_field' => 'bar', Chris@0: 'type' => 'image', Chris@0: 'settings' => ['image_style' => 'foo', 'image_link' => ''], Chris@0: ]; Chris@0: $view->save(); Chris@0: Chris@0: $dependencies = $view->getDependencies() + ['config' => []]; Chris@0: Chris@0: // Checks that style 'foo' is a dependency of view 'entity_test_fields'. Chris@0: $this->assertTrue(in_array('image.style.foo', $dependencies['config'])); Chris@0: Chris@0: // Delete the 'foo' image style. Chris@0: $style->delete(); Chris@0: Chris@0: $view = View::load('entity_test_fields'); Chris@0: Chris@0: // Checks that the view has not been deleted too. Chris@0: $this->assertNotNull(View::load('entity_test_fields')); Chris@0: Chris@0: // Checks that the image field was removed from the View. Chris@0: $display = $view->getDisplay('default'); Chris@0: $this->assertFalse(isset($display['display_options']['fields']['bar'])); Chris@0: Chris@0: // Checks that the view has been disabled. Chris@0: $this->assertFalse($view->status()); Chris@0: Chris@0: $dependencies = $view->getDependencies() + ['config' => []]; Chris@0: // Checks that the dependency on style 'foo' has been removed. Chris@0: $this->assertFalse(in_array('image.style.foo', $dependencies['config'])); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests removing a config dependency that deletes the View. Chris@0: */ Chris@0: public function testConfigRemovalRole() { Chris@0: // Create a role we can add to the View and delete. Chris@0: $role = Role::create([ Chris@0: 'id' => 'dummy', Chris@0: 'label' => 'dummy', Chris@0: ]); Chris@0: Chris@0: $role->save(); Chris@0: Chris@0: /** @var \Drupal\views\ViewEntityInterface $view */ Chris@0: $view = View::load('entity_test_fields'); Chris@0: $display = &$view->getDisplay('default'); Chris@0: Chris@0: // Set the access to be restricted by the dummy role. Chris@0: $display['display_options']['access'] = [ Chris@0: 'type' => 'role', Chris@0: 'options' => [ Chris@0: 'role' => [ Chris@0: $role->id() => $role->id(), Chris@0: ], Chris@0: ], Chris@0: ]; Chris@0: $view->save(); Chris@0: Chris@0: // Check that the View now has a dependency on the Role. Chris@0: $dependencies = $view->getDependencies() + ['config' => []]; Chris@0: $this->assertTrue(in_array('user.role.dummy', $dependencies['config'])); Chris@0: Chris@0: // Delete the role. Chris@0: $role->delete(); Chris@0: Chris@0: $view = View::load('entity_test_fields'); Chris@0: Chris@0: // Checks that the view has been deleted too. Chris@0: $this->assertNull($view); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests uninstalling a module that provides a base table for a View. Chris@0: */ Chris@0: public function testConfigRemovalBaseTable() { Chris@0: // Find all the entity types provided by the entity_test module and install Chris@0: // the schema for them so we can uninstall them. Chris@0: $entities = \Drupal::entityTypeManager()->getDefinitions(); Chris@0: foreach ($entities as $entity_type_id => $definition) { Chris@0: if ($definition->getProvider() == 'entity_test') { Chris@0: $this->installEntitySchema($entity_type_id); Chris@0: }; Chris@0: } Chris@0: Chris@0: // Check that removing the module that provides the base table for a View, Chris@0: // deletes the View. Chris@0: $this->assertNotNull(View::load('entity_test_fields')); Chris@0: $this->container->get('module_installer')->uninstall(['entity_test']); Chris@0: // Check that the View has been deleted. Chris@0: $this->assertNull(View::load('entity_test_fields')); Chris@0: } Chris@0: Chris@0: }