You are here

function ConfigInstallTest::testModuleInstallation in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/config/src/Tests/ConfigInstallTest.php \Drupal\config\Tests\ConfigInstallTest::testModuleInstallation()

Tests module installation.

File

core/modules/config/src/Tests/ConfigInstallTest.php, line 43
Contains \Drupal\config\Tests\ConfigInstallTest.

Class

ConfigInstallTest
Tests installation of configuration objects in installation functionality.

Namespace

Drupal\config\Tests

Code

function testModuleInstallation() {
  $default_config = 'config_test.system';
  $default_configuration_entity = 'config_test.dynamic.dotted.default';

  // Verify that default module config does not exist before installation yet.
  $config = $this
    ->config($default_config);
  $this
    ->assertIdentical($config
    ->isNew(), TRUE);
  $config = $this
    ->config($default_configuration_entity);
  $this
    ->assertIdentical($config
    ->isNew(), TRUE);

  // Ensure that schema provided by modules that are not installed is not
  // available.
  $this
    ->assertFalse(\Drupal::service('config.typed')
    ->hasConfigSchema('config_schema_test.someschema'), 'Configuration schema for config_schema_test.someschema does not exist.');

  // Install the test module.
  $this
    ->installModules(array(
    'config_test',
  ));

  // Verify that default module config exists.
  \Drupal::configFactory()
    ->reset($default_config);
  \Drupal::configFactory()
    ->reset($default_configuration_entity);
  $config = $this
    ->config($default_config);
  $this
    ->assertIdentical($config
    ->isNew(), FALSE);
  $config = $this
    ->config($default_configuration_entity);
  $this
    ->assertIdentical($config
    ->isNew(), FALSE);

  // Verify that config_test API hooks were invoked for the dynamic default
  // configuration entity.
  $this
    ->assertFalse(isset($GLOBALS['hook_config_test']['load']));
  $this
    ->assertTrue(isset($GLOBALS['hook_config_test']['presave']));
  $this
    ->assertTrue(isset($GLOBALS['hook_config_test']['insert']));
  $this
    ->assertFalse(isset($GLOBALS['hook_config_test']['update']));
  $this
    ->assertFalse(isset($GLOBALS['hook_config_test']['predelete']));
  $this
    ->assertFalse(isset($GLOBALS['hook_config_test']['delete']));

  // Install the schema test module.
  $this
    ->enableModules(array(
    'config_schema_test',
  ));
  $this
    ->installConfig(array(
    'config_schema_test',
  ));

  // After module installation the new schema should exist.
  $this
    ->assertTrue(\Drupal::service('config.typed')
    ->hasConfigSchema('config_schema_test.someschema'), 'Configuration schema for config_schema_test.someschema exists.');

  // Test that uninstalling configuration removes configuration schema.
  $this
    ->config('core.extension')
    ->set('module', array())
    ->save();
  \Drupal::service('config.manager')
    ->uninstall('module', 'config_test');
  $this
    ->assertFalse(\Drupal::service('config.typed')
    ->hasConfigSchema('config_schema_test.someschema'), 'Configuration schema for config_schema_test.someschema does not exist.');
}