ConfigAfterInstallerTestBase.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Drupal\FunctionalTests\Installer;
  3. use Drupal\Core\Config\FileStorage;
  4. use Drupal\Core\Config\InstallStorage;
  5. use Drupal\Core\Config\StorageInterface;
  6. use Drupal\KernelTests\AssertConfigTrait;
  7. /**
  8. * Provides a class for install profiles to check their installed config.
  9. */
  10. abstract class ConfigAfterInstallerTestBase extends InstallerTestBase {
  11. use AssertConfigTrait;
  12. /**
  13. * Ensures that all the installed config looks like the exported one.
  14. *
  15. * @param array $skipped_config
  16. * An array of skipped config.
  17. */
  18. protected function assertInstalledConfig(array $skipped_config) {
  19. $this->addToAssertionCount(1);
  20. /** @var \Drupal\Core\Config\StorageInterface $active_config_storage */
  21. $active_config_storage = $this->container->get('config.storage');
  22. /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
  23. $config_manager = $this->container->get('config.manager');
  24. $default_install_path = 'core/profiles/' . $this->profile . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
  25. $profile_config_storage = new FileStorage($default_install_path, StorageInterface::DEFAULT_COLLECTION);
  26. foreach ($profile_config_storage->listAll() as $config_name) {
  27. $result = $config_manager->diff($profile_config_storage, $active_config_storage, $config_name);
  28. try {
  29. $this->assertConfigDiff($result, $config_name, $skipped_config);
  30. }
  31. catch (\Exception $e) {
  32. $this->fail($e->getMessage());
  33. }
  34. }
  35. }
  36. }