// Set the event listener to return three possible collections.
// @see \Drupal\config_collection_install_test\EventSubscriber
\Drupal::
state()->
set('config_collection_install_test.collection_names',
$collections);
// Install the test module.
$this->
enableModules(['config_collection_install_test'
]);
$this->
installConfig(['config_collection_install_test'
]);
/** @var \Drupal\Core\Config\StorageInterface $active_storage */
$active_storage = \Drupal::
service('config.storage'
);
$this->
assertEquals($collections,
$active_storage->
getAllCollectionNames());
foreach ($collections as $collection) { $collection_storage =
$active_storage->
createCollection($collection);
$data =
$collection_storage->
read('config_collection_install_test.test'
);
$this->
assertEquals($collection,
$data['collection'
]);
} // Tests that clashing configuration in collections is detected.
try { \Drupal::
service('module_installer'
)->
install(['config_collection_clash_install_test'
]);
$this->
fail('Expected PreExistingConfigException not thrown.'
);
} catch (PreExistingConfigException
$e) { $this->
assertEquals('config_collection_clash_install_test',
$e->
getExtension());