You are here

function ConfigImportUITest::testImportDiff in Zircon Profile 8

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

Tests the screen that shows differences between active and sync.

File

core/modules/config/src/Tests/ConfigImportUITest.php, line 273
Contains \Drupal\config\Tests\ConfigImportUITest.

Class

ConfigImportUITest
Tests the user interface for importing/exporting configuration.

Namespace

Drupal\config\Tests

Code

function testImportDiff() {
  $sync = $this->container
    ->get('config.storage.sync');
  $config_name = 'config_test.system';
  $change_key = 'foo';
  $remove_key = '404';
  $add_key = 'biff';
  $add_data = '<em>bangpow</em>';
  $change_data = '<p><em>foobar</em></p>';
  $original_data = array(
    'foo' => '<p>foobar</p>',
    'baz' => '<strong>no change</strong>',
    '404' => '<em>herp</em>',
  );

  // Update active storage to have html in config data.
  $this
    ->config($config_name)
    ->setData($original_data)
    ->save();

  // Change a configuration value in sync.
  $sync_data = $original_data;
  $sync_data[$change_key] = $change_data;
  $sync_data[$add_key] = $add_data;
  unset($sync_data[$remove_key]);
  $sync
    ->write($config_name, $sync_data);

  // Load the diff UI and verify that the diff reflects the change.
  $this
    ->drupalGet('admin/config/development/configuration/sync/diff/' . $config_name);
  $this
    ->assertTitle(format_string('View changes of @config_name | Drupal', array(
    '@config_name' => $config_name,
  )));

  // The following assertions do not use $this::assertEscaped() because
  // \Drupal\Component\Diff\DiffFormatter adds markup that signifies what has
  // changed.
  // Changed values are escaped.
  $this
    ->assertText(Html::escape("foo: '<p><em>foobar</em></p>'"));
  $this
    ->assertText(Html::escape("foo: '<p>foobar</p>'"));

  // The no change values are escaped.
  $this
    ->assertText(Html::escape("baz: '<strong>no change</strong>'"));

  // Added value is escaped.
  $this
    ->assertText(Html::escape("biff: '<em>bangpow</em>'"));

  // Deleted value is escaped.
  $this
    ->assertText(Html::escape("404: '<em>herp</em>'"));

  // Reset data back to original, and remove a key
  $sync_data = $original_data;
  unset($sync_data[$remove_key]);
  $sync
    ->write($config_name, $sync_data);

  // Load the diff UI and verify that the diff reflects a removed key.
  $this
    ->drupalGet('admin/config/development/configuration/sync/diff/' . $config_name);

  // The no change values are escaped.
  $this
    ->assertText(Html::escape("foo: '<p>foobar</p>'"));
  $this
    ->assertText(Html::escape("baz: '<strong>no change</strong>'"));

  // Removed key is escaped.
  $this
    ->assertText(Html::escape("404: '<em>herp</em>'"));

  // Reset data back to original and add a key
  $sync_data = $original_data;
  $sync_data[$add_key] = $add_data;
  $sync
    ->write($config_name, $sync_data);

  // Load the diff UI and verify that the diff reflects an added key.
  $this
    ->drupalGet('admin/config/development/configuration/sync/diff/' . $config_name);

  // The no change values are escaped.
  $this
    ->assertText(Html::escape("baz: '<strong>no change</strong>'"));
  $this
    ->assertText(Html::escape("404: '<em>herp</em>'"));

  // Added key is escaped.
  $this
    ->assertText(Html::escape("biff: '<em>bangpow</em>'"));
}