X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fviews%2Ftests%2Fsrc%2FKernel%2FViewsConfigDependenciesIntegrationTest.php;fp=web%2Fcore%2Fmodules%2Fviews%2Ftests%2Fsrc%2FKernel%2FViewsConfigDependenciesIntegrationTest.php;h=294bb0f44c2efd356eafe8a50ba5cf0acabd08c5;hp=f5a2e39aa0ef1c84a5434f7faa1a993d7fe7d368;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/views/tests/src/Kernel/ViewsConfigDependenciesIntegrationTest.php b/web/core/modules/views/tests/src/Kernel/ViewsConfigDependenciesIntegrationTest.php index f5a2e39aa..294bb0f44 100644 --- a/web/core/modules/views/tests/src/Kernel/ViewsConfigDependenciesIntegrationTest.php +++ b/web/core/modules/views/tests/src/Kernel/ViewsConfigDependenciesIntegrationTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\views\Kernel; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\image\Entity\ImageStyle; +use Drupal\user\Entity\Role; use Drupal\views\Entity\View; /** @@ -17,13 +18,23 @@ class ViewsConfigDependenciesIntegrationTest extends ViewsKernelTestBase { /** * {@inheritdoc} */ - public static $modules = ['field', 'file', 'image', 'entity_test']; + public static $modules = ['field', 'file', 'image', 'entity_test', 'user', 'text']; /** * {@inheritdoc} */ public static $testViews = ['entity_test_fields']; + /** + * {@inheritdoc} + */ + protected function setUp($import_test_views = TRUE) { + parent::setUp($import_test_views); + + $this->installEntitySchema('user'); + $this->installSchema('user', ['users_data']); + } + /** * Tests integration with image module. */ @@ -69,7 +80,81 @@ class ViewsConfigDependenciesIntegrationTest extends ViewsKernelTestBase { // Delete the 'foo' image style. $style->delete(); + $view = View::load('entity_test_fields'); + + // Checks that the view has not been deleted too. + $this->assertNotNull(View::load('entity_test_fields')); + + // Checks that the image field was removed from the View. + $display = $view->getDisplay('default'); + $this->assertFalse(isset($display['display_options']['fields']['bar'])); + + // Checks that the view has been disabled. + $this->assertFalse($view->status()); + + $dependencies = $view->getDependencies() + ['config' => []]; + // Checks that the dependency on style 'foo' has been removed. + $this->assertFalse(in_array('image.style.foo', $dependencies['config'])); + } + + /** + * Tests removing a config dependency that deletes the View. + */ + public function testConfigRemovalRole() { + // Create a role we can add to the View and delete. + $role = Role::create([ + 'id' => 'dummy', + 'label' => 'dummy', + ]); + + $role->save(); + + /** @var \Drupal\views\ViewEntityInterface $view */ + $view = View::load('entity_test_fields'); + $display = &$view->getDisplay('default'); + + // Set the access to be restricted by the dummy role. + $display['display_options']['access'] = [ + 'type' => 'role', + 'options' => [ + 'role' => [ + $role->id() => $role->id(), + ], + ], + ]; + $view->save(); + + // Check that the View now has a dependency on the Role. + $dependencies = $view->getDependencies() + ['config' => []]; + $this->assertTrue(in_array('user.role.dummy', $dependencies['config'])); + + // Delete the role. + $role->delete(); + + $view = View::load('entity_test_fields'); + // Checks that the view has been deleted too. + $this->assertNull($view); + } + + /** + * Tests uninstalling a module that provides a base table for a View. + */ + public function testConfigRemovalBaseTable() { + // Find all the entity types provided by the entity_test module and install + // the schema for them so we can uninstall them. + $entities = \Drupal::entityTypeManager()->getDefinitions(); + foreach ($entities as $entity_type_id => $definition) { + if ($definition->getProvider() == 'entity_test') { + $this->installEntitySchema($entity_type_id); + }; + } + + // Check that removing the module that provides the base table for a View, + // deletes the View. + $this->assertNotNull(View::load('entity_test_fields')); + $this->container->get('module_installer')->uninstall(['entity_test']); + // Check that the View has been deleted. $this->assertNull(View::load('entity_test_fields')); }