Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / config / tests / src / Functional / ConfigImportAllTest.php
index 0608681dd7ffb90b7bdf23f8335156d324a9edb7..7d37bc49099b1e9d46ee44319dd853eaa42b32d3 100644 (file)
@@ -3,9 +3,7 @@
 namespace Drupal\Tests\config\Functional;
 
 use Drupal\Core\Config\StorageComparer;
-use Drupal\filter\Entity\FilterFormat;
-use Drupal\shortcut\Entity\Shortcut;
-use Drupal\taxonomy\Entity\Term;
+use Drupal\Core\Entity\ContentEntityTypeInterface;
 use Drupal\Tests\SchemaCheckTestTrait;
 use Drupal\Tests\system\Functional\Module\ModuleTestBase;
 
@@ -72,33 +70,29 @@ class ConfigImportAllTest extends ModuleTestBase {
     system_list_reset();
     $this->resetAll();
 
-    // Delete every field on the site so all modules can be uninstalled. For
-    // example, if a comment field exists then module becomes required and can
-    // not be uninstalled.
+    // Delete all entities provided by modules that prevent uninstallation. For
+    // example, if any content entity exists its provider cannot be uninstalled.
+    // So deleting all taxonomy terms allows the Taxonomy to be uninstalled.
+    // Additionally, every field is deleted so modules can be uninstalled. For
+    // example, if a comment field exists then Comment cannot be uninstalled.
+    $entity_type_manager = \Drupal::entityTypeManager();
+    foreach ($entity_type_manager->getDefinitions() as $entity_type) {
+      if (($entity_type instanceof ContentEntityTypeInterface || in_array($entity_type->id(), ['field_storage_config', 'filter_format'], TRUE))
+        && !in_array($entity_type->getProvider(), ['system', 'user'], TRUE)) {
+        $storage = $entity_type_manager->getStorage($entity_type->id());
+        $storage->delete($storage->loadMultiple());
+      }
+    }
 
-    $field_storages = \Drupal::entityManager()->getStorage('field_storage_config')->loadMultiple();
-    \Drupal::entityManager()->getStorage('field_storage_config')->delete($field_storages);
-    // Purge the data.
+    // Purge the field data.
     field_purge_batch(1000);
 
-    // Delete all terms.
-    $terms = Term::loadMultiple();
-    entity_delete_multiple('taxonomy_term', array_keys($terms));
-
-    // Delete all filter formats.
-    $filters = FilterFormat::loadMultiple();
-    entity_delete_multiple('filter_format', array_keys($filters));
-
-    // Delete any shortcuts so the shortcut module can be uninstalled.
-    $shortcuts = Shortcut::loadMultiple();
-    entity_delete_multiple('shortcut', array_keys($shortcuts));
-
     system_list_reset();
     $all_modules = system_rebuild_module_data();
 
     // Ensure that only core required modules and the install profile can not be uninstalled.
     $validation_reasons = \Drupal::service('module_installer')->validateUninstall(array_keys($all_modules));
-    $this->assertEqual(['standard', 'system', 'user'], array_keys($validation_reasons));
+    $this->assertEqual(['system', 'user', 'standard'], array_keys($validation_reasons));
 
     $modules_to_uninstall = array_filter($all_modules, function ($module) use ($validation_reasons) {
       // Filter required and not enabled modules.