コード例 #1
0
 /**
  * Create test views from config.
  *
  * @param string $class
  *   The name of the test class.
  * @param array $modules
  *   The module directories to look in for test views.
  */
 public static function createTestViews($class, array $modules)
 {
     $views = array();
     while ($class) {
         if (property_exists($class, 'testViews')) {
             $views = array_merge($views, $class::$testViews);
         }
         $class = get_parent_class($class);
     }
     if (!empty($views)) {
         $storage = \Drupal::entityManager()->getStorage('view');
         $module_handler = \Drupal::moduleHandler();
         foreach ($modules as $module) {
             $config_dir = drupal_get_path('module', $module) . '/test_views';
             if (!is_dir($config_dir) || !$module_handler->moduleExists($module)) {
                 continue;
             }
             $file_storage = new FileStorage($config_dir);
             foreach ($file_storage->listAll('views.view.') as $config_name) {
                 $id = str_replace('views.view.', '', $config_name);
                 if (in_array($id, $views)) {
                     $storage->create($file_storage->read($config_name))->save();
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: DefaultConfigTest.php プロジェクト: ddrozdik/dmaps
 /**
  * Tests if installed config is equal to the exported config.
  *
  * @dataProvider providerTestModuleConfig
  */
 public function testModuleConfig($module)
 {
     /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
     $module_installer = $this->container->get('module_installer');
     /** @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');
     $module_installer->install([$module]);
     // System and user are required in order to be able to install some of the
     // other modules. Therefore they are put into static::$modules, which though
     // doesn't install config files, so import those config files explicitly.
     switch ($module) {
         case 'system':
         case 'user':
             $this->installConfig([$module]);
             break;
     }
     $default_install_path = drupal_get_path('module', $module) . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
     $module_config_storage = new FileStorage($default_install_path, StorageInterface::DEFAULT_COLLECTION);
     // The following config entries are changed on module install, so compare
     // them doesn't make sense.
     $skipped_config = [];
     $skipped_config['locale.settings'][] = 'path: ';
     $skipped_config['syslog.settings'][] = 'facility: ';
     // @todo Figure out why simpletest.settings is not installed.
     $skipped_config['simpletest.settings'] = TRUE;
     // Compare the installed config with the one in the module directory.
     foreach ($module_config_storage->listAll() as $config_name) {
         $result = $config_manager->diff($module_config_storage, $active_config_storage, $config_name);
         $this->assertConfigDiff($result, $config_name, $skipped_config);
     }
 }
コード例 #3
0
 /**
  * Create test views from config.
  *
  * @param string $class
  *   The name of the test class. Installs the listed test views *in order*.
  * @param array $modules
  *   The module directories to look in for test views.
  */
 public static function createTestViews($class, array $modules)
 {
     $views = array();
     while ($class) {
         if (property_exists($class, 'testViews')) {
             $views = array_merge($views, $class::$testViews);
         }
         $class = get_parent_class($class);
     }
     if (!empty($views)) {
         $storage = \Drupal::entityManager()->getStorage('view');
         $module_handler = \Drupal::moduleHandler();
         foreach ($modules as $module) {
             $config_dir = drupal_get_path('module', $module) . '/test_views';
             if (!is_dir($config_dir) || !$module_handler->moduleExists($module)) {
                 continue;
             }
             $file_storage = new FileStorage($config_dir);
             $available_views = $file_storage->listAll('views.view.');
             foreach ($views as $id) {
                 $config_name = 'views.view.' . $id;
                 if (in_array($config_name, $available_views)) {
                     $storage->create($file_storage->read($config_name))->save();
                 }
             }
         }
     }
     // Rebuild the router once.
     \Drupal::service('router.builder')->rebuild();
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $file_upload = $this->getRequest()->files->get('files[import_tarball]', NULL, TRUE);
     $has_upload = FALSE;
     if ($file_upload && $file_upload->isValid()) {
         // The sync directory must be empty if we are doing an upload.
         $form_state->setValue('import_tarball', $file_upload->getRealPath());
         $has_upload = TRUE;
     }
     $sync_directory = $form_state->getValue('sync_directory');
     // If we've customised the sync directory ensure its good to go.
     if ($sync_directory != config_get_config_directory(CONFIG_SYNC_DIRECTORY)) {
         // Ensure it exists and is writeable.
         if (!file_prepare_directory($sync_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
             $form_state->setErrorByName('sync_directory', t('The directory %directory could not be created or could not be made writable. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see the <a href="@handbook_url">online handbook</a>.', array('%directory' => $sync_directory, '@handbook_url' => 'http://drupal.org/server-permissions')));
         }
     }
     // If no tarball ensure we have files.
     if (!$form_state->hasAnyErrors() && !$has_upload) {
         $sync = new FileStorage($sync_directory);
         if (count($sync->listAll()) === 0) {
             $form_state->setErrorByName('sync_directory', t('No file upload provided and the sync directory is empty'));
         }
     }
 }
コード例 #5
0
 /**
  * Tests the FileStorage::listAll method with a relative and absolute path.
  */
 public function testlistAll()
 {
     $expected_files = array('core.extension', 'system.performance');
     $config_files = $this->storage->listAll();
     $this->assertIdentical($config_files, $expected_files, 'Relative path, two config files found.');
     // Initialize FileStorage with absolute file path.
     $absolute_path = realpath($this->directory);
     $storage_absolute_path = new FileStorage($absolute_path);
     $config_files = $storage_absolute_path->listAll();
     $this->assertIdentical($config_files, $expected_files, 'Absolute path, two config files found.');
 }
コード例 #6
0
ファイル: FileStorageTest.php プロジェクト: frankcr/sftw8
 /**
  * Tests the FileStorage::listAll method with a relative and absolute path.
  */
 public function testlistAll()
 {
     $expected_files = array('core.extension', 'system.performance');
     $config_files = $this->storage->listAll();
     $this->assertIdentical($config_files, $expected_files, 'Relative path, two config files found.');
     // @todo https://www.drupal.org/node/2666954 FileStorage::listAll() is
     //   case-sensitive. However, \Drupal\Core\Config\DatabaseStorage::listAll()
     //   is case-insensitive.
     $this->assertIdentical(['system.performance'], $this->storage->listAll('system'), 'The FileStorage::listAll() with prefix works.');
     $this->assertIdentical([], $this->storage->listAll('System'), 'The FileStorage::listAll() is case sensitive.');
     // Initialize FileStorage with absolute file path.
     $absolute_path = realpath($this->directory);
     $storage_absolute_path = new FileStorage($absolute_path);
     $config_files = $storage_absolute_path->listAll();
     $this->assertIdentical($config_files, $expected_files, 'Absolute path, two config files found.');
 }
コード例 #7
0
 /**
  * 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)
 {
     /** @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());
         }
     }
 }
コード例 #8
0
 /**
  * Tests if installed config is equal to the exported config.
  *
  * @dataProvider providerTestModuleConfig
  */
 public function testModuleConfig($module)
 {
     // System and user are required in order to be able to install some of the
     // other modules. Therefore they are put into static::$modules, which though
     // doesn't install config files, so import those config files explicitly.
     switch ($module) {
         case 'system':
         case 'user':
             $this->installConfig([$module]);
             break;
     }
     $module_path = drupal_get_path('module', $module) . '/';
     /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */
     $module_installer = $this->container->get('module_installer');
     // @todo https://www.drupal.org/node/2308745 Rest has an implicit dependency
     //   on the Node module remove once solved.
     if (in_array($module, ['rest', 'hal'])) {
         $module_installer->install(['node']);
     }
     // Work out any additional modules and themes that need installing to create
     // and optional config.
     $optional_config_storage = new FileStorage($module_path . InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION);
     $modules_to_install = [$module];
     $themes_to_install = [];
     foreach ($optional_config_storage->listAll() as $config_name) {
         $data = $optional_config_storage->read($config_name);
         if (isset($data['dependencies']['module'])) {
             $modules_to_install = array_merge($modules_to_install, $data['dependencies']['module']);
         }
         if (isset($data['dependencies']['theme'])) {
             $themes_to_install = array_merge($themes_to_install, $data['dependencies']['theme']);
         }
     }
     $module_installer->install(array_unique($modules_to_install));
     $this->container->get('theme_installer')->install($themes_to_install);
     // Test configuration in the module's config/install directory.
     $module_config_storage = new FileStorage($module_path . InstallStorage::CONFIG_INSTALL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION);
     $this->doTestsOnConfigStorage($module_config_storage);
     // Test configuration in the module's config/optional directory.
     $this->doTestsOnConfigStorage($optional_config_storage);
 }
コード例 #9
0
ファイル: ConfigInstaller.php プロジェクト: dmyerson/d8ecs
 /**
  * {@inheritdoc}
  */
 public function installOptionalConfig(StorageInterface $storage = NULL, $dependency = [])
 {
     $profile = $this->drupalGetProfile();
     $optional_profile_config = [];
     if (!$storage) {
         // Search the install profile's optional configuration too.
         $storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, TRUE);
         // The extension install storage ensures that overrides are used.
         $profile_storage = NULL;
     } elseif (isset($profile)) {
         // Creates a profile storage to search for overrides.
         $profile_install_path = $this->drupalGetPath('module', $profile) . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
         $profile_storage = new FileStorage($profile_install_path, StorageInterface::DEFAULT_COLLECTION);
         $optional_profile_config = $profile_storage->listAll();
     } else {
         // Profile has not been set yet. For example during the first steps of the
         // installer or during unit tests.
         $profile_storage = NULL;
     }
     $enabled_extensions = $this->getEnabledExtensions();
     $existing_config = $this->getActiveStorages()->listAll();
     $list = array_unique(array_merge($storage->listAll(), $optional_profile_config));
     $list = array_filter($list, function ($config_name) use($existing_config) {
         // Only list configuration that:
         // - does not already exist
         // - is a configuration entity (this also excludes config that has an
         //   implicit dependency on modules that are not yet installed)
         return !in_array($config_name, $existing_config) && $this->configManager->getEntityTypeIdByName($config_name);
     });
     $all_config = array_merge($existing_config, $list);
     $config_to_create = $storage->readMultiple($list);
     // Check to see if the corresponding override storage has any overrides or
     // new configuration that can be installed.
     if ($profile_storage) {
         $config_to_create = $profile_storage->readMultiple($list) + $config_to_create;
     }
     foreach ($config_to_create as $config_name => $data) {
         // Exclude configuration where its dependencies cannot be met.
         if (!$this->validateDependencies($config_name, $data, $enabled_extensions, $all_config)) {
             unset($config_to_create[$config_name]);
         } elseif (!empty($dependency)) {
             // Create a light weight dependency object to check dependencies.
             $config_entity = new ConfigEntityDependency($config_name, $data);
             if (!$config_entity->hasDependency(key($dependency), reset($dependency))) {
                 unset($config_to_create[$config_name]);
             }
         }
     }
     if (!empty($config_to_create)) {
         $this->createConfiguration(StorageInterface::DEFAULT_COLLECTION, $config_to_create, TRUE);
     }
 }
コード例 #10
0
 /**
  * Asserts that the default configuration of a module has been installed.
  *
  * @param string $module
  *   The name of the module.
  *
  * @return bool
  *   TRUE if configuration has been installed, FALSE otherwise.
  */
 function assertModuleConfig($module)
 {
     $module_config_dir = drupal_get_path('module', $module) . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
     if (!is_dir($module_config_dir)) {
         return;
     }
     $module_file_storage = new FileStorage($module_config_dir);
     // Verify that the module's default config directory is not empty and
     // contains default configuration files (instead of something else).
     $all_names = $module_file_storage->listAll();
     if (empty($all_names)) {
         // Module has an empty config directory. For example it might contain a
         // schema directory.
         return;
     }
     $this->assertTrue($all_names);
     // Look up each default configuration object name in the active
     // configuration, and if it exists, remove it from the stack.
     // Only default config that belongs to $module is guaranteed to exist; any
     // other default config depends on whether other modules are enabled. Thus,
     // list all default config once more, but filtered by $module.
     $names = $module_file_storage->listAll($module . '.');
     foreach ($names as $key => $name) {
         if ($this->config($name)->get()) {
             unset($names[$key]);
         }
     }
     // Verify that all configuration has been installed (which means that $names
     // is empty).
     return $this->assertFalse($names, format_string('All default configuration of @module module found.', array('@module' => $module)));
 }
コード例 #11
0
 /**
  * Installs default configuration for a particular collection.
  *
  * @param string $collection
  *  The configuration collection to install.
  * @param string $type
  *   The extension type; e.g., 'module' or 'theme'.
  * @param string $name
  *   The name of the module or theme to install default configuration for.
  * @param array $enabled_extensions
  *   A list of all the currently enabled modules and themes.
  *
  * @return array
  *   The list of configuration objects to create.
  */
 protected function listDefaultConfigCollection($collection, $type, $name, array $enabled_extensions)
 {
     // Get all default configuration owned by this extension.
     $source_storage = $this->getSourceStorage($collection);
     $config_to_install = $source_storage->listAll($name . '.');
     // If not installing the core base system default configuration, work out if
     // this extension provides default configuration for any other enabled
     // extensions.
     $extension_path = drupal_get_path($type, $name);
     if ($type !== 'core' && is_dir($extension_path . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY)) {
         $default_storage = new FileStorage($extension_path . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY, $collection);
         $other_module_config = array_filter($default_storage->listAll(), function ($value) use($name) {
             return !preg_match('/^' . $name . '\\./', $value);
         });
         $other_module_config = array_filter($other_module_config, function ($config_name) use($enabled_extensions) {
             $provider = Unicode::substr($config_name, 0, strpos($config_name, '.'));
             return in_array($provider, $enabled_extensions);
         });
         $config_to_install = array_merge($config_to_install, $other_module_config);
     }
     return $config_to_install;
 }
コード例 #12
0
 /**
  * Returns a list of configuration items provided by the install profile.
  */
 protected function listInstallProfileConfig()
 {
     static $item_names = NULL;
     if (!isset($item_names)) {
         $config_path = drupal_get_path('profile', drupal_get_profile()) . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
         if (is_dir($config_path)) {
             $install_storage = new FileStorage($config_path);
             $item_names = $install_storage->listAll();
         } else {
             $item_names = array();
         }
     }
     return $item_names;
 }