function ConfigImportUITest::testImportDiff
Same name in other branches
- 8.9.x core/modules/config/tests/src/Functional/ConfigImportUITest.php \Drupal\Tests\config\Functional\ConfigImportUITest::testImportDiff()
- 10 core/modules/config/tests/src/Functional/ConfigImportUITest.php \Drupal\Tests\config\Functional\ConfigImportUITest::testImportDiff()
- 11.x core/modules/config/tests/src/Functional/ConfigImportUITest.php \Drupal\Tests\config\Functional\ConfigImportUITest::testImportDiff()
Tests the screen that shows differences between active and sync.
File
-
core/
modules/ config/ tests/ src/ Functional/ ConfigImportUITest.php, line 284
Class
- ConfigImportUITest
- Tests the user interface for importing configuration.
Namespace
Drupal\Tests\config\FunctionalCode
public 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 = [
'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->assertSession()
->responseNotContains('&nbsp;');
$this->assertSession()
->titleEquals("View changes of {$config_name} | Drupal");
// The following assertions do not use
// $this->assertSession()->assertEscaped() because
// \Drupal\Component\Diff\DiffFormatter adds markup that signifies what has
// changed.
// Changed values are escaped.
$this->assertSession()
->pageTextContains("foo: '<p><em>foobar</em></p>'");
$this->assertSession()
->pageTextContains("foo: '<p>foobar</p>'");
// The no change values are escaped.
$this->assertSession()
->pageTextContains("baz: '<strong>no change</strong>'");
// Added value is escaped.
$this->assertSession()
->pageTextContains("biff: '<em>bangpow</em>'");
// Deleted value is escaped.
$this->assertSession()
->pageTextContains("404: '<em>herp</em>'");
// Verify diff colors are displayed.
$this->assertSession()
->elementsCount('xpath', '//table[contains(@class, "diff")]', 1);
// 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->assertSession()
->pageTextContains("foo: '<p>foobar</p>'");
$this->assertSession()
->pageTextContains("baz: '<strong>no change</strong>'");
// Removed key is escaped.
$this->assertSession()
->pageTextContains("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->assertSession()
->pageTextContains("baz: '<strong>no change</strong>'");
$this->assertSession()
->pageTextContains("404: '<em>herp</em>'");
// Added key is escaped.
$this->assertSession()
->pageTextContains("biff: '<em>bangpow</em>'");
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.