ConfigInstallTest.php 3.47 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\config\Tests\ConfigInstallTest.
6 7 8 9
 */

namespace Drupal\config\Tests;

10
use Drupal\simpletest\DrupalUnitTestBase;
11 12 13 14

/**
 * Tests installation of configuration objects in installation functionality.
 */
15
class ConfigInstallTest extends DrupalUnitTestBase {
16 17
  public static function getInfo() {
    return array(
18
      'name' => 'Installation functionality unit tests',
19 20 21 22 23
      'description' => 'Tests installation of configuration objects in installation functionality.',
      'group' => 'Configuration',
    );
  }

24 25 26 27 28 29 30 31
  function setUp() {
    parent::setUp();

    // Ensure the global variable being asserted by this test does not exist;
    // a previous test executed in this request/process might have set it.
    unset($GLOBALS['hook_config_test']);
  }

32 33 34 35 36
  /**
   * Tests module installation.
   */
  function testModuleInstallation() {
    $default_config = 'config_test.system';
37
    $default_configuration_entity = 'config_test.dynamic.dotted.default';
38 39

    // Verify that default module config does not exist before installation yet.
40
    $config = \Drupal::config($default_config);
41
    $this->assertIdentical($config->isNew(), TRUE);
42
    $config = \Drupal::config($default_configuration_entity);
43 44
    $this->assertIdentical($config->isNew(), TRUE);

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

49
    // Install the test module.
50 51
    $this->enableModules(array('config_test', 'config_schema_test'));
    $this->installConfig(array('config_test', 'config_schema_test'));
52

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

56
    // Verify that default module config exists.
57 58
    \Drupal::configFactory()->reset($default_config);
    \Drupal::configFactory()->reset($default_configuration_entity);
59
    $config = \Drupal::config($default_config);
60
    $this->assertIdentical($config->isNew(), FALSE);
61
    $config = \Drupal::config($default_configuration_entity);
62 63
    $this->assertIdentical($config->isNew(), FALSE);

64
    // Verify that config_test API hooks were invoked for the dynamic default
65
    // configuration entity.
66 67 68 69 70 71
    $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']));
72 73

    // Ensure that data type casting is applied during config installation.
74
    $config = \Drupal::config('config_schema_test.schema_in_install');
75 76 77
    $this->assertIdentical($config->get('integer'), 1);

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

82 83
  }
}