namespace Drupal\KernelTests\Core\Config;
use Drupal\Component\Utility\Html;
-use Drupal\Component\Utility\SafeMarkup;
+use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Config\ConfigImporterException;
use Drupal\Core\Config\StorageComparer;
*/
class ConfigImporterTest extends KernelTestBase {
+ /**
+ * The beginning of an import validation error.
+ */
+ const FAIL_MESSAGE = 'There were errors validating the config synchronization.';
+
/**
* Config Importer object used for testing.
*
protected function setUp() {
parent::setUp();
- $this->installConfig(['config_test']);
+ $this->installConfig(['system', 'config_test']);
// Installing config_test's default configuration pollutes the global
// variable being used for recording hook invocations by this test already,
// so it has to be cleared out manually.
$this->fail('ConfigImporterException not thrown, invalid import was not stopped due to mis-matching site UUID.');
}
catch (ConfigImporterException $e) {
- $this->assertEqual($e->getMessage(), 'There were errors validating the config synchronization.');
- $error_log = $this->configImporter->getErrors();
- $expected = ['Site UUID in source storage does not match the target storage.'];
- $this->assertEqual($expected, $error_log);
+ $actual_message = $e->getMessage();
+
+ $actual_error_log = $this->configImporter->getErrors();
+ $expected_error_log = ['Site UUID in source storage does not match the target storage.'];
+ $this->assertEqual($actual_error_log, $expected_error_log);
+
+ $expected = static::FAIL_MESSAGE . PHP_EOL . 'Site UUID in source storage does not match the target storage.';
+ $this->assertEquals($expected, $actual_message);
+ foreach ($expected_error_log as $log_row) {
+ $this->assertTrue(preg_match("/$log_row/", $actual_message));
+ }
}
}
// Add a dependency on primary, to ensure that is synced first.
'dependencies' => [
'config' => [$name_primary],
- ]
+ ],
];
$sync->write($name_secondary, $values_secondary);
$logs = $this->configImporter->getErrors();
$this->assertEqual(count($logs), 1);
- $this->assertEqual($logs[0], SafeMarkup::format('Deleted and replaced configuration entity "@name"', ['@name' => $name_secondary]));
+ $this->assertEqual($logs[0], new FormattableMarkup('Deleted and replaced configuration entity "@name"', ['@name' => $name_secondary]));
}
/**
// Add a dependency on secondary, so that is synced first.
'dependencies' => [
'config' => [$name_secondary],
- ]
+ ],
];
$sync->write($name_primary, $values_primary);
$values_secondary = [
// Add a dependency on deleter, to make sure that is synced first.
'dependencies' => [
'config' => [$name_deleter],
- ]
+ ],
];
$storage->write($name_deletee, $values_deletee);
$values_deletee['label'] = 'Updated Deletee';
// will also be synced after the deletee due to alphabetical ordering.
'dependencies' => [
'config' => [$name_deleter],
- ]
+ ],
];
$storage->write($name_other, $values_other);
$values_other['label'] = 'Updated other';
$logs = $this->configImporter->getErrors();
$this->assertEqual(count($logs), 1);
- $this->assertEqual($logs[0], SafeMarkup::format('Update target "@name" is missing.', ['@name' => $name_deletee]));
+ $this->assertEqual($logs[0], new FormattableMarkup('Update target "@name" is missing.', ['@name' => $name_deletee]));
}
/**
$this->fail('ConfigImporterException not thrown; an invalid import was not stopped due to missing dependencies.');
}
catch (ConfigImporterException $e) {
- $this->assertEqual($e->getMessage(), 'There were errors validating the config synchronization.');
+ $expected = [
+ static::FAIL_MESSAGE,
+ 'Unable to install the <em class="placeholder">unknown_module</em> module since it does not exist.',
+ 'Unable to install the <em class="placeholder">Book</em> module since it requires the <em class="placeholder">Node, Text, Field, Filter, User</em> modules.',
+ 'Unable to install the <em class="placeholder">unknown_theme</em> theme since it does not exist.',
+ 'Unable to install the <em class="placeholder">Bartik</em> theme since it requires the <em class="placeholder">Classy</em> theme.',
+ 'Unable to install the <em class="placeholder">Bartik</em> theme since it requires the <em class="placeholder">Stable</em> theme.',
+ 'Configuration <em class="placeholder">config_test.dynamic.dotted.config</em> depends on the <em class="placeholder">unknown</em> configuration that will not exist after import.',
+ 'Configuration <em class="placeholder">config_test.dynamic.dotted.existing</em> depends on the <em class="placeholder">config_test.dynamic.dotted.deleted</em> configuration that will not exist after import.',
+ 'Configuration <em class="placeholder">config_test.dynamic.dotted.module</em> depends on the <em class="placeholder">unknown</em> module that will not be installed after import.',
+ 'Configuration <em class="placeholder">config_test.dynamic.dotted.theme</em> depends on the <em class="placeholder">unknown</em> theme that will not be installed after import.',
+ 'Configuration <em class="placeholder">unknown.config</em> depends on the <em class="placeholder">unknown</em> extension that will not be installed after import.',
+ ];
+ $this->assertEquals(implode(PHP_EOL, $expected), $e->getMessage());
$error_log = $this->configImporter->getErrors();
$expected = [
'Unable to install the <em class="placeholder">unknown_module</em> module since it does not exist.',
}
}
- // Make a config entity have mulitple unmet dependencies.
+ // Make a config entity have multiple unmet dependencies.
$config_entity_data = $sync->read('config_test.dynamic.dotted.default');
$config_entity_data['dependencies'] = ['module' => ['unknown', 'dblog']];
$sync->write('config_test.dynamic.dotted.module', $config_entity_data);
$this->fail('ConfigImporterException not thrown, invalid import was not stopped due to missing dependencies.');
}
catch (ConfigImporterException $e) {
- $this->assertEqual($e->getMessage(), 'There were errors validating the config synchronization.');
+ $expected = [
+ static::FAIL_MESSAGE,
+ 'Unable to install the <em class="placeholder">unknown_module</em> module since it does not exist.',
+ 'Unable to install the <em class="placeholder">Book</em> module since it requires the <em class="placeholder">Node, Text, Field, Filter, User</em> modules.',
+ 'Unable to install the <em class="placeholder">unknown_theme</em> theme since it does not exist.',
+ 'Unable to install the <em class="placeholder">Bartik</em> theme since it requires the <em class="placeholder">Classy</em> theme.',
+ 'Unable to install the <em class="placeholder">Bartik</em> theme since it requires the <em class="placeholder">Stable</em> theme.',
+ 'Configuration <em class="placeholder">config_test.dynamic.dotted.config</em> depends on the <em class="placeholder">unknown</em> configuration that will not exist after import.',
+ 'Configuration <em class="placeholder">config_test.dynamic.dotted.existing</em> depends on the <em class="placeholder">config_test.dynamic.dotted.deleted</em> configuration that will not exist after import.',
+ 'Configuration <em class="placeholder">config_test.dynamic.dotted.module</em> depends on the <em class="placeholder">unknown</em> module that will not be installed after import.',
+ 'Configuration <em class="placeholder">config_test.dynamic.dotted.theme</em> depends on the <em class="placeholder">unknown</em> theme that will not be installed after import.',
+ 'Configuration <em class="placeholder">unknown.config</em> depends on the <em class="placeholder">unknown</em> extension that will not be installed after import.',
+ 'Unable to install the <em class="placeholder">unknown_module</em> module since it does not exist.',
+ 'Unable to install the <em class="placeholder">Book</em> module since it requires the <em class="placeholder">Node, Text, Field, Filter, User</em> modules.',
+ 'Unable to install the <em class="placeholder">unknown_theme</em> theme since it does not exist.',
+ 'Unable to install the <em class="placeholder">Bartik</em> theme since it requires the <em class="placeholder">Classy</em> theme.',
+ 'Unable to install the <em class="placeholder">Bartik</em> theme since it requires the <em class="placeholder">Stable</em> theme.',
+ 'Configuration <em class="placeholder">config_test.dynamic.dotted.config</em> depends on configuration (<em class="placeholder">unknown, unknown2</em>) that will not exist after import.',
+ 'Configuration <em class="placeholder">config_test.dynamic.dotted.existing</em> depends on the <em class="placeholder">config_test.dynamic.dotted.deleted</em> configuration that will not exist after import.',
+ 'Configuration <em class="placeholder">config_test.dynamic.dotted.module</em> depends on modules (<em class="placeholder">unknown, Database Logging</em>) that will not be installed after import.',
+ 'Configuration <em class="placeholder">config_test.dynamic.dotted.theme</em> depends on themes (<em class="placeholder">unknown, Seven</em>) that will not be installed after import.',
+ 'Configuration <em class="placeholder">unknown.config</em> depends on the <em class="placeholder">unknown</em> extension that will not be installed after import.',
+ ];
+ $this->assertEquals(implode(PHP_EOL, $expected), $e->getMessage());
$error_log = $this->configImporter->getErrors();
$expected = [
'Configuration <em class="placeholder">config_test.dynamic.dotted.config</em> depends on configuration (<em class="placeholder">unknown, unknown2</em>) that will not exist after import.',
$this->fail('ConfigImporterException not thrown, invalid import was not stopped due to missing dependencies.');
}
catch (ConfigImporterException $e) {
- $this->assertEqual($e->getMessage(), 'There were errors validating the config synchronization.');
+ $expected = static::FAIL_MESSAGE . PHP_EOL . 'The core.extension configuration does not exist.';
+ $this->assertEquals($expected, $e->getMessage());
$error_log = $this->configImporter->getErrors();
$this->assertEqual(['The core.extension configuration does not exist.'], $error_log);
}
$this->fail('ConfigImporterException not thrown; an invalid import was not stopped due to missing dependencies.');
}
catch (ConfigImporterException $e) {
- $this->assertEqual($e->getMessage(), 'There were errors validating the config synchronization.');
+ $expected = static::FAIL_MESSAGE . PHP_EOL . 'Unable to install the <em class="placeholder">standard</em> module since it does not exist.';
+ $this->assertEquals($expected, $e->getMessage(), 'There were errors validating the config synchronization.');
$error_log = $this->configImporter->getErrors();
// Install profiles should not even be scanned at this point.
$this->assertEqual(['Unable to install the <em class="placeholder">standard</em> module since it does not exist.'], $error_log);
$this->fail('ConfigImporterException not thrown; an invalid import was not stopped due to missing dependencies.');
}
catch (ConfigImporterException $e) {
- $this->assertEqual($e->getMessage(), 'There were errors validating the config synchronization.');
+ $expected = static::FAIL_MESSAGE . PHP_EOL . 'Cannot change the install profile from <em class="placeholder"></em> to <em class="placeholder">this_will_not_work</em> once Drupal is installed.';
+ $this->assertEquals($expected, $e->getMessage(), 'There were errors validating the config synchronization.');
$error_log = $this->configImporter->getErrors();
// Install profiles can not be changed. Note that KernelTestBase currently
// does not use an install profile. This situation should be impossible
}
/**
- * Helper meothd to test custom config installer steps.
+ * Helper method to test custom config installer steps.
*
* @param array $context
* Batch context.