Imports test views from config.
string $class: The name of the test class.
array $modules: (optional) The module directories to look in for test views. Defaults to an empty array.
config_install_default_config()
public static function importTestViews($class, $modules = array()) {
$views = array();
while ($class) {
if (property_exists($class, 'testViews')) {
$views = array_merge($views, $class::$testViews);
}
$class = get_parent_class($class);
}
if (!empty($views)) {
$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;
}
$source_storage = new FileStorage($config_dir);
// Only import views used by test.
$views_to_import = array();
foreach ($source_storage
->listAll('views.view.') as $config_name) {
$id = str_replace('views.view.', '', $config_name);
if (in_array($id, $views)) {
$views_to_import[] = $config_name;
}
}
$storage_comparer = new StorageComparer($source_storage, \Drupal::service('config.storage'));
$storage_comparer
->addChangelist('create', $views_to_import);
$installer = new ViewTestConfigInstaller($storage_comparer, \Drupal::service('event_dispatcher'), \Drupal::service('config.factory'), \Drupal::entityManager(), \Drupal::lock());
$installer
->import();
}
}
}