protected function ConfigDiffTest::assertYamlEdit in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/KernelTests/Core/Config/ConfigDiffTest.php \Drupal\KernelTests\Core\Config\ConfigDiffTest::assertYamlEdit()
- 10 core/tests/Drupal/KernelTests/Core/Config/ConfigDiffTest.php \Drupal\KernelTests\Core\Config\ConfigDiffTest::assertYamlEdit()
Helper method to test that an edit is found in a diff'd YAML file.
Parameters
array $edits: A list of edits.
string $field: The field key that is being asserted.
string $type: The type of edit that is being asserted.
mixed $orig: (optional) The original value of the edit. If not supplied, assertion is skipped.
mixed $closing: (optional) The closing value of the edit. If not supplied, assertion is skipped.
2 calls to ConfigDiffTest::assertYamlEdit()
- ConfigDiffTest::testCollectionDiff in core/
tests/ Drupal/ KernelTests/ Core/ Config/ ConfigDiffTest.php - Tests calculating the difference between two sets of config collections.
- ConfigDiffTest::testDiff in core/
tests/ Drupal/ KernelTests/ Core/ Config/ ConfigDiffTest.php - Tests calculating the difference between two sets of configuration.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Config/ ConfigDiffTest.php, line 155
Class
- ConfigDiffTest
- Calculating the difference between two sets of configuration.
Namespace
Drupal\KernelTests\Core\ConfigCode
protected function assertYamlEdit(array $edits, $field, $type, $orig = NULL, $closing = NULL) {
$match = FALSE;
foreach ($edits as $edit) {
// Choose which section to search for the field.
$haystack = $type == 'add' ? $edit->closing : $edit->orig;
// Look through each line and try and find the key.
if (is_array($haystack)) {
foreach ($haystack as $item) {
if (strpos($item, $field . ':') === 0) {
$match = TRUE;
// Assert that the edit is of the type specified.
$this
->assertEqual($edit->type, $type, "The {$field} item in the diff is a {$type}");
// If an original value was given, assert that it matches.
if (isset($orig)) {
$this
->assertIdentical($edit->orig, $orig, "The original value for key '{$field}' is correct.");
}
// If a closing value was given, assert that it matches.
if (isset($closing)) {
$this
->assertIdentical($edit->closing, $closing, "The closing value for key '{$field}' is correct.");
}
// Break out of the search entirely.
break 2;
}
}
}
}
// If we didn't match anything, fail.
if (!$match) {
$this
->fail("{$field} edit was not matched");
}
}