function ConfigImportTest::testNew

Tests creation of configuration during import.

File

drupal/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php, line 94
Definition of Drupal\config\Tests\ConfigImportTest.

Class

ConfigImportTest
Tests importing configuration from files into active configuration.

Namespace

Drupal\config\Tests

Code

function testNew() {
  $dynamic_name = 'config_test.dynamic.new';
  $storage = $this->container
    ->get('config.storage');
  $staging = $this->container
    ->get('config.storage.staging');

  // Verify the configuration to create does not exist yet.
  $this
    ->assertIdentical($storage
    ->exists($dynamic_name), FALSE, $dynamic_name . ' not found.');
  $this
    ->assertIdentical($staging
    ->exists($dynamic_name), FALSE, $dynamic_name . ' not found.');

  // Create new config entity.
  $original_dynamic_data = array(
    'id' => 'new',
    'uuid' => '30df59bd-7b03-4cf7-bb35-d42fc49f0651',
    'label' => 'New',
    'style' => '',
    'langcode' => 'und',
  );
  $staging
    ->write($dynamic_name, $original_dynamic_data);

  // Create manifest for new config entity.
  $manifest_data = config('manifest.config_test.dynamic')
    ->get();
  $manifest_data[$original_dynamic_data['id']]['name'] = 'config_test.dynamic.' . $original_dynamic_data['id'];
  $staging
    ->write('manifest.config_test.dynamic', $manifest_data);
  $this
    ->assertIdentical($staging
    ->exists($dynamic_name), TRUE, $dynamic_name . ' found.');

  // Import.
  config_import();

  // Verify the values appeared.
  $config = config($dynamic_name);
  $this
    ->assertIdentical($config
    ->get('label'), $original_dynamic_data['label']);

  // Verify that appropriate module API hooks have been invoked.
  $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']));

  // Verify that there is nothing more to import.
  $this
    ->assertFalse(config_sync_get_changes($staging, $storage));
}