function ConfigDiffTest::testCollectionDiff in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/config/src/Tests/ConfigDiffTest.php \Drupal\config\Tests\ConfigDiffTest::testCollectionDiff()
Tests calculating the difference between two sets of config collections.
File
- core/
modules/ config/ src/ Tests/ ConfigDiffTest.php, line 119 - Contains \Drupal\config\Tests\ConfigDiffTest.
Class
- ConfigDiffTest
- Calculating the difference between two sets of configuration.
Namespace
Drupal\config\TestsCode
function testCollectionDiff() {
/** @var \Drupal\Core\Config\StorageInterface $active */
$active = $this->container
->get('config.storage');
/** @var \Drupal\Core\Config\StorageInterface $sync */
$sync = $this->container
->get('config.storage.sync');
$active_test_collection = $active
->createCollection('test');
$sync_test_collection = $sync
->createCollection('test');
$config_name = 'config_test.test';
$data = array(
'foo' => 'bar',
);
$active
->write($config_name, $data);
$sync
->write($config_name, $data);
$active_test_collection
->write($config_name, $data);
$sync_test_collection
->write($config_name, array(
'foo' => 'baz',
));
// Test the fields match in the default collection diff.
$diff = \Drupal::service('config.manager')
->diff($active, $sync, $config_name);
$edits = $diff
->getEdits();
$this
->assertEqual($edits[0]->type, 'copy', 'The first item in the diff is a copy.');
$this
->assertEqual(count($edits), 1, 'There is one item in the diff');
// Test that the differences are detected when diffing the collection.
$diff = \Drupal::service('config.manager')
->diff($active, $sync, $config_name, NULL, 'test');
$edits = $diff
->getEdits();
$this
->assertEqual($edits[0]->type, 'change', 'The second item in the diff is a copy.');
$this
->assertEqual($edits[0]->orig, array(
'foo: bar',
));
$this
->assertEqual($edits[0]->closing, array(
'foo: baz',
));
$this
->assertEqual($edits[1]->type, 'copy', 'The second item in the diff is a copy.');
}