1 config.test ConfigurationUITest::testDiff()

Tests the screen that shows differences between active and staging.

File

core/modules/config/tests/config.test, line 319
Tests for Configuration module.

Class

ConfigurationUITest
Tests the UI for syncing, importing, and exporting.

Code

function testDiff() {
  $staging_storage = new ConfigFileStorage(config_get_config_directory('staging'));

  $config_name = 'config_test.simple';
  $change_key = 'favorite_animal';
  $remove_key = 'favorite_color';
  $add_key = 'favorite_day';
  $add_data = 'friday';
  $change_data = 'bunnies';
  $original_data = array(
    'favorite_animal' => 'cats',
    'favorite_color' => 'blue',
  );

  // Copy all configuration to staging before modification.
  $this->copyConfig('active', 'staging');

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

  // Load the diff UI and verify that the diff reflects the changes.
  $this->backdropGet('admin/config/development/configuration/sync/diff/' . $config_name);
  $deleted_words = $this->xpath('//td[contains(@class, :class)]//del', array(':class' => 'diff-deletedline'));
  $this->assertEqual($original_data[$change_key], (string) $deleted_words[0]);
  $this->assertEqual($remove_key, (string) $deleted_words[1]);
  $this->assertEqual($original_data[$remove_key], (string) $deleted_words[2]);

  $added_words = $this->xpath('//td[contains(@class, :class)]//ins', array(':class' => 'diff-addedline'));
  $this->assertEqual($change_data, (string) $added_words[0]);
  $this->assertEqual($add_key, (string) $added_words[1]);
  $this->assertEqual($add_data, (string) $added_words[2]);
}