View source
<?php
namespace Drupal\config\Tests;
use Drupal\Core\Config\PreExistingConfigException;
use Drupal\Core\Config\StorageInterface;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase;
class ConfigInstallWebTest extends WebTestBase {
protected $adminUser;
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser(array(
'administer modules',
'administer themes',
));
unset($GLOBALS['hook_config_test']);
}
function testIntegrationModuleReinstallation() {
$default_config = 'config_integration_test.settings';
$default_configuration_entity = 'config_test.dynamic.config_integration_test';
\Drupal::service('module_installer')
->install(array(
'config_test',
));
$config_static = $this
->config($default_config);
$this
->assertIdentical($config_static
->isNew(), TRUE);
$config_entity = $this
->config($default_configuration_entity);
$this
->assertIdentical($config_entity
->isNew(), TRUE);
\Drupal::service('module_installer')
->install(array(
'config_integration_test',
));
\Drupal::configFactory()
->reset($default_config);
\Drupal::configFactory()
->reset($default_configuration_entity);
$config_static = $this
->config($default_config);
$this
->assertIdentical($config_static
->isNew(), FALSE);
$this
->assertIdentical($config_static
->get('foo'), 'default setting');
$config_entity = $this
->config($default_configuration_entity);
$this
->assertIdentical($config_entity
->isNew(), FALSE);
$this
->assertIdentical($config_entity
->get('label'), 'Default integration config label');
$config_static
->set('foo', 'customized setting')
->save();
$config_entity
->set('label', 'Customized integration config label')
->save();
$this->container
->get('config.factory')
->reset();
$this->container
->get('module_installer')
->uninstall(array(
'config_integration_test',
));
$config_static = $this
->config($default_config);
$this
->assertIdentical($config_static
->isNew(), TRUE);
$config_entity = $this
->config($default_configuration_entity);
$this
->assertIdentical($config_entity
->isNew(), FALSE);
$this
->assertIdentical($config_entity
->get('label'), 'Customized integration config label');
try {
\Drupal::service('module_installer')
->install(array(
'config_integration_test',
));
$this
->fail('Expected PreExistingConfigException not thrown.');
} catch (PreExistingConfigException $e) {
$this
->assertEqual($e
->getExtension(), 'config_integration_test');
$this
->assertEqual($e
->getConfigObjects(), [
StorageInterface::DEFAULT_COLLECTION => [
'config_test.dynamic.config_integration_test',
],
]);
$this
->assertEqual($e
->getMessage(), 'Configuration objects (config_test.dynamic.config_integration_test) provided by config_integration_test already exist in active configuration');
}
$config_entity
->delete();
\Drupal::service('module_installer')
->install(array(
'config_integration_test',
));
\Drupal::configFactory()
->reset($default_config);
\Drupal::configFactory()
->reset($default_configuration_entity);
$config_static = $this
->config($default_config);
$this
->assertIdentical($config_static
->isNew(), FALSE);
$this
->assertIdentical($config_static
->get('foo'), 'default setting');
$config_entity = \Drupal::config($default_configuration_entity);
$this
->assertIdentical($config_entity
->isNew(), FALSE);
$this
->assertIdentical($config_entity
->get('label'), 'Default integration config label');
}
public function testPreExistingConfigInstall() {
$this
->drupalLogin($this->adminUser);
$this
->drupalPostForm('admin/modules', array(
'modules[Testing][config_test][enable]' => TRUE,
'modules[Testing][config_install_fail_test][enable]' => TRUE,
), t('Install'));
$this
->assertRaw('Unable to install Configuration install fail test, <em class="placeholder">config_test.dynamic.dotted.default</em> already exists in active configuration.');
$this
->drupalPostForm('admin/modules/uninstall', array(
'uninstall[config_test]' => TRUE,
), t('Uninstall'));
$this
->drupalPostForm(NULL, array(), t('Uninstall'));
$this
->drupalPostForm('admin/modules', array(
'modules[Testing][config_install_fail_test][enable]' => TRUE,
), t('Install'));
$this
->drupalPostForm(NULL, array(), t('Continue'));
$this
->assertRaw('Unable to install Configuration install fail test, <em class="placeholder">config_test.dynamic.dotted.default</em> already exists in active configuration.');
\Drupal::service('module_installer')
->install([
'language',
]);
$this
->rebuildContainer();
ConfigurableLanguage::createFromLangcode('fr')
->save();
\Drupal::languageManager()
->getLanguageConfigOverride('fr', 'config_test.dynamic.dotted.default')
->set('label', 'Je suis Charlie')
->save();
$this
->drupalPostForm('admin/modules', array(
'modules[Testing][config_install_fail_test][enable]' => TRUE,
), t('Install'));
$this
->assertRaw('Unable to install Configuration install fail test, <em class="placeholder">config_test.dynamic.dotted.default, language/fr/config_test.dynamic.dotted.default</em> already exist in active configuration.');
$this
->drupalGet('admin/appearance');
$url = $this
->xpath("//a[contains(@href,'config_clash_test_theme') and contains(@href,'/install?')]/@href")[0];
$this
->drupalGet($this
->getAbsoluteUrl($url));
$this
->assertRaw('Unable to install config_clash_test_theme, <em class="placeholder">config_test.dynamic.dotted.default, language/fr/config_test.dynamic.dotted.default</em> already exist in active configuration.');
try {
\Drupal::service('theme_handler')
->install([
'config_clash_test_theme',
]);
$this
->fail('Expected PreExistingConfigException not thrown.');
} catch (PreExistingConfigException $e) {
$this
->assertEqual($e
->getExtension(), 'config_clash_test_theme');
$this
->assertEqual($e
->getConfigObjects(), [
StorageInterface::DEFAULT_COLLECTION => [
'config_test.dynamic.dotted.default',
],
'language.fr' => [
'config_test.dynamic.dotted.default',
],
]);
$this
->assertEqual($e
->getMessage(), 'Configuration objects (config_test.dynamic.dotted.default, language/fr/config_test.dynamic.dotted.default) provided by config_clash_test_theme already exist in active configuration');
}
}
public function testUnmetDependenciesInstall() {
$this
->drupalLogin($this->adminUser);
$this
->drupalPostForm('admin/modules', array(
'modules[Testing][config_test][enable]' => TRUE,
), t('Install'));
$this
->drupalPostForm('admin/modules', array(
'modules[Testing][config_install_dependency_test][enable]' => TRUE,
), t('Install'));
$this
->assertRaw('Unable to install Config install dependency test, <em class="placeholder">config_test.dynamic.other_module_test_with_dependency</em> has unmet dependencies.');
$this
->drupalPostForm('admin/modules', array(
'modules[Testing][config_other_module_config_test][enable]' => TRUE,
), t('Install'));
$this
->drupalPostForm('admin/modules', array(
'modules[Testing][config_install_dependency_test][enable]' => TRUE,
), t('Install'));
$this
->rebuildContainer();
$this
->assertTrue(entity_load('config_test', 'other_module_test_with_dependency'), 'The config_test.dynamic.other_module_test_with_dependency configuration has been created during install.');
}
}