View source
<?php
namespace Drupal\config\Tests;
use Drupal\simpletest\WebTestBase;
class ConfigOtherModuleTest extends WebTestBase {
public function testInstallOtherModuleFirst() {
$this
->installModule('config_other_module_config_test');
$config = $this
->config('config_test.dynamic.other_module_test');
$this
->assertTrue($config
->isNew(), 'Default configuration for other modules is not installed if that module is not enabled.');
$this
->installModule('config_test');
$this
->assertTrue(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration has been installed.');
$this
->uninstallModule('config_test');
$config = $this
->config('config_test.dynamic.other_module_test');
$this
->assertTrue($config
->isNew(), 'Default configuration for other modules is removed when the config entity provider is disabled.');
$this
->installModule('config_test');
$other_module_config_entity = entity_load('config_test', 'other_module_test', TRUE);
$this
->assertTrue($other_module_config_entity, "Default configuration has been recreated.");
$other_module_config_entity
->set('style', "The piano ain't got no wrong notes.");
$other_module_config_entity
->save();
$this
->uninstallModule('config_other_module_config_test');
$this
->assertTrue(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration for other modules is not removed when the module that provides it is uninstalled.');
$this
->assertTrue(entity_load('config_test', 'dotted.default', TRUE), 'The configuration is not deleted.');
$this
->installModule('config_other_module_config_test');
$this
->assertTrue(\Drupal::moduleHandler()
->moduleExists('config_other_module_config_test'), 'The config_other_module_config_test module is installed.');
$this
->assertNull(entity_load('config_test', 'other_module_test_unmet', TRUE), 'The optional configuration whose dependencies are met is not created.');
$this
->installModule('config_install_dependency_test');
$this
->assertTrue(entity_load('config_test', 'other_module_test_unmet', TRUE), 'The optional configuration whose dependencies are met is now created.');
}
public function testInstallConfigEntityModuleFirst() {
$this
->installModule('config_test');
$this
->assertFalse(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration provided by config_other_module_config_test does not exist.');
$this
->installModule('config_other_module_config_test');
$this
->assertTrue(entity_load('config_test', 'other_module_test', TRUE), 'Default configuration provided by config_other_module_config_test has been installed.');
}
public function testUninstall() {
$this
->installModule('views');
$this
->assertTrue(entity_load('view', 'frontpage', TRUE) === NULL, 'After installing Views, frontpage view which is dependant on the Node and Views modules does not exist.');
$this
->installModule('node');
$this
->assertTrue(entity_load('view', 'frontpage', TRUE) !== NULL, 'After installing Node, frontpage view which is dependant on the Node and Views modules exists.');
$this
->uninstallModule('node');
$this
->assertTrue(entity_load('view', 'frontpage', TRUE) === NULL, 'After uninstalling Node, frontpage view which is dependant on the Node and Views modules does not exist.');
}
protected function installModule($module) {
$this->container
->get('module_installer')
->install(array(
$module,
));
$this->container = \Drupal::getContainer();
}
protected function uninstallModule($module) {
$this->container
->get('module_installer')
->uninstall(array(
$module,
));
$this->container = \Drupal::getContainer();
}
}