Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Config / ConfigImporterTest.php
index 4024b7f9d967592e02fcf367454f9f0d11dc910a..c8eb231a97cf747de592b7b14bdc68b1ef348261 100644 (file)
@@ -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';
@@ -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 <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.',
@@ -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 <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.',
@@ -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 <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);
@@ -686,7 +736,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 . '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
@@ -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.