X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Ftests%2FDrupal%2FKernelTests%2FCore%2FConfig%2FConfigImporterTest.php;h=c8eb231a97cf747de592b7b14bdc68b1ef348261;hb=refs%2Fheads%2Fd864;hp=0ecc38c181f752f39fa788a4e0a7ca4e39f96d0f;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php b/web/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php index 0ecc38c18..c8eb231a9 100644 --- a/web/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php +++ b/web/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php @@ -3,7 +3,7 @@ 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; @@ -16,6 +16,11 @@ use Drupal\KernelTests\KernelTestBase; */ 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. * @@ -33,7 +38,7 @@ class ConfigImporterTest extends KernelTestBase { 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. @@ -104,10 +109,17 @@ class ConfigImporterTest extends KernelTestBase { $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)); + } } } @@ -226,7 +238,7 @@ class ConfigImporterTest extends KernelTestBase { // Add a dependency on primary, to ensure that is synced first. 'dependencies' => [ 'config' => [$name_primary], - ] + ], ]; $sync->write($name_secondary, $values_secondary); @@ -245,7 +257,7 @@ class ConfigImporterTest extends KernelTestBase { $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])); } /** @@ -265,7 +277,7 @@ class ConfigImporterTest extends KernelTestBase { // Add a dependency on secondary, so that is synced first. 'dependencies' => [ 'config' => [$name_secondary], - ] + ], ]; $sync->write($name_primary, $values_primary); $values_secondary = [ @@ -322,7 +334,7 @@ class ConfigImporterTest extends KernelTestBase { // 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'; @@ -338,7 +350,7 @@ class ConfigImporterTest extends KernelTestBase { // 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'; @@ -351,7 +363,7 @@ class ConfigImporterTest extends KernelTestBase { $name_deletee, $name_other, ]; - $this->assertIdentical($expected, $updates); + $this->assertSame($expected, $updates); // Import. $this->configImporter->import(); @@ -373,7 +385,7 @@ class ConfigImporterTest extends KernelTestBase { $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])); } /** @@ -580,7 +592,20 @@ class ConfigImporterTest extends KernelTestBase { $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 unknown_module module since it does not exist.', + 'Unable to install the Book module since it requires the Node, Text, Field, Filter, User modules.', + 'Unable to install the unknown_theme theme since it does not exist.', + 'Unable to install the Bartik theme since it requires the Classy theme.', + 'Unable to install the Bartik theme since it requires the Stable theme.', + 'Configuration config_test.dynamic.dotted.config depends on the unknown configuration that will not exist after import.', + 'Configuration config_test.dynamic.dotted.existing depends on the config_test.dynamic.dotted.deleted configuration that will not exist after import.', + 'Configuration config_test.dynamic.dotted.module depends on the unknown module that will not be installed after import.', + 'Configuration config_test.dynamic.dotted.theme depends on the unknown theme that will not be installed after import.', + 'Configuration unknown.config depends on the unknown 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 unknown_module module since it does not exist.', @@ -598,7 +623,7 @@ class ConfigImporterTest extends KernelTestBase { } } - // 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); @@ -611,7 +636,30 @@ class ConfigImporterTest extends KernelTestBase { $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 unknown_module module since it does not exist.', + 'Unable to install the Book module since it requires the Node, Text, Field, Filter, User modules.', + 'Unable to install the unknown_theme theme since it does not exist.', + 'Unable to install the Bartik theme since it requires the Classy theme.', + 'Unable to install the Bartik theme since it requires the Stable theme.', + 'Configuration config_test.dynamic.dotted.config depends on the unknown configuration that will not exist after import.', + 'Configuration config_test.dynamic.dotted.existing depends on the config_test.dynamic.dotted.deleted configuration that will not exist after import.', + 'Configuration config_test.dynamic.dotted.module depends on the unknown module that will not be installed after import.', + 'Configuration config_test.dynamic.dotted.theme depends on the unknown theme that will not be installed after import.', + 'Configuration unknown.config depends on the unknown extension that will not be installed after import.', + 'Unable to install the unknown_module module since it does not exist.', + 'Unable to install the Book module since it requires the Node, Text, Field, Filter, User modules.', + 'Unable to install the unknown_theme theme since it does not exist.', + 'Unable to install the Bartik theme since it requires the Classy theme.', + 'Unable to install the Bartik theme since it requires the Stable theme.', + 'Configuration config_test.dynamic.dotted.config depends on configuration (unknown, unknown2) that will not exist after import.', + 'Configuration config_test.dynamic.dotted.existing depends on the config_test.dynamic.dotted.deleted configuration that will not exist after import.', + 'Configuration config_test.dynamic.dotted.module depends on modules (unknown, Database Logging) that will not be installed after import.', + 'Configuration config_test.dynamic.dotted.theme depends on themes (unknown, Seven) that will not be installed after import.', + 'Configuration unknown.config depends on the unknown extension that will not be installed after import.', + ]; + $this->assertEquals(implode(PHP_EOL, $expected), $e->getMessage()); $error_log = $this->configImporter->getErrors(); $expected = [ 'Configuration config_test.dynamic.dotted.config depends on configuration (unknown, unknown2) that will not exist after import.', @@ -637,7 +685,8 @@ class ConfigImporterTest extends KernelTestBase { $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); } @@ -661,7 +710,8 @@ class ConfigImporterTest extends KernelTestBase { $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 standard 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 standard module since it does not exist.'], $error_log); @@ -686,13 +736,14 @@ class ConfigImporterTest extends KernelTestBase { $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 to this_will_not_work 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 // to get in but site's can removed the install profile setting from // settings.php so the test is valid. - $this->assertEqual(['Cannot change the install profile from this_will_not_work to once Drupal is installed.'], $error_log); + $this->assertEqual(['Cannot change the install profile from to this_will_not_work once Drupal is installed.'], $error_log); } } @@ -797,7 +848,7 @@ class ConfigImporterTest extends KernelTestBase { } /** - * Helper meothd to test custom config installer steps. + * Helper method to test custom config installer steps. * * @param array $context * Batch context.