function ConfigImportUITest::testImport

Tests importing configuration.

File

drupal/core/modules/config/lib/Drupal/config/Tests/ConfigImportUITest.php, line 38
Definition of Drupal\config\Tests\ConfigImportUITest.

Class

ConfigImportUITest
Tests importing configuration from files into active store.

Namespace

Drupal\config\Tests

Code

function testImport() {
  $name = 'system.site';
  $dynamic_name = 'config_test.dynamic.new';
  $storage = $this->container
    ->get('config.storage');
  $staging = $this->container
    ->get('config.storage.staging');
  $this
    ->drupalGet('admin/config/development/sync');
  $this
    ->assertText('There are no configuration changes.');
  $this
    ->assertNoFieldById('edit-submit', t('Import all'));

  // Create updated configuration object.
  $new_site_name = 'Config import test ' . $this
    ->randomString();
  $this
    ->prepareSiteNameUpdate($new_site_name);
  $this
    ->assertIdentical($staging
    ->exists($name), TRUE, $name . ' found.');

  // Create new config entity.
  $original_dynamic_data = array(
    'id' => 'new',
    'uuid' => '30df59bd-7b03-4cf7-bb35-d42fc49f0651',
    'label' => 'New',
    'weight' => '0',
    'style' => '',
    'status' => '1',
    'langcode' => language_default()->langcode,
    'protected_property' => '',
  );
  $staging
    ->write($dynamic_name, $original_dynamic_data);
  $this
    ->assertIdentical($staging
    ->exists($dynamic_name), TRUE, $dynamic_name . ' found.');

  // Verify that both appear as ready to import.
  $this
    ->drupalGet('admin/config/development/sync');
  $this
    ->assertText($name);
  $this
    ->assertText($dynamic_name);
  $this
    ->assertFieldById('edit-submit', t('Import all'));

  // Import and verify that both do not appear anymore.
  $this
    ->drupalPost(NULL, array(), t('Import all'));
  $this
    ->assertNoText($name);
  $this
    ->assertNoText($dynamic_name);
  $this
    ->assertNoFieldById('edit-submit', t('Import all'));

  // Verify that there are no further changes to import.
  $this
    ->assertText(t('There are no configuration changes.'));

  // Verify site name has changed.
  $this
    ->assertIdentical($new_site_name, config('system.site')
    ->get('name'));

  // Verify that new config entity exists.
  $this
    ->assertIdentical($original_dynamic_data, config($dynamic_name)
    ->get());

  // Verify the cache got cleared.
  $this
    ->assertTrue(isset($GLOBALS['hook_cache_flush']));
}