ConfigImportInstallProfileTest.php in Drupal 9
File
core/modules/config/tests/src/Functional/ConfigImportInstallProfileTest.php
View source
<?php
namespace Drupal\Tests\config\Functional;
use Drupal\Tests\BrowserTestBase;
class ConfigImportInstallProfileTest extends BrowserTestBase {
protected $profile = 'testing_config_import';
protected static $modules = [
'config',
];
protected $defaultTheme = 'stark';
protected $webUser;
protected function setUp() : void {
parent::setUp();
$this->webUser = $this
->drupalCreateUser([
'synchronize configuration',
]);
$this
->drupalLogin($this->webUser);
$this
->copyConfig($this->container
->get('config.storage'), $this->container
->get('config.storage.sync'));
}
public function testInstallProfileValidation() {
$sync = $this->container
->get('config.storage.sync');
$this
->copyConfig($this->container
->get('config.storage'), $sync);
$core = $sync
->read('core.extension');
unset($core['module']['testing_config_import']);
$sync
->write('core.extension', $core);
$this
->drupalGet('admin/config/development/configuration');
$this
->submitForm([], 'Import all');
$this
->assertSession()
->pageTextContains('The configuration cannot be imported because it failed validation for the following reasons:');
$this
->assertSession()
->pageTextContains('Unable to uninstall the Testing config import profile since it is the install profile.');
$core['module']['testing_config_import'] = 0;
unset($core['module']['syslog']);
unset($core['theme']['stark']);
$core['theme']['stable'] = 0;
$core['theme']['classy'] = 0;
$sync
->write('core.extension', $core);
$sync
->deleteAll('syslog.');
$theme = $sync
->read('system.theme');
$theme['default'] = 'classy';
$sync
->write('system.theme', $theme);
$this
->drupalGet('admin/config/development/configuration');
$this
->submitForm([], 'Import all');
$this
->assertSession()
->pageTextContains('The configuration was imported successfully.');
$this
->rebuildContainer();
$this
->assertFalse(\Drupal::moduleHandler()
->moduleExists('syslog'), 'The syslog module has been uninstalled.');
$this
->assertFalse(\Drupal::service('theme_handler')
->themeExists('stark'), 'The stark theme has been uninstalled.');
$this
->assertTrue(\Drupal::service('theme_handler')
->themeExists('classy'), 'The classy theme has been installed.');
}
}