diff --git a/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php b/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php index 1660f62f3cf5c5e6072ab466988edd0ffc7695c3..ae7f1359543e0f33d66ea3e5abe3910d5dfb4ecb 100644 --- a/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php +++ b/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php @@ -195,7 +195,10 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { $this->checkForUpdates(); $state = $this->container->get('state'); $state->set('system.maintenance_mode', $maintenance_mode_on); - StagedDatabaseUpdateValidator::setExtensionsWithUpdates(['system', 'automatic_updates_theme_with_updates']); + StagedDatabaseUpdateValidator::setExtensionsWithUpdates([ + 'system', + 'automatic_updates_theme_with_updates', + ]); $page = $this->getSession()->getPage(); // Navigate to the automatic updates form. @@ -289,7 +292,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { // Set an error before completing the update. This error should be visible // on admin pages after completing the update without having to explicitly // run the status checks. - TestSubscriber1::setTestResult([ValidationResult::createError(['Error before continue.'])], StatusCheckEvent::class); + TestSubscriber1::setTestResult([ValidationResult::createError([t('Error before continue.')])], StatusCheckEvent::class); if ($has_database_updates) { // Simulate a staged database update in the automatic_updates_test module. // We must do this after the update has started, because the pending @@ -588,9 +591,9 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { // Add warnings from StatusCheckEvent. $summary_status_check_event = t('Some summary'); $messages_status_check_event = [ - "The only thing we're allowed to do is to", - "believe that we won't regret the choice", - "we made.", + t("The only thing we're allowed to do is to"), + t("believe that we won't regret the choice"), + t("we made."), ]; $warning_status_check_event = ValidationResult::createWarning($messages_status_check_event, $summary_status_check_event); TestSubscriber::setTestResult([$warning_status_check_event], StatusCheckEvent::class); @@ -619,9 +622,9 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { $assert->checkboxChecked('edit-projects-semver-test'); $assert->buttonExists('Update'); $messages = [ - "The only thing we're allowed to do is to", - "believe that we won't regret the choice", - "we made.", + t("The only thing we're allowed to do is to"), + t("believe that we won't regret the choice"), + t("we made."), ]; $summary = t('Some summary'); $error = ValidationResult::createError($messages, $summary); diff --git a/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php b/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php index 9675e3cf29cf655bd862c37553ef068a3a7ee918..dd2da2f16515cdd97420ebe269906ba93f1497d0 100644 --- a/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php +++ b/automatic_updates_extensions/tests/src/Kernel/ExtensionUpdaterTest.php @@ -163,7 +163,7 @@ class ExtensionUpdaterTest extends AutomaticUpdatesExtensionsKernelTestBase { public function testUpdateException(string $event_class): void { $extension_updater = $this->container->get('automatic_updates_extensions.updater'); $results = [ - ValidationResult::createError(['An error of some sorts.']), + ValidationResult::createError([t('An error of some sorts.')]), ]; TestSubscriber1::setTestResult($results, $event_class); try { diff --git a/automatic_updates_extensions/tests/src/Kernel/Validator/UpdateReleaseValidatorTest.php b/automatic_updates_extensions/tests/src/Kernel/Validator/UpdateReleaseValidatorTest.php index fa5bdb51a629bb0aa5455d4b5170f6b6ffaba5f3..b59e6f3286e6fcf1a0a03168fe163ebf191ae608 100644 --- a/automatic_updates_extensions/tests/src/Kernel/Validator/UpdateReleaseValidatorTest.php +++ b/automatic_updates_extensions/tests/src/Kernel/Validator/UpdateReleaseValidatorTest.php @@ -67,7 +67,12 @@ class UpdateReleaseValidatorTest extends AutomaticUpdatesExtensionsKernelTestBas if ($error_expected) { $expected_results = [ ValidationResult::createError( - ["Project $project to version " . LegacyVersionUtility::convertToSemanticVersion($target_version)], + [ + t('Project @project to version @target_version', [ + '@project' => $project, + '@target_version' => LegacyVersionUtility::convertToSemanticVersion($target_version), + ]), + ], t('Cannot update because the following project version is not in the list of installable releases.') ), ]; diff --git a/package_manager/src/Event/PreOperationStageEvent.php b/package_manager/src/Event/PreOperationStageEvent.php index 8865954492861268a32c129910bffb65becdc329..64f975fb097d72dfac19e3410d7a4cfb4c50dc7f 100644 --- a/package_manager/src/Event/PreOperationStageEvent.php +++ b/package_manager/src/Event/PreOperationStageEvent.php @@ -51,4 +51,16 @@ abstract class PreOperationStageEvent extends StageEvent { $this->results[] = ValidationResult::createError($messages, $summary); } + /** + * Adds an error from a throwable. + * + * @param \Throwable $throwable + * The throwable. + * @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $summary + * (optional) The summary of error messages. + */ + public function addErrorFromThrowable(\Throwable $throwable, ?TranslatableMarkup $summary = NULL): void { + $this->results[] = ValidationResult::createErrorFromThrowable($throwable, $summary); + } + } diff --git a/package_manager/src/ValidationResult.php b/package_manager/src/ValidationResult.php index d5fb5da664085e134ffe749bec03357e7e7bdb45..0d3a1107938c99d524495090b005859638915e60 100644 --- a/package_manager/src/ValidationResult.php +++ b/package_manager/src/ValidationResult.php @@ -22,7 +22,7 @@ final class ValidationResult { /** * The error messages. * - * @var \Drupal\Core\StringTranslation\TranslatableMarkup[] + * @var \Drupal\Core\StringTranslation\TranslatableMarkup[]|string[] */ protected $messages; @@ -39,7 +39,7 @@ final class ValidationResult { * @param int $severity * The severity of the result. Should be one of the * SystemManager::REQUIREMENT_* constants. - * @param \Drupal\Core\StringTranslation\TranslatableMarkup[] $messages + * @param \Drupal\Core\StringTranslation\TranslatableMarkup[]|string[] $messages * The error messages. * @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $summary * The errors summary. @@ -56,6 +56,20 @@ final class ValidationResult { $this->severity = $severity; } + /** + * Creates an error ValidationResult object from a throwable. + * + * @param \Throwable $throwable + * The throwable. + * @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $summary + * The errors summary. + * + * @return static + */ + public static function createErrorFromThrowable(\Throwable $throwable, ?TranslatableMarkup $summary = NULL): self { + return new static(SystemManager::REQUIREMENT_ERROR, [$throwable->getMessage()], $summary); + } + /** * Creates an error ValidationResult object. * @@ -97,7 +111,7 @@ final class ValidationResult { /** * Gets the messages. * - * @return \Drupal\Core\StringTranslation\TranslatableMarkup[] + * @return \Drupal\Core\StringTranslation\TranslatableMarkup[]|string[] * The error or warning messages. */ public function getMessages(): array { diff --git a/package_manager/src/Validator/OverwriteExistingPackagesValidator.php b/package_manager/src/Validator/OverwriteExistingPackagesValidator.php index b8e8b8a67188918c70e4d7e04f0a2ea2ddcc2c51..f1ce2d9177dffc57e4d0867c7dbbfde5f15bcce4 100644 --- a/package_manager/src/Validator/OverwriteExistingPackagesValidator.php +++ b/package_manager/src/Validator/OverwriteExistingPackagesValidator.php @@ -73,7 +73,10 @@ final class OverwriteExistingPackagesValidator implements EventSubscriberInterfa $missing_new_packages = array_diff_key($new_packages, $installed_packages_data); if ($missing_new_packages) { $missing_new_packages = array_keys($missing_new_packages); - $event->addError($missing_new_packages, $this->t('Package Manager could not get the data for the following packages:')); + foreach ($missing_new_packages as &$missing_new_package) { + $missing_new_package = $this->t('@missing_new_package', ['@missing_new_package' => $missing_new_package]); + } + $event->addError(array_values($missing_new_packages), $this->t('Package Manager could not get the data for the following packages.')); return; } diff --git a/package_manager/src/Validator/StagedDBUpdateValidator.php b/package_manager/src/Validator/StagedDBUpdateValidator.php index aee2cf7684e159e7a399b89121b0ffddfa07579d..5dadab5188293b86b9546897a5aee8358b9b1d26 100644 --- a/package_manager/src/Validator/StagedDBUpdateValidator.php +++ b/package_manager/src/Validator/StagedDBUpdateValidator.php @@ -166,7 +166,7 @@ class StagedDBUpdateValidator implements EventSubscriberInterface { * @param string $stage_dir * The path of the stage directory. * - * @return string[] + * @return \Drupal\Core\StringTranslation\TranslatableMarkup[] * The names of the extensions that have possible database updates. */ public function getExtensionsWithDatabaseUpdates(string $stage_dir): array { diff --git a/package_manager/tests/src/Kernel/ComposerExecutableValidatorTest.php b/package_manager/tests/src/Kernel/ComposerExecutableValidatorTest.php index cffa7ad961172d1706f3ec37dd0fe575953fc948..28b8d7ee263c91051bb312b71ea82dd911bcbf5f 100644 --- a/package_manager/tests/src/Kernel/ComposerExecutableValidatorTest.php +++ b/package_manager/tests/src/Kernel/ComposerExecutableValidatorTest.php @@ -109,7 +109,7 @@ class ComposerExecutableValidatorTest extends PackageManagerKernelTestBase { public function providerComposerVersionValidation(): array { // Invalid or undetectable Composer versions will always produce the same // error. - $invalid_version = ValidationResult::createError(['The Composer version could not be detected.']); + $invalid_version = ValidationResult::createError([t('The Composer version could not be detected.')]); // Unsupported Composer versions will report the detected version number // in the validation result, so we need a function to churn out those fake @@ -118,7 +118,10 @@ class ComposerExecutableValidatorTest extends PackageManagerKernelTestBase { $minimum_version = ComposerExecutableValidator::MINIMUM_COMPOSER_VERSION_CONSTRAINT; return ValidationResult::createError([ - "A Composer version which satisfies <code>$minimum_version</code> is required, but version $version was detected.", + t('A Composer version which satisfies <code>@minimum_version</code> is required, but version @version was detected.', [ + '@minimum_version' => $minimum_version, + '@version' => $version, + ]), ]); }; diff --git a/package_manager/tests/src/Kernel/ComposerPatchesValidatorTest.php b/package_manager/tests/src/Kernel/ComposerPatchesValidatorTest.php index 64014e7f750e8d79803390ac34daa1e0d1b55f8b..718563a3c8a88b718168466983e024abf8148184 100644 --- a/package_manager/tests/src/Kernel/ComposerPatchesValidatorTest.php +++ b/package_manager/tests/src/Kernel/ComposerPatchesValidatorTest.php @@ -31,7 +31,9 @@ class ComposerPatchesValidatorTest extends PackageManagerKernelTestBase { // factory as an array, Composer will assume that the configuration is // coming from a config.json file, even if one doesn't exist. $error = ValidationResult::createError([ - "The <code>cweagans/composer-patches</code> plugin is installed, but the <code>composer-exit-on-patch-failure</code> key is not set to <code>true</code> in the <code>extra</code> section of $dir/config.json.", + t('The <code>cweagans/composer-patches</code> plugin is installed, but the <code>composer-exit-on-patch-failure</code> key is not set to <code>true</code> in the <code>extra</code> section of @dir/config.json.', [ + '@dir' => $dir, + ]), ]); $this->assertStatusCheckResults([$error]); $this->assertResults([$error], PreCreateEvent::class); diff --git a/package_manager/tests/src/Kernel/ComposerSettingsValidatorTest.php b/package_manager/tests/src/Kernel/ComposerSettingsValidatorTest.php index 53ff0f0511b32b3f730b97fbbe28b7cb982882d9..934a1f6a33172229e71f21dc9e69fd4c055069df 100644 --- a/package_manager/tests/src/Kernel/ComposerSettingsValidatorTest.php +++ b/package_manager/tests/src/Kernel/ComposerSettingsValidatorTest.php @@ -24,7 +24,7 @@ class ComposerSettingsValidatorTest extends PackageManagerKernelTestBase { */ public function providerSecureHttpValidation(): array { $error = ValidationResult::createError([ - 'HTTPS must be enabled for Composer downloads. See <a href="https://getcomposer.org/doc/06-config.md#secure-http">the Composer documentation</a> for more information.', + t('HTTPS must be enabled for Composer downloads. See <a href="https://getcomposer.org/doc/06-config.md#secure-http">the Composer documentation</a> for more information.'), ]); return [ diff --git a/package_manager/tests/src/Kernel/EnvironmentSupportValidatorTest.php b/package_manager/tests/src/Kernel/EnvironmentSupportValidatorTest.php index 3f28d1cbfd68c9b11821edc2a5679ce5138ddd53..6d7c2546f7b68980c831c186f48f28bb6d1e3ca7 100644 --- a/package_manager/tests/src/Kernel/EnvironmentSupportValidatorTest.php +++ b/package_manager/tests/src/Kernel/EnvironmentSupportValidatorTest.php @@ -24,7 +24,7 @@ class EnvironmentSupportValidatorTest extends PackageManagerKernelTestBase { putenv(EnvironmentSupportValidator::VARIABLE_NAME . '=broken/url.org'); $result = ValidationResult::createError([ - 'Package Manager is not supported by your environment.', + t('Package Manager is not supported by your environment.'), ]); foreach ([PreCreateEvent::class, StatusCheckEvent::class] as $event_class) { $this->assertEventPropagationStopped($event_class, [$this->container->get('package_manager.validator.environment_support'), 'validateStagePreOperation']); diff --git a/package_manager/tests/src/Kernel/LockFileValidatorTest.php b/package_manager/tests/src/Kernel/LockFileValidatorTest.php index cf46072f0e6a274e0e9f829eb18c6e18e13c1935..6184957cc52e9e038a1dfa3ddec63947ef51627d 100644 --- a/package_manager/tests/src/Kernel/LockFileValidatorTest.php +++ b/package_manager/tests/src/Kernel/LockFileValidatorTest.php @@ -42,7 +42,7 @@ class LockFileValidatorTest extends PackageManagerKernelTestBase { public function testCreateWithNoLock(): void { unlink($this->activeDir . '/composer.lock'); - $no_lock = ValidationResult::createError(['Could not hash the active lock file.']); + $no_lock = ValidationResult::createError([t('Could not hash the active lock file.')]); $stage = $this->assertResults([$no_lock], PreCreateEvent::class); // The stage was not created successfully, so the status check should be // clear. @@ -78,7 +78,7 @@ class LockFileValidatorTest extends PackageManagerKernelTestBase { file_put_contents($this->activeDir . '/composer.lock', 'changed'); }, $event_class); $result = ValidationResult::createError([ - 'Unexpected changes were detected in composer.lock, which indicates that other Composer operations were performed since this Package Manager operation started. This can put the code base into an unreliable state and therefore is not allowed.', + t('Unexpected changes were detected in composer.lock, which indicates that other Composer operations were performed since this Package Manager operation started. This can put the code base into an unreliable state and therefore is not allowed.'), ]); $stage = $this->assertResults([$result], $event_class); // A status check should agree that there is an error here. @@ -99,7 +99,7 @@ class LockFileValidatorTest extends PackageManagerKernelTestBase { unlink($this->activeDir . '/composer.lock'); }, $event_class); $result = ValidationResult::createError([ - 'Could not hash the active lock file.', + t('Could not hash the active lock file.'), ]); $stage = $this->assertResults([$result], $event_class); // A status check should agree that there is an error here. @@ -123,7 +123,7 @@ class LockFileValidatorTest extends PackageManagerKernelTestBase { $this->container->get('state')->delete($state_key); }, $event_class); $result = ValidationResult::createError([ - 'Could not retrieve stored hash of the active lock file.', + t('Could not retrieve stored hash of the active lock file.'), ]); $stage = $this->assertResults([$result], $event_class); // A status check should agree that there is an error here. @@ -138,7 +138,7 @@ class LockFileValidatorTest extends PackageManagerKernelTestBase { Stager::setLockFileShouldChange(FALSE); $result = ValidationResult::createError([ - 'There are no pending Composer operations.', + t('There are no pending Composer operations.'), ]); $stage = $this->assertResults([$result], PreApplyEvent::class); // A status check shouldn't produce raise any errors, because it's only diff --git a/package_manager/tests/src/Kernel/MultisiteValidatorTest.php b/package_manager/tests/src/Kernel/MultisiteValidatorTest.php index b9171e599279dbb8e2671bc0c8d27908d0be5d67..fc3757b90f762461986b8ebf7ac08ab25d395ad9 100644 --- a/package_manager/tests/src/Kernel/MultisiteValidatorTest.php +++ b/package_manager/tests/src/Kernel/MultisiteValidatorTest.php @@ -27,7 +27,7 @@ class MultisiteValidatorTest extends PackageManagerKernelTestBase { TRUE, [ ValidationResult::createError([ - 'Drupal multisite is not supported by Package Manager.', + t('Drupal multisite is not supported by Package Manager.'), ]), ], ], diff --git a/package_manager/tests/src/Kernel/OverwriteExistingPackagesValidatorTest.php b/package_manager/tests/src/Kernel/OverwriteExistingPackagesValidatorTest.php index 3431180b3bbceb044610f325fedba89ebbcc3cee..40b4224795b484e60f9f6c4cc2bf07e57b25c9a1 100644 --- a/package_manager/tests/src/Kernel/OverwriteExistingPackagesValidatorTest.php +++ b/package_manager/tests/src/Kernel/OverwriteExistingPackagesValidatorTest.php @@ -113,13 +113,13 @@ class OverwriteExistingPackagesValidatorTest extends PackageManagerKernelTestBas $expected_results = [ ValidationResult::createError([ - 'The new package drupal/module_1 will be installed in the directory /vendor/composer/../../modules/module_1, which already exists but is not managed by Composer.', + t('The new package drupal/module_1 will be installed in the directory /vendor/composer/../../modules/module_1, which already exists but is not managed by Composer.'), ]), ValidationResult::createError([ - 'The new package drupal/module_2 will be installed in the directory /vendor/composer/../../modules/module_2, which already exists but is not managed by Composer.', + t('The new package drupal/module_2 will be installed in the directory /vendor/composer/../../modules/module_2, which already exists but is not managed by Composer.'), ]), ValidationResult::createError([ - 'The new package drupal/module_4 will be installed in the directory /vendor/composer/../../modules/module_1, which already exists but is not managed by Composer.', + t('The new package drupal/module_4 will be installed in the directory /vendor/composer/../../modules/module_1, which already exists but is not managed by Composer.'), ]), ]; $this->assertResults($expected_results, PreApplyEvent::class); diff --git a/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php b/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php index 7b240cb6767e08b79a6ad0c66abf94a3efc6e363..c365efac7148106252d420e1343b4cbff3994cc6 100644 --- a/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php +++ b/package_manager/tests/src/Kernel/PackageManagerKernelTestBase.php @@ -193,9 +193,9 @@ abstract class PackageManagerKernelTestBase extends KernelTestBase { * * @param \Drupal\package_manager\ValidationResult[] $expected_results * The expected validation results. - * @param \Drupal\package_manager\Stage|null $stage - * (optional) The stage to use to create the status check event. If none is - * provided a new stage will be created. + * @param \Drupal\Tests\package_manager\Kernel\TestStage|null $stage + * (optional) The test stage to use to create the status check event. If + * none is provided a new stage will be created. */ protected function assertStatusCheckResults(array $expected_results, Stage $stage = NULL): void { $actual_results = $this->runStatusCheck($stage ?? $this->createStage(), $this->container->get('event_dispatcher')); @@ -488,6 +488,19 @@ class TestStage extends Stage { use TestStageTrait; + /** + * {@inheritdoc} + * + * TRICKY: without this, any failed ::assertStatusCheckResults() + * will fail, because PHPUnit will want to serialize all arguments in the call + * stack. + * + * @see https://www.drupal.org/project/automatic_updates/issues/3312619#comment-14801308 + */ + public function __sleep(): array { + return []; + } + } /** diff --git a/package_manager/tests/src/Kernel/PendingUpdatesValidatorTest.php b/package_manager/tests/src/Kernel/PendingUpdatesValidatorTest.php index e4d4745ffefb0fc518ee86c9f6b52407f7628f2a..4156a56a3bbdcbe214d2068434b60bcc6d95beae 100644 --- a/package_manager/tests/src/Kernel/PendingUpdatesValidatorTest.php +++ b/package_manager/tests/src/Kernel/PendingUpdatesValidatorTest.php @@ -44,7 +44,7 @@ class PendingUpdatesValidatorTest extends PackageManagerKernelTestBase { require_once __DIR__ . '/../../fixtures/db_update.php'; $result = ValidationResult::createError([ - 'Some modules have database schema updates to install. You should run the <a href="/update.php">database update script</a> immediately.', + t('Some modules have database schema updates to install. You should run the <a href="/update.php">database update script</a> immediately.'), ]); $this->assertStatusCheckResults([$result]); $this->assertResults([$result], PreCreateEvent::class); @@ -58,7 +58,7 @@ class PendingUpdatesValidatorTest extends PackageManagerKernelTestBase { // will think it's pending. require_once __DIR__ . '/../../fixtures/post_update.php'; $result = ValidationResult::createError([ - 'Some modules have database schema updates to install. You should run the <a href="/update.php">database update script</a> immediately.', + t('Some modules have database schema updates to install. You should run the <a href="/update.php">database update script</a> immediately.'), ]); $this->assertStatusCheckResults([$result]); $this->assertResults([$result], PreCreateEvent::class); diff --git a/package_manager/tests/src/Kernel/SettingsValidatorTest.php b/package_manager/tests/src/Kernel/SettingsValidatorTest.php index dc9b8ff3d58496f55bc1d85b98a891eb0adf6a0d..137cc7f023e8f451156967c5ab1207fb232b3192 100644 --- a/package_manager/tests/src/Kernel/SettingsValidatorTest.php +++ b/package_manager/tests/src/Kernel/SettingsValidatorTest.php @@ -22,7 +22,7 @@ class SettingsValidatorTest extends PackageManagerKernelTestBase { * The test cases. */ public function providerSettingsValidation(): array { - $result = ValidationResult::createError(['The <code>update_fetch_with_http_fallback</code> setting must be disabled.']); + $result = ValidationResult::createError([t('The <code>update_fetch_with_http_fallback</code> setting must be disabled.')]); return [ 'HTTP fallback enabled' => [TRUE, [$result]], diff --git a/package_manager/tests/src/Kernel/StageEventsTest.php b/package_manager/tests/src/Kernel/StageEventsTest.php index 905ce0d1599c5015c043c4852d1488167fb55c9e..06161dccd4c838cb068fe9d832ee4ce7cbb2f83c 100644 --- a/package_manager/tests/src/Kernel/StageEventsTest.php +++ b/package_manager/tests/src/Kernel/StageEventsTest.php @@ -141,7 +141,7 @@ class StageEventsTest extends PackageManagerKernelTestBase implements EventSubsc * @dataProvider providerValidationResults */ public function testValidationResults(string $event_class): void { - $error_messages = ['Burn, baby, burn']; + $error_messages = [t('Burn, baby, burn')]; // Set up an event listener which will only flag an error for the event // class under test. $handler = function (StageEvent $event) use ($event_class, $error_messages): void { diff --git a/package_manager/tests/src/Kernel/StageValidationExceptionTest.php b/package_manager/tests/src/Kernel/StageValidationExceptionTest.php index 0b68618f253b7f22c3b53fb5f103cacf7b69922a..7f219c5333fb0f7c67bc49135ae97623ac0e26a6 100644 --- a/package_manager/tests/src/Kernel/StageValidationExceptionTest.php +++ b/package_manager/tests/src/Kernel/StageValidationExceptionTest.php @@ -31,10 +31,11 @@ class StageValidationExceptionTest extends PackageManagerKernelTestBase { */ public function providerResultsAsText(): array { $messages = ['Bang!', 'Pow!']; + $translated_messages = [t('Bang!'), t('Pow!')]; $summary = t('There was sadness.'); - $result_no_summary = ValidationResult::createError([$messages[0]]); - $result_with_summary = ValidationResult::createError($messages, $summary); + $result_no_summary = ValidationResult::createError([$translated_messages[0]]); + $result_with_summary = ValidationResult::createError($translated_messages, $summary); $result_with_summary_message = "{$summary->getUntranslatedString()}\n{$messages[0]}\n{$messages[1]}\n"; return [ diff --git a/package_manager/tests/src/Kernel/StagedDBUpdateValidatorTest.php b/package_manager/tests/src/Kernel/StagedDBUpdateValidatorTest.php index dd65d36dbae0a5ee96a51a95b331d785ed9e5bd2..5755d4ff2a2e6938c8b0750d67c93f0c6b36085e 100644 --- a/package_manager/tests/src/Kernel/StagedDBUpdateValidatorTest.php +++ b/package_manager/tests/src/Kernel/StagedDBUpdateValidatorTest.php @@ -96,7 +96,7 @@ class StagedDBUpdateValidatorTest extends PackageManagerKernelTestBase { unlink("$stage_dir/$path/$name.$suffix"); } - $result = ValidationResult::createWarning(['System', 'Stark'], t('Possible database updates have been detected in the following extensions.')); + $result = ValidationResult::createWarning([t('System'), t('Stark')], t('Possible database updates have been detected in the following extensions.')); $this->assertStatusCheckResults([$result], $stage); } @@ -117,7 +117,7 @@ class StagedDBUpdateValidatorTest extends PackageManagerKernelTestBase { file_put_contents("$stage_dir/$path/$name.$suffix", $this->randomString()); } - $result = ValidationResult::createWarning(['System', 'Stark'], t('Possible database updates have been detected in the following extensions.')); + $result = ValidationResult::createWarning([t('System'), t('Stark')], t('Possible database updates have been detected in the following extensions.')); $this->assertStatusCheckResults([$result], $stage); } @@ -139,7 +139,7 @@ class StagedDBUpdateValidatorTest extends PackageManagerKernelTestBase { unlink("$active_dir/$path/$name.$suffix"); } - $result = ValidationResult::createWarning(['System', 'Stark'], t('Possible database updates have been detected in the following extensions.')); + $result = ValidationResult::createWarning([t('System'), t('Stark')], t('Possible database updates have been detected in the following extensions.')); $this->assertStatusCheckResults([$result], $stage); } diff --git a/package_manager/tests/src/Kernel/SupportedReleaseValidatorTest.php b/package_manager/tests/src/Kernel/SupportedReleaseValidatorTest.php index 4a67afb4c10cac5bcc61dc0215be2e99cd320bbe..9830ab0ff05fa7d77b7bff6c1f8dba051553a8fb 100644 --- a/package_manager/tests/src/Kernel/SupportedReleaseValidatorTest.php +++ b/package_manager/tests/src/Kernel/SupportedReleaseValidatorTest.php @@ -92,7 +92,7 @@ class SupportedReleaseValidatorTest extends PackageManagerKernelTestBase { 'install_path' => NULL, ], [ - ValidationResult::createError(['semver_test (drupal/semver_test) 8.2.0'], $summary), + ValidationResult::createError([t('semver_test (drupal/semver_test) 8.2.0')], $summary), ], ], 'legacy, supported update' => [ @@ -120,7 +120,7 @@ class SupportedReleaseValidatorTest extends PackageManagerKernelTestBase { 'install_path' => NULL, ], [ - ValidationResult::createError(['aaa_update_test (drupal/aaa_update_test) 3.0.0'], $summary), + ValidationResult::createError([t('aaa_update_test (drupal/aaa_update_test) 3.0.0')], $summary), ], ], 'aaa_automatic_updates_test(not in active), update to unsupported branch' => [ @@ -135,7 +135,7 @@ class SupportedReleaseValidatorTest extends PackageManagerKernelTestBase { 'install_path' => '../../modules/aaa_automatic_updates_test', ], [ - ValidationResult::createError(['aaa_automatic_updates_test (drupal/aaa_automatic_updates_test) 7.0.1-dev'], $summary), + ValidationResult::createError([t('aaa_automatic_updates_test (drupal/aaa_automatic_updates_test) 7.0.1-dev')], $summary), ], ], 'aaa_automatic_updates_test(not in active), update to supported branch' => [ diff --git a/package_manager/tests/src/Kernel/SymlinkValidatorTest.php b/package_manager/tests/src/Kernel/SymlinkValidatorTest.php index 9811cb35284c261abb4951a4d101dd46d67b06f0..1dbbda904cc62099f36a7ebe2f6d181d922883b4 100644 --- a/package_manager/tests/src/Kernel/SymlinkValidatorTest.php +++ b/package_manager/tests/src/Kernel/SymlinkValidatorTest.php @@ -67,7 +67,7 @@ class SymlinkValidatorTest extends PackageManagerKernelTestBase { $test_cases["$event event with symlinks"] = [ TRUE, [ - ValidationResult::createError(['Symlinks were found.']), + ValidationResult::createError([t('Symlinks were found.')]), ], $event, ]; diff --git a/package_manager/tests/src/Kernel/WritableFileSystemValidatorTest.php b/package_manager/tests/src/Kernel/WritableFileSystemValidatorTest.php index 0ad2304c58daeae3e903ed412db16a6fe29aa060..0ef49d5df216cf0070ffa45ce7c260e061a1282a 100644 --- a/package_manager/tests/src/Kernel/WritableFileSystemValidatorTest.php +++ b/package_manager/tests/src/Kernel/WritableFileSystemValidatorTest.php @@ -31,8 +31,8 @@ class WritableFileSystemValidatorTest extends PackageManagerKernelTestBase { */ public function providerWritable(): array { // The root and vendor paths are defined by ::createVirtualProject(). - $root_error = 'The Drupal directory "vfs://root/active" is not writable.'; - $vendor_error = 'The vendor directory "vfs://root/active/vendor" is not writable.'; + $root_error = t('The Drupal directory "vfs://root/active" is not writable.'); + $vendor_error = t('The vendor directory "vfs://root/active/vendor" is not writable.'); $summary = t('The file system is not writable.'); $writable_permission = 0777; $non_writable_permission = 0444; diff --git a/package_manager/tests/src/Kernel/XdebugValidatorTest.php b/package_manager/tests/src/Kernel/XdebugValidatorTest.php index b0e3b581f32ae6368ce24283c39b37e35f7aa230..7b13ca692dbd51a0ae240c5602e11ba82079003c 100644 --- a/package_manager/tests/src/Kernel/XdebugValidatorTest.php +++ b/package_manager/tests/src/Kernel/XdebugValidatorTest.php @@ -24,7 +24,7 @@ class XdebugValidatorTest extends PackageManagerKernelTestBase { } $result = ValidationResult::createWarning([ - 'Xdebug is enabled, which may have a negative performance impact on Package Manager and any modules that use it.', + t('Xdebug is enabled, which may have a negative performance impact on Package Manager and any modules that use it.'), ]); $this->assertStatusCheckResults([$result]); } diff --git a/package_manager/tests/src/Unit/ValidationResultTest.php b/package_manager/tests/src/Unit/ValidationResultTest.php index ccf221a8c372b0eb101cc2c25b01cd5bfd6f29fa..b64f3fbc777ac0ffdc9919c652bf780c57796116 100644 --- a/package_manager/tests/src/Unit/ValidationResultTest.php +++ b/package_manager/tests/src/Unit/ValidationResultTest.php @@ -33,8 +33,8 @@ class ValidationResultTest extends UnitTestCase { public function testOverallSeverity(): void { // An error and a warning should be counted as an error. $results = [ - ValidationResult::createError(['Boo!']), - ValidationResult::createWarning(['Moo!']), + ValidationResult::createError([t('Boo!')]), + ValidationResult::createWarning([t('Moo!')]), ]; $this->assertSame(SystemManager::REQUIREMENT_ERROR, ValidationResult::getOverallSeverity($results)); @@ -100,7 +100,7 @@ class ValidationResultTest extends UnitTestCase { public function providerCreateExceptions(): array { return [ '2 messages, no summary' => [ - ['Something is wrong', 'Something else is also wrong'], + [t('Something is wrong'), t('Something else is also wrong')], 'If more than one message is provided, a summary is required.', ], 'no messages' => [ @@ -119,11 +119,14 @@ class ValidationResultTest extends UnitTestCase { public function providerValidConstructorArguments(): array { return [ '1 message no summary' => [ - 'messages' => ['Something is wrong'], + 'messages' => [t('Something is wrong')], 'summary' => NULL, ], '2 messages has summary' => [ - 'messages' => ['Something is wrong', 'Something else is also wrong'], + 'messages' => [ + t('Something is wrong'), + t('Something else is also wrong'), + ], 'summary' => 'This sums it up.', ], ]; diff --git a/src/Validator/StagedProjectsValidator.php b/src/Validator/StagedProjectsValidator.php index 2bac253be6a4fe819e83cf10798c5fab79bf1b93..def20086af0c170e85d6318f1bbbb8f4e9a6bfc9 100644 --- a/src/Validator/StagedProjectsValidator.php +++ b/src/Validator/StagedProjectsValidator.php @@ -51,9 +51,7 @@ final class StagedProjectsValidator implements EventSubscriberInterface { $stage = $stage->getStageComposer(); } catch (\Throwable $e) { - $event->addError([ - $e->getMessage(), - ]); + $event->addErrorFromThrowable($e); return; } diff --git a/tests/src/Functional/UpdaterFormTest.php b/tests/src/Functional/UpdaterFormTest.php index f8350d13b143e08cd266bfc17aa20c397a325039..c3a075feb6c1c85c6c9bce10023653bcdd25fbc1 100644 --- a/tests/src/Functional/UpdaterFormTest.php +++ b/tests/src/Functional/UpdaterFormTest.php @@ -6,6 +6,7 @@ namespace Drupal\Tests\automatic_updates\Functional; use Drupal\automatic_updates_test\Datetime\TestTime; use Drupal\fixture_manipulator\StageFixtureManipulator; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\package_manager_test_validation\StagedDatabaseUpdateValidator; use Drupal\package_manager\Event\PostRequireEvent; use Drupal\package_manager\Event\PreApplyEvent; @@ -252,7 +253,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { public function testStatusCheckFailureWhenNoUpdateExists() { $assert_session = $this->assertSession(); $this->mockActiveCoreVersion('9.8.1'); - $message = "You've not experienced Shakespeare until you have read him in the original Klingon."; + $message = t("You've not experienced Shakespeare until you have read him in the original Klingon."); $result = ValidationResult::createError([$message]); TestSubscriber1::setTestResult([$result], StatusCheckEvent::class); $this->checkForUpdates(); @@ -781,7 +782,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { // Set an error before completing the update. This error should be visible // on admin pages after completing the update without having to explicitly // run the status checks. - TestSubscriber1::setTestResult([ValidationResult::createError(['Error before continue.'])], StatusCheckEvent::class); + TestSubscriber1::setTestResult([ValidationResult::createError([t('Error before continue.')])], StatusCheckEvent::class); if ($has_database_updates) { // Simulate a staged database update in the automatic_updates_test module. // We must do this after the update has started, because the pending @@ -946,9 +947,9 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { $this->assertUpdateStagedTimes(1); $error_messages = [ - "The only thing we're allowed to do is to", - "believe that we won't regret the choice", - "we made.", + t("The only thing we're allowed to do is to"), + t("believe that we won't regret the choice"), + t("we made."), ]; $summary = t('some generic summary'); $error = ValidationResult::createError($error_messages, $summary); @@ -976,9 +977,9 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { $this->assertUpdateStagedTimes(1); $messages = [ - "The only thing we're allowed to do is to", - "believe that we won't regret the choice", - "we made.", + t("The only thing we're allowed to do is to"), + t("believe that we won't regret the choice"), + t("we made."), ]; $summary = t('some generic summary'); $warning = ValidationResult::createWarning($messages, $summary); @@ -996,12 +997,12 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { /** * Sets an error message, runs status checks, and asserts it is displayed. * - * @return string + * @return \Drupal\Core\StringTranslation\TranslatableMarkup * The cached error check message. */ - private function setAndAssertCachedMessage(): string { + private function setAndAssertCachedMessage(): TranslatableMarkup { // Store a status error, which will be cached. - $message = "You've not experienced Shakespeare until you have read him in the original Klingon."; + $message = t("You've not experienced Shakespeare until you have read him in the original Klingon."); $result = ValidationResult::createError([$message]); TestSubscriber1::setTestResult([$result], StatusCheckEvent::class); // Run the status checks a visit an admin page the message will be diff --git a/tests/src/Kernel/CronUpdaterTest.php b/tests/src/Kernel/CronUpdaterTest.php index cfb33249a73232bcaec51c66a5a6dc4a7bf82bd2..d73154f37ce2cbb715350c201330c74f0bff4628 100644 --- a/tests/src/Kernel/CronUpdaterTest.php +++ b/tests/src/Kernel/CronUpdaterTest.php @@ -280,7 +280,7 @@ class CronUpdaterTest extends AutomaticUpdatesKernelTestBase { // (if the exception class is StageValidationException). if ($exception_class === StageValidationException::class) { $results = [ - ValidationResult::createError(['Destroy the stage!']), + ValidationResult::createError([t('Destroy the stage!')]), ]; TestSubscriber1::setTestResult($results, $event_class); $exception = new StageValidationException($results); @@ -500,7 +500,7 @@ END; ->save(); $results = [ - ValidationResult::createError(['Error while updating!']), + ValidationResult::createError([t('Error while updating!')]), ]; TestSubscriber1::setTestResult($results, $event_class); $exception = new StageValidationException($results); @@ -537,7 +537,7 @@ END; ->setCorePackageVersion('9.8.1') ->setReadyToCommit(); $results = [ - ValidationResult::createError(['Error while updating!']), + ValidationResult::createError([t('Error while updating!')]), ]; TestSubscriber1::setTestResult($results, $event_class); $exception = new StageValidationException($results); diff --git a/tests/src/Kernel/StatusCheck/CronFrequencyValidatorTest.php b/tests/src/Kernel/StatusCheck/CronFrequencyValidatorTest.php index 7009c957029e06f4c07e0163a3588a23937af4d2..5915984b7e8c076a79d7ecf3528d4e10c7380229 100644 --- a/tests/src/Kernel/StatusCheck/CronFrequencyValidatorTest.php +++ b/tests/src/Kernel/StatusCheck/CronFrequencyValidatorTest.php @@ -80,7 +80,7 @@ class CronFrequencyValidatorTest extends AutomaticUpdatesKernelTestBase { */ public function providerLastCronRunValidation(): array { $error = ValidationResult::createError([ - 'Cron has not run recently. For more information, see the online handbook entry for <a href="https://www.drupal.org/cron">configuring cron jobs</a> to run at least every 3 hours.', + t('Cron has not run recently. For more information, see the online handbook entry for <a href="https://www.drupal.org/cron">configuring cron jobs</a> to run at least every 3 hours.'), ]); return [ @@ -134,7 +134,7 @@ class CronFrequencyValidatorTest extends AutomaticUpdatesKernelTestBase { 21600, [ ValidationResult::createWarning([ - 'Cron is not set to run frequently enough. <a href="/admin/config/system/cron">Configure it</a> to run at least every 3 hours or disable automated cron and run it via an external scheduling system.', + t('Cron is not set to run frequently enough. <a href="/admin/config/system/cron">Configure it</a> to run at least every 3 hours or disable automated cron and run it via an external scheduling system.'), ]), ], ], @@ -142,7 +142,7 @@ class CronFrequencyValidatorTest extends AutomaticUpdatesKernelTestBase { 90000, [ ValidationResult::createError([ - 'Cron is not set to run frequently enough. <a href="/admin/config/system/cron">Configure it</a> to run at least every 3 hours or disable automated cron and run it via an external scheduling system.', + t('Cron is not set to run frequently enough. <a href="/admin/config/system/cron">Configure it</a> to run at least every 3 hours or disable automated cron and run it via an external scheduling system.'), ]), ], ], diff --git a/tests/src/Kernel/StatusCheck/CronServerValidatorTest.php b/tests/src/Kernel/StatusCheck/CronServerValidatorTest.php index 7b980e2a3d060d98e480b4e8651c2ba47b975e97..7d1555a23790b8197bb4353c18c5322598423844 100644 --- a/tests/src/Kernel/StatusCheck/CronServerValidatorTest.php +++ b/tests/src/Kernel/StatusCheck/CronServerValidatorTest.php @@ -37,7 +37,7 @@ class CronServerValidatorTest extends AutomaticUpdatesKernelTestBase { */ public function providerCronServerValidation(): array { $error = ValidationResult::createError([ - 'Your site appears to be running on the built-in PHP web server on port 80. Drupal cannot be automatically updated with this configuration unless the site can also be reached on an alternate port.', + t('Your site appears to be running on the built-in PHP web server on port 80. Drupal cannot be automatically updated with this configuration unless the site can also be reached on an alternate port.'), ]); // Add all the test cases where there no expected results for all cron // modes. diff --git a/tests/src/Kernel/StatusCheck/ScaffoldFilePermissionsValidatorTest.php b/tests/src/Kernel/StatusCheck/ScaffoldFilePermissionsValidatorTest.php index 61ad0876c919e542b36796c6095655bb94fc6d52..d5d163cfb3b361aa1a04c3f9610ef473a6fd218b 100644 --- a/tests/src/Kernel/StatusCheck/ScaffoldFilePermissionsValidatorTest.php +++ b/tests/src/Kernel/StatusCheck/ScaffoldFilePermissionsValidatorTest.php @@ -80,7 +80,7 @@ class ScaffoldFilePermissionsValidatorTest extends AutomaticUpdatesKernelTestBas 'write-protected scaffold file, writable site directory' => [ ['sites/default/default.settings.php'], [ - ValidationResult::createError(['sites/default/default.settings.php']), + ValidationResult::createError([t('sites/default/default.settings.php')]), ], ], // Whether the site directory is write-protected only matters during @@ -93,7 +93,7 @@ class ScaffoldFilePermissionsValidatorTest extends AutomaticUpdatesKernelTestBas 'sites/default', ], [ - ValidationResult::createError(['sites/default/default.settings.php']), + ValidationResult::createError([t('sites/default/default.settings.php')]), ], ], 'write-protected site directory' => [ @@ -167,7 +167,7 @@ class ScaffoldFilePermissionsValidatorTest extends AutomaticUpdatesKernelTestBas '[web-root]/sites/default/new.txt' => '', ], [ - ValidationResult::createError(['sites/default']), + ValidationResult::createError([t('sites/default')]), ], ], 'new scaffold file added to writable site directory' => [ @@ -185,7 +185,7 @@ class ScaffoldFilePermissionsValidatorTest extends AutomaticUpdatesKernelTestBas ], [], [ - ValidationResult::createError(['sites/default']), + ValidationResult::createError([t('sites/default')]), ], ], 'writable scaffold file removed from writable site directory' => [ @@ -208,7 +208,10 @@ class ScaffoldFilePermissionsValidatorTest extends AutomaticUpdatesKernelTestBas ], [], [ - ValidationResult::createError(['sites/default', 'sites/default/deleted.txt'], $summary), + ValidationResult::createError([ + t('sites/default'), + t('sites/default/deleted.txt'), + ], $summary), ], ], 'non-writable scaffold file removed from writable site directory' => [ @@ -218,7 +221,7 @@ class ScaffoldFilePermissionsValidatorTest extends AutomaticUpdatesKernelTestBas ], [], [ - ValidationResult::createError(['sites/default/deleted.txt']), + ValidationResult::createError([t('sites/default/deleted.txt')]), ], ], // If only scaffold files outside the site directory changed, the diff --git a/tests/src/Kernel/StatusCheck/StagedProjectsValidatorTest.php b/tests/src/Kernel/StatusCheck/StagedProjectsValidatorTest.php index b80b7c01970e90f0688a1b45c09e53d0ba3958ca..5ccbc1da0eeea9c3e74f2c1a8bb5ddceac4ee7dc 100644 --- a/tests/src/Kernel/StatusCheck/StagedProjectsValidatorTest.php +++ b/tests/src/Kernel/StatusCheck/StagedProjectsValidatorTest.php @@ -58,7 +58,7 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase { $updater->begin(['drupal' => '9.8.1']); $updater->stage(); - $error = ValidationResult::createError(["Composer could not find the config file: $composer_json\n"]); + $error = ValidationResult::createError([t("Composer could not find the config file: @composer_json\n", ["@composer_json" => $composer_json])]); try { $updater->apply(); $this->fail('Expected an error, but none was raised.'); @@ -143,8 +143,8 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase { ->setReadyToCommit(); $messages = [ - "module 'drupal/test_module2' installed.", - "custom module 'drupal/dev-test_module2' installed.", + t("module 'drupal/test_module2' installed."), + t("custom module 'drupal/dev-test_module2' installed."), ]; $error = ValidationResult::createError($messages, t('The update cannot proceed because the following Drupal projects were installed during the update.')); @@ -222,8 +222,8 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase { ->setReadyToCommit(); $messages = [ - "theme 'drupal/test_theme' removed.", - "custom theme 'drupal/dev-test_theme' removed.", + t("theme 'drupal/test_theme' removed."), + t("custom theme 'drupal/dev-test_theme' removed."), ]; $error = ValidationResult::createError($messages, t('The update cannot proceed because the following Drupal projects were removed during the update.')); $updater = $this->container->get('automatic_updates.updater'); @@ -285,8 +285,8 @@ class StagedProjectsValidatorTest extends AutomaticUpdatesKernelTestBase { ->setReadyToCommit(); $messages = [ - "module 'drupal/test_module' from 1.3.0 to 1.3.1.", - "module 'drupal/dev-test_module' from 1.3.0 to 1.3.1.", + t("module 'drupal/test_module' from 1.3.0 to 1.3.1."), + t("module 'drupal/dev-test_module' from 1.3.0 to 1.3.1."), ]; $error = ValidationResult::createError($messages, t('The update cannot proceed because the following Drupal projects were unexpectedly updated. Only Drupal Core updates are currently supported.')); $updater = $this->container->get('automatic_updates.updater'); diff --git a/tests/src/Kernel/StatusCheck/VersionPolicyValidatorTest.php b/tests/src/Kernel/StatusCheck/VersionPolicyValidatorTest.php index 8001bc1455ae07c6a72d91f6d8eac97122be2bc7..ea7aa571d1885705ec7633832d9d976ad3c79fb1 100644 --- a/tests/src/Kernel/StatusCheck/VersionPolicyValidatorTest.php +++ b/tests/src/Kernel/StatusCheck/VersionPolicyValidatorTest.php @@ -50,7 +50,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase { [CronUpdater::DISABLED, CronUpdater::SECURITY, CronUpdater::ALL], [ $this->createVersionPolicyValidationResult('9.8.0-dev', NULL, [ - 'Drupal cannot be automatically updated from the installed version, 9.8.0-dev, because automatic updates from a dev version to any other version are not supported.', + t('Drupal cannot be automatically updated from the installed version, 9.8.0-dev, because automatic updates from a dev version to any other version are not supported.'), ]), ], ], @@ -68,7 +68,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase { [CronUpdater::SECURITY, CronUpdater::ALL], [ $this->createVersionPolicyValidationResult('9.8.0-alpha1', NULL, [ - 'Drupal cannot be automatically updated during cron from its current version, 9.8.0-alpha1, because it is not a stable version.', + t('Drupal cannot be automatically updated during cron from its current version, 9.8.0-alpha1, because it is not a stable version.'), ]), ], ], @@ -84,7 +84,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase { [CronUpdater::SECURITY, CronUpdater::ALL], [ $this->createVersionPolicyValidationResult('9.8.0-beta2', NULL, [ - 'Drupal cannot be automatically updated during cron from its current version, 9.8.0-beta2, because it is not a stable version.', + t('Drupal cannot be automatically updated during cron from its current version, 9.8.0-beta2, because it is not a stable version.'), ]), ], ], @@ -100,7 +100,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase { [CronUpdater::SECURITY, CronUpdater::ALL], [ $this->createVersionPolicyValidationResult('9.8.0-rc3', NULL, [ - 'Drupal cannot be automatically updated during cron from its current version, 9.8.0-rc3, because it is not a stable version.', + t('Drupal cannot be automatically updated during cron from its current version, 9.8.0-rc3, because it is not a stable version.'), ]), ], ], @@ -134,8 +134,8 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase { [CronUpdater::SECURITY, CronUpdater::ALL], [ $this->createVersionPolicyValidationResult('9.7.1', NULL, [ - 'The currently installed version of Drupal core, 9.7.1, is not in a supported minor version. Your site will not be automatically updated during cron until it is updated to a supported minor version.', - 'See the <a href="/admin/reports/updates">available updates page</a> for available updates.', + t('The currently installed version of Drupal core, 9.7.1, is not in a supported minor version. Your site will not be automatically updated during cron until it is updated to a supported minor version.'), + t('See the <a href="/admin/reports/updates">available updates page</a> for available updates.'), ]), ], ], @@ -145,8 +145,8 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase { [CronUpdater::SECURITY, CronUpdater::ALL], [ $this->createVersionPolicyValidationResult('9.7.1', NULL, [ - 'The currently installed version of Drupal core, 9.7.1, is not in a supported minor version. Your site will not be automatically updated during cron until it is updated to a supported minor version.', - 'Use the <a href="/admin/modules/update">update form</a> to update to a supported version.', + t('The currently installed version of Drupal core, 9.7.1, is not in a supported minor version. Your site will not be automatically updated during cron until it is updated to a supported minor version.'), + t('Use the <a href="/admin/modules/update">update form</a> to update to a supported version.'), ]), ], TRUE, @@ -204,7 +204,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase { ['drupal' => '9.8.1'], [ $this->createVersionPolicyValidationResult('9.8.0-dev', '9.8.1', [ - 'Drupal cannot be automatically updated from the installed version, 9.8.0-dev, because automatic updates from a dev version to any other version are not supported.', + t('Drupal cannot be automatically updated from the installed version, 9.8.0-dev, because automatic updates from a dev version to any other version are not supported.'), ]), ], ], @@ -216,7 +216,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase { ['drupal' => '9.8.0'], [ $this->createVersionPolicyValidationResult('9.8.1', '9.8.0', [ - 'Update version 9.8.0 is lower than 9.8.1, downgrading is not supported.', + t('Update version 9.8.0 is lower than 9.8.1, downgrading is not supported.'), ]), ], ], @@ -226,7 +226,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase { ['drupal' => '9.8.2'], [ $this->createVersionPolicyValidationResult('8.9.1', '9.8.2', [ - 'Drupal cannot be automatically updated from 8.9.1 to 9.8.2 because automatic updates from one major version to another are not supported.', + t('Drupal cannot be automatically updated from 8.9.1 to 9.8.2 because automatic updates from one major version to another are not supported.'), ]), ], ], @@ -236,7 +236,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase { ['drupal' => '9.8.1'], [ $this->createVersionPolicyValidationResult('9.8.0', '9.8.1', [ - 'Cannot update Drupal core to 9.8.1 because it is not in the list of installable releases.', + t('Cannot update Drupal core to 9.8.1 because it is not in the list of installable releases.'), ]), ], ], @@ -257,7 +257,7 @@ class VersionPolicyValidatorTest extends AutomaticUpdatesKernelTestBase { ['drupal' => '9.8.2'], [ $this->createVersionPolicyValidationResult('9.7.9', '9.8.2', [ - 'Drupal cannot be automatically updated from 9.7.9 to 9.8.2 because automatic updates from one minor version to another are not supported.', + t('Drupal cannot be automatically updated from 9.7.9 to 9.8.2 because automatic updates from one minor version to another are not supported.'), ]), ], ], diff --git a/tests/src/Kernel/UpdaterTest.php b/tests/src/Kernel/UpdaterTest.php index c19b4ad9a3564b83b0da0537145cbd655bd2d4f7..7c24da9ca36fb661e05f87fd2830b1d197d724b0 100644 --- a/tests/src/Kernel/UpdaterTest.php +++ b/tests/src/Kernel/UpdaterTest.php @@ -220,7 +220,7 @@ class UpdaterTest extends AutomaticUpdatesKernelTestBase { public function testUpdateException(string $event_class) { $updater = $this->container->get('automatic_updates.updater'); $results = [ - ValidationResult::createError(['An error of some sorts.']), + ValidationResult::createError([t('An error of some sorts.')]), ]; TestSubscriber1::setTestResult($results, $event_class); try { diff --git a/tests/src/Kernel/ValidationResultDisplayTraitTest.php b/tests/src/Kernel/ValidationResultDisplayTraitTest.php index 7bdbec570d1619e6ebb90952249b57f350f7529e..71e03c825a1a718e18dac1ecfffac54aa5f76c6c 100644 --- a/tests/src/Kernel/ValidationResultDisplayTraitTest.php +++ b/tests/src/Kernel/ValidationResultDisplayTraitTest.php @@ -35,10 +35,10 @@ class ValidationResultDisplayTraitTest extends AutomaticUpdatesKernelTestBase { // An error and a warning should display the error preamble, and the result // messages as errors and warnings, respectively. $results = [ - ValidationResult::createError(['Boo!']), - ValidationResult::createError(['Wednesday', 'Lurch'], $this->t('The Addams Family')), - ValidationResult::createWarning(['Moo!']), - ValidationResult::createWarning(['Shaggy', 'The dog'], $this->t('Mystery Mobile')), + ValidationResult::createError([t('Boo!')]), + ValidationResult::createError([t('Wednesday'), t('Lurch')], $this->t('The Addams Family')), + ValidationResult::createWarning([t('Moo!')]), + ValidationResult::createWarning([t('Shaggy'), t('The dog')], $this->t('Mystery Mobile')), ]; $this->displayResults($results, $messenger, $renderer); diff --git a/tests/src/Traits/ValidationTestTrait.php b/tests/src/Traits/ValidationTestTrait.php index e0e88a60a243f5ed55307c2724834eeeb5d3014e..82f399645143249ef51a4aba55ca9367d8849bd2 100644 --- a/tests/src/Traits/ValidationTestTrait.php +++ b/tests/src/Traits/ValidationTestTrait.php @@ -48,7 +48,7 @@ trait ValidationTestTrait { $messages = []; $random = $this->randomMachineName(64); for ($i = 0; $i < $message_count; $i++) { - $messages[] = "Message $i $random"; + $messages[] = t("Message @i @random", ['@i' => $i, '@random' => $random]); } $summary = t('Summary @random', ['@random' => $random]); switch ($severity) {