View source
<?php
namespace Drupal\Tests\config\Functional;
use Drupal\Core\Config\StorageComparer;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Extension\ExtensionLifecycle;
use Drupal\Tests\SchemaCheckTestTrait;
use Drupal\Tests\system\Functional\Module\ModuleTestBase;
class ConfigImportAllTest extends ModuleTestBase {
use SchemaCheckTestTrait;
protected $webUser;
protected $profile = 'standard';
protected function setUp() : void {
parent::setUp();
$this->webUser = $this
->drupalCreateUser([
'synchronize configuration',
]);
$this
->drupalLogin($this->webUser);
}
public function testInstallUninstall() {
$all_modules = $this->container
->get('extension.list.module')
->getList();
$all_modules = array_filter($all_modules, function ($module) {
if ($module->origin !== 'core' || !empty($module->info['hidden']) || $module->status == TRUE || $module->info['package'] == 'Testing' || $module->info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER] === ExtensionLifecycle::DEPRECATED) {
return FALSE;
}
return TRUE;
});
\Drupal::service('module_installer')
->install(array_keys($all_modules));
$this
->assertModules(array_keys($all_modules), TRUE);
foreach ($all_modules as $module => $info) {
$this
->assertModuleConfig($module);
$this
->assertModuleTablesExist($module);
}
$this
->copyConfig($this->container
->get('config.storage'), $this->container
->get('config.storage.sync'));
$this
->resetAll();
$entity_type_manager = \Drupal::entityTypeManager();
foreach ($entity_type_manager
->getDefinitions() as $entity_type) {
if (($entity_type instanceof ContentEntityTypeInterface || in_array($entity_type
->id(), [
'field_storage_config',
'filter_format',
], TRUE)) && !in_array($entity_type
->getProvider(), [
'system',
'user',
], TRUE)) {
$storage = $entity_type_manager
->getStorage($entity_type
->id());
$storage
->delete($storage
->loadMultiple());
}
}
field_purge_batch(1000);
$all_modules = \Drupal::service('extension.list.module')
->getList();
$database_module = \Drupal::service('database')
->getProvider();
$expected_modules = [
'path_alias',
'system',
'user',
'standard',
$database_module,
];
$validation_reasons = \Drupal::service('module_installer')
->validateUninstall(array_keys($all_modules));
$validation_modules = array_keys($validation_reasons);
$this
->assertEqualsCanonicalizing($expected_modules, $validation_modules);
$modules_to_uninstall = array_filter($all_modules, function ($module) use ($validation_reasons) {
if (!empty($module->info['required']) || $module->status == FALSE) {
return FALSE;
}
return TRUE;
});
unset($modules_to_uninstall['config']);
unset($modules_to_uninstall[$database_module]);
$this
->assertTrue(isset($modules_to_uninstall['comment']), 'The comment module will be disabled');
$this
->assertTrue(isset($modules_to_uninstall['file']), 'The File module will be disabled');
$this
->assertTrue(isset($modules_to_uninstall['editor']), 'The Editor module will be disabled');
\Drupal::service('module_installer')
->uninstall(array_keys($modules_to_uninstall));
$this
->assertModules(array_keys($modules_to_uninstall), FALSE);
foreach ($modules_to_uninstall as $module => $info) {
$this
->assertNoModuleConfig($module);
$this
->assertModuleTablesDoNotExist($module);
}
$this
->drupalGet('admin/config/development/configuration');
$this
->submitForm([], 'Import all');
$this
->rebuildContainer();
$this
->assertSame([], $this
->configImporter()
->getErrors());
$this
->assertModules(array_keys($modules_to_uninstall), TRUE);
foreach ($modules_to_uninstall as $module => $info) {
$this
->assertModuleConfig($module);
$this
->assertModuleTablesExist($module);
}
$storage_comparer = new StorageComparer($this->container
->get('config.storage.sync'), $this->container
->get('config.storage'));
$this
->assertSame($storage_comparer
->getEmptyChangelist(), $storage_comparer
->createChangelist()
->getChangelist());
$names = $this->container
->get('config.storage')
->listAll();
$typed_config = $this->container
->get('config.typed');
foreach ($names as $name) {
$config = $this
->config($name);
$this
->assertConfigSchema($typed_config, $name, $config
->get());
}
}
}