diff core/tests/Drupal/FunctionalTests/Installer/ConfigAfterInstallerTestBase.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/tests/Drupal/FunctionalTests/Installer/ConfigAfterInstallerTestBase.php	Thu Jul 05 14:24:15 2018 +0000
@@ -0,0 +1,44 @@
+<?php
+
+namespace Drupal\FunctionalTests\Installer;
+
+use Drupal\Core\Config\FileStorage;
+use Drupal\Core\Config\InstallStorage;
+use Drupal\Core\Config\StorageInterface;
+use Drupal\KernelTests\AssertConfigTrait;
+
+/**
+ * Provides a class for install profiles to check their installed config.
+ */
+abstract class ConfigAfterInstallerTestBase extends InstallerTestBase {
+
+  use AssertConfigTrait;
+
+  /**
+   * Ensures that all the installed config looks like the exported one.
+   *
+   * @param array $skipped_config
+   *   An array of skipped config.
+   */
+  protected function assertInstalledConfig(array $skipped_config) {
+    $this->addToAssertionCount(1);
+    /** @var \Drupal\Core\Config\StorageInterface $active_config_storage */
+    $active_config_storage = $this->container->get('config.storage');
+    /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
+    $config_manager = $this->container->get('config.manager');
+
+    $default_install_path = 'core/profiles/' . $this->profile . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
+    $profile_config_storage = new FileStorage($default_install_path, StorageInterface::DEFAULT_COLLECTION);
+
+    foreach ($profile_config_storage->listAll() as $config_name) {
+      $result = $config_manager->diff($profile_config_storage, $active_config_storage, $config_name);
+      try {
+        $this->assertConfigDiff($result, $config_name, $skipped_config);
+      }
+      catch (\Exception $e) {
+        $this->fail($e->getMessage());
+      }
+    }
+  }
+
+}