3 namespace Drupal\config\Tests;
5 use Drupal\simpletest\WebTestBase;
8 * Tests the importing/exporting configuration based on the install profile.
12 class ConfigImportInstallProfileTest extends WebTestBase {
15 * The profile to install as a basis for testing.
19 protected $profile = 'testing_config_import';
26 public static $modules = ['config'];
29 * A user with the 'synchronize configuration' permission.
31 * @var \Drupal\user\UserInterface
35 protected function setUp() {
38 $this->webUser = $this->drupalCreateUser(['synchronize configuration']);
39 $this->drupalLogin($this->webUser);
40 $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
44 * Tests config importer cannot uninstall install profiles.
46 * @see \Drupal\Core\EventSubscriber\ConfigImportSubscriber
48 public function testInstallProfileValidation() {
49 $sync = $this->container->get('config.storage.sync');
50 $this->copyConfig($this->container->get('config.storage'), $sync);
51 $core = $sync->read('core.extension');
53 // Ensure install profiles can not be uninstalled.
54 unset($core['module']['testing_config_import']);
55 $sync->write('core.extension', $core);
57 $this->drupalPostForm('admin/config/development/configuration', [], t('Import all'));
58 $this->assertText('The configuration cannot be imported because it failed validation for the following reasons:');
59 $this->assertText('Unable to uninstall the Testing config import profile since it is the install profile.');
61 // Uninstall dependencies of testing_config_import.
62 $core['module']['testing_config_import'] = 0;
63 unset($core['module']['syslog']);
64 unset($core['theme']['stark']);
65 $core['theme']['stable'] = 0;
66 $core['theme']['classy'] = 0;
67 $sync->write('core.extension', $core);
68 $sync->deleteAll('syslog.');
69 $theme = $sync->read('system.theme');
70 $theme['default'] = 'classy';
71 $sync->write('system.theme', $theme);
72 $this->drupalPostForm('admin/config/development/configuration', [], t('Import all'));
73 $this->assertText('The configuration was imported successfully.');
74 $this->rebuildContainer();
75 $this->assertFalse(\Drupal::moduleHandler()->moduleExists('syslog'), 'The syslog module has been uninstalled.');
76 $this->assertFalse(\Drupal::service('theme_handler')->themeExists('stark'), 'The stark theme has been uninstalled.');
77 $this->assertTrue(\Drupal::service('theme_handler')->themeExists('classy'), 'The classy theme has been installed.');