diff --git a/core/modules/comment/tests/src/Kernel/Views/CommentUserNameTest.php b/core/modules/comment/tests/src/Kernel/Views/CommentUserNameTest.php index 80820e96028dcff1db827fcc0d4a1e5c3ee41350..61b21e753c19040468046277dc8a4a332a43c77d 100644 --- a/core/modules/comment/tests/src/Kernel/Views/CommentUserNameTest.php +++ b/core/modules/comment/tests/src/Kernel/Views/CommentUserNameTest.php @@ -7,6 +7,7 @@ use Drupal\comment\Entity\Comment; use Drupal\comment\Entity\CommentType; use Drupal\Core\Session\AnonymousUserSession; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\entity_test\Entity\EntityTest; use Drupal\Tests\views\Kernel\ViewsKernelTestBase; use Drupal\user\Entity\Role; @@ -21,6 +22,8 @@ */ class CommentUserNameTest extends ViewsKernelTestBase { + use StringTranslationTrait; + /** * Admin user. * @@ -83,7 +86,7 @@ protected function setUp($import_test_views = TRUE): void { $commentType = CommentType::create([ 'id' => 'entity_test_comment', - 'label' => t('Entity Test Comment'), + 'label' => $this->t('Entity Test Comment'), 'target_entity_type_id' => 'entity_test', ]); $commentType->save(); diff --git a/core/modules/language/tests/src/Kernel/Views/LanguageTestBase.php b/core/modules/language/tests/src/Kernel/Views/LanguageTestBase.php index 6d526ab7628ed9c5cbaf7d471424db9c8b9dba32..05661ddda360ed7cc0ace7c97b43beac2389153f 100644 --- a/core/modules/language/tests/src/Kernel/Views/LanguageTestBase.php +++ b/core/modules/language/tests/src/Kernel/Views/LanguageTestBase.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\language\Kernel\Views; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\Tests\views\Kernel\ViewsKernelTestBase; @@ -12,6 +13,8 @@ */ abstract class LanguageTestBase extends ViewsKernelTestBase { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -49,8 +52,8 @@ protected function schemaDefinition() { protected function viewsData() { $data = parent::viewsData(); $data['views_test_data']['langcode'] = [ - 'title' => t('Langcode'), - 'help' => t('Langcode'), + 'title' => $this->t('Langcode'), + 'help' => $this->t('Langcode'), 'field' => [ 'id' => 'language', ], diff --git a/core/modules/locale/tests/src/Kernel/LocaleStringIsSafeTest.php b/core/modules/locale/tests/src/Kernel/LocaleStringIsSafeTest.php index 525aad05495a0c640ffd0801316114d78745cbfd..47311d68bae1e7feb130dfbcb0d61fe791ccfd79 100644 --- a/core/modules/locale/tests/src/Kernel/LocaleStringIsSafeTest.php +++ b/core/modules/locale/tests/src/Kernel/LocaleStringIsSafeTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\locale\Kernel; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\KernelTests\KernelTestBase; /** @@ -13,6 +14,8 @@ */ class LocaleStringIsSafeTest extends KernelTestBase { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -75,7 +78,7 @@ public function testLocalizedTokenizedString(): void { // Pass the original string to the t() function to get it marked as safe. // phpcs:ignore Drupal.Semantics.FunctionT.NotLiteralString - $safe_string = t($original_string); + $safe_string = $this->t($original_string); $rendered_safe_string = \Drupal::theme()->render('locale_test_tokenized', ['content' => $safe_string]); // t() function always marks the string as safe so it won't be escaped, // and should be the same as the original. diff --git a/core/modules/migrate/tests/src/Kernel/MigrateEntityContentValidationTest.php b/core/modules/migrate/tests/src/Kernel/MigrateEntityContentValidationTest.php index 6bc3d633be443e9709707aed31648e16d0b4b252..648f3b6099e7b6018045b6df0671cb9dc6fe4e69 100644 --- a/core/modules/migrate/tests/src/Kernel/MigrateEntityContentValidationTest.php +++ b/core/modules/migrate/tests/src/Kernel/MigrateEntityContentValidationTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\migrate\Kernel; use Drupal\Component\Render\FormattableMarkup; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\filter\Entity\FilterFormat; @@ -25,6 +26,8 @@ */ class MigrateEntityContentValidationTest extends KernelTestBase { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -155,7 +158,7 @@ public function test2(): void { ]); $this->assertSame(sprintf('1: [user]: name=%s||name=%s||mail=Email field is required.', $username_constraint->illegalMessage, new FormattableMarkup($username_constraint->tooLongMessage, ['%name' => $long_username, '%max' => 60])), $this->messages[0], 'First message should have 3 validation errors.'); // phpcs:ignore Drupal.Semantics.FunctionT.NotLiteralString - $this->assertSame(sprintf('1: [user]: name=%s||name=%s||mail=Email field is required.', $username_constraint->illegalMessage, t($username_constraint->tooLongMessage, ['%name' => $long_username, '%max' => 60])), $this->messages[0], 'First message should have 3 validation errors.'); + $this->assertSame(sprintf('1: [user]: name=%s||name=%s||mail=Email field is required.', $username_constraint->illegalMessage, $this->t($username_constraint->tooLongMessage, ['%name' => $long_username, '%max' => 60])), $this->messages[0], 'First message should have 3 validation errors.'); $this->assertSame(sprintf('2: [user]: name=%s||mail=Email field is required.', $username_constraint->illegalMessage), $this->messages[1], 'Second message should have 2 validation errors.'); $this->assertSame(sprintf('3: [user]: name=%s||mail=Email field is required.', $username_constraint->illegalMessage), $this->messages[2], 'Third message should have 2 validation errors.'); $this->assertArrayNotHasKey(3, $this->messages, 'Fourth message should not exist.'); diff --git a/core/modules/package_manager/tests/src/Kernel/AllowedScaffoldPackagesValidatorTest.php b/core/modules/package_manager/tests/src/Kernel/AllowedScaffoldPackagesValidatorTest.php index f7ebc28da1d7a09c0e0180fa6eda822f6c17947e..bf064f4e2bf1fedc6e4814bf4aa5b039264c89ba 100644 --- a/core/modules/package_manager/tests/src/Kernel/AllowedScaffoldPackagesValidatorTest.php +++ b/core/modules/package_manager/tests/src/Kernel/AllowedScaffoldPackagesValidatorTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\package_manager\Kernel; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\fixture_manipulator\ActiveFixtureManipulator; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreCreateEvent; @@ -16,6 +17,8 @@ */ class AllowedScaffoldPackagesValidatorTest extends PackageManagerKernelTestBase { + use StringTranslationTrait; + /** * Tests that the allowed-packages setting is validated during pre-create. */ @@ -29,10 +32,10 @@ public function testPreCreate(): void { $result = ValidationResult::createError( [ - t("drupal/dummy_scaffolding"), - t("drupal/dummy_scaffolding_2"), + $this->t("drupal/dummy_scaffolding"), + $this->t("drupal/dummy_scaffolding_2"), ], - t('Any packages other than the implicitly allowed packages are not allowed to scaffold files. See <a href="https://www.drupal.org/docs/develop/using-composer/using-drupals-composer-scaffold">the scaffold documentation</a> for more information.') + $this->t('Any packages other than the implicitly allowed packages are not allowed to scaffold files. See <a href="https://www.drupal.org/docs/develop/using-composer/using-drupals-composer-scaffold">the scaffold documentation</a> for more information.') ); $this->assertStatusCheckResults([$result]); $this->assertResults([$result], PreCreateEvent::class); @@ -51,9 +54,9 @@ public function testPreApply(): void { $result = ValidationResult::createError( [ - t("drupal/dummy_scaffolding"), + $this->t("drupal/dummy_scaffolding"), ], - t('Any packages other than the implicitly allowed packages are not allowed to scaffold files. See <a href="https://www.drupal.org/docs/develop/using-composer/using-drupals-composer-scaffold">the scaffold documentation</a> for more information.') + $this->t('Any packages other than the implicitly allowed packages are not allowed to scaffold files. See <a href="https://www.drupal.org/docs/develop/using-composer/using-drupals-composer-scaffold">the scaffold documentation</a> for more information.') ); $this->assertResults([$result], PreApplyEvent::class); } diff --git a/core/modules/package_manager/tests/src/Kernel/BaseRequirementsFulfilledValidatorTest.php b/core/modules/package_manager/tests/src/Kernel/BaseRequirementsFulfilledValidatorTest.php index 56c8984388b3d482dc72167d9fb46be296eb34a5..06afcf8aeaffb2462d4205b14ac4d7e7478f02fa 100644 --- a/core/modules/package_manager/tests/src/Kernel/BaseRequirementsFulfilledValidatorTest.php +++ b/core/modules/package_manager/tests/src/Kernel/BaseRequirementsFulfilledValidatorTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\package_manager\Kernel; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreOperationStageEvent; @@ -23,6 +24,7 @@ class BaseRequirementsFulfilledValidatorTest extends PackageManagerKernelTestBase implements EventSubscriberInterface { use BaseRequirementValidatorTrait; + use StringTranslationTrait; /** * The event class to throw to an error for. @@ -37,7 +39,7 @@ class BaseRequirementsFulfilledValidatorTest extends PackageManagerKernelTestBas public function validate(PreOperationStageEvent $event): void { if (get_class($event) === $this->eventClass) { $event->addError([ - t('This will not stand!'), + $this->t('This will not stand!'), ]); } } @@ -81,7 +83,7 @@ public function testBaseRequirement(string $event_class): void { $this->assertEventPropagationStopped($event_class, [$validator, 'validate']); $result = ValidationResult::createError([ - t('This will not stand!'), + $this->t('This will not stand!'), ]); if ($event_class === StatusCheckEvent::class) { diff --git a/core/modules/package_manager/tests/src/Kernel/ComposerMinimumStabilityValidatorTest.php b/core/modules/package_manager/tests/src/Kernel/ComposerMinimumStabilityValidatorTest.php index ce6c4a60a4b8ac6e6c90230d6abce662aa600090..0e4a1eab9a6175cfc7c7cb88456055dd5233cbc3 100644 --- a/core/modules/package_manager/tests/src/Kernel/ComposerMinimumStabilityValidatorTest.php +++ b/core/modules/package_manager/tests/src/Kernel/ComposerMinimumStabilityValidatorTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\package_manager\Kernel; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\package_manager\Exception\StageEventException; use Drupal\package_manager\ValidationResult; @@ -14,6 +15,8 @@ */ class ComposerMinimumStabilityValidatorTest extends PackageManagerKernelTestBase { + use StringTranslationTrait; + /** * Tests error if requested version is less stable than the minimum: stable. */ @@ -21,7 +24,7 @@ public function testPreRequireEvent(): void { $stage = $this->createStage(); $stage->create(); $result = ValidationResult::createError([ - t("<code>drupal/core</code>'s requested version 9.8.1-beta1 is less stable (beta) than the minimum stability (stable) required in <PROJECT_ROOT>/composer.json."), + $this->t("<code>drupal/core</code>'s requested version 9.8.1-beta1 is less stable (beta) than the minimum stability (stable) required in <PROJECT_ROOT>/composer.json."), ]); try { $stage->require(['drupal/core:9.8.1-beta1']); @@ -40,7 +43,7 @@ public function testPreRequireEvent(): void { // Dev packages are also checked. $stage->create(); $result = ValidationResult::createError([ - t("<code>drupal/core-dev</code>'s requested version 9.8.x-dev is less stable (dev) than the minimum stability (stable) required in <PROJECT_ROOT>/composer.json."), + $this->t("<code>drupal/core-dev</code>'s requested version 9.8.x-dev is less stable (dev) than the minimum stability (stable) required in <PROJECT_ROOT>/composer.json."), ]); try { $stage->require([], ['drupal/core-dev:9.8.x-dev']); diff --git a/core/modules/package_manager/tests/src/Kernel/ComposerPatchesValidatorTest.php b/core/modules/package_manager/tests/src/Kernel/ComposerPatchesValidatorTest.php index 4d1e72fbea04b031a9e1487724a5f737de427ab8..27ce47ab37331d49297a50a275a321c4b3ff9f1d 100644 --- a/core/modules/package_manager/tests/src/Kernel/ComposerPatchesValidatorTest.php +++ b/core/modules/package_manager/tests/src/Kernel/ComposerPatchesValidatorTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\package_manager\Kernel; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\fixture_manipulator\ActiveFixtureManipulator; use Drupal\package_manager\Event\PreCreateEvent; @@ -18,6 +19,8 @@ */ class ComposerPatchesValidatorTest extends PackageManagerKernelTestBase { + use StringTranslationTrait; + const ABSENT = 0; const CONFIG_ALLOWED_PLUGIN = 1; const EXTRA_EXIT_ON_PATCH_FAILURE = 2; @@ -283,7 +286,7 @@ public function testErrorDuringPreApplyWithHelp(int $in_active, int $in_stage, a ->toString(); // Reformat the provided results so that they all have the link to the // online documentation appended to them. - $messages[$message_index] = t('@message See <a href=":url">the help page</a> for information on how to resolve the problem.', ['@message' => $message, ':url' => $url]); + $messages[$message_index] = $this->t('@message See <a href=":url">the help page</a> for information on how to resolve the problem.', ['@message' => $message, ':url' => $url]); } } $expected_results[$result_index] = ValidationResult::createError($messages, $result->summary); diff --git a/core/modules/package_manager/tests/src/Kernel/ComposerValidatorTest.php b/core/modules/package_manager/tests/src/Kernel/ComposerValidatorTest.php index e5d2e2bc68384fb6ab4af9a0adc73b2cb3dc9afb..5615a76c67318a738f498f5e7b139baafdd276f8 100644 --- a/core/modules/package_manager/tests/src/Kernel/ComposerValidatorTest.php +++ b/core/modules/package_manager/tests/src/Kernel/ComposerValidatorTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\package_manager\Kernel; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\fixture_manipulator\ActiveFixtureManipulator; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreCreateEvent; @@ -16,6 +17,8 @@ */ class ComposerValidatorTest extends PackageManagerKernelTestBase { + use StringTranslationTrait; + /** * Data provider for testComposerSettingsValidation(). * @@ -156,7 +159,7 @@ public function testLinkToOnlineHelp(array $config, array $expected_messages): v $this->enableModules(['help']); (new ActiveFixtureManipulator())->addConfig($config)->commitChanges(); - $result = ValidationResult::createError($expected_messages, t("Composer settings don't satisfy Package Manager's requirements.")); + $result = ValidationResult::createError($expected_messages, $this->t("Composer settings don't satisfy Package Manager's requirements.")); $this->assertStatusCheckResults([$result]); } diff --git a/core/modules/package_manager/tests/src/Kernel/EnvironmentSupportValidatorTest.php b/core/modules/package_manager/tests/src/Kernel/EnvironmentSupportValidatorTest.php index 2e9a3909bf9c583d688e68a909ecc586856688b8..7ae3424270f843cd98d649f18a47c0cb0be33d1d 100644 --- a/core/modules/package_manager/tests/src/Kernel/EnvironmentSupportValidatorTest.php +++ b/core/modules/package_manager/tests/src/Kernel/EnvironmentSupportValidatorTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\package_manager\Kernel; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\StatusCheckEvent; @@ -17,6 +18,8 @@ */ class EnvironmentSupportValidatorTest extends PackageManagerKernelTestBase { + use StringTranslationTrait; + /** * Tests handling of an invalid URL in the environment support variable. */ @@ -24,7 +27,7 @@ public function testInvalidUrl(): void { putenv(EnvironmentSupportValidator::VARIABLE_NAME . '=broken/url.org'); $result = ValidationResult::createError([ - t('Package Manager is not supported by your environment.'), + $this->t('Package Manager is not supported by your environment.'), ]); foreach ([PreCreateEvent::class, StatusCheckEvent::class] as $event_class) { $this->assertEventPropagationStopped($event_class, [$this->container->get(EnvironmentSupportValidator::class), 'validate']); @@ -42,7 +45,7 @@ public function testInvalidUrlDuringPreApply(): void { }); $result = ValidationResult::createError([ - t('Package Manager is not supported by your environment.'), + $this->t('Package Manager is not supported by your environment.'), ]); $this->assertEventPropagationStopped(PreApplyEvent::class, [$this->container->get(EnvironmentSupportValidator::class), 'validate']); @@ -57,7 +60,7 @@ public function testValidUrl(): void { putenv(EnvironmentSupportValidator::VARIABLE_NAME . '=' . $url); $result = ValidationResult::createError([ - t('<a href=":url">Package Manager is not supported by your environment.</a>', [':url' => $url]), + $this->t('<a href=":url">Package Manager is not supported by your environment.</a>', [':url' => $url]), ]); $this->assertStatusCheckResults([$result]); $this->assertResults([$result], PreCreateEvent::class); @@ -73,7 +76,7 @@ public function testValidUrlDuringPreApply(): void { }); $result = ValidationResult::createError([ - t('<a href=":url">Package Manager is not supported by your environment.</a>', [':url' => $url]), + $this->t('<a href=":url">Package Manager is not supported by your environment.</a>', [':url' => $url]), ]); $this->assertResults([$result], PreApplyEvent::class); } diff --git a/core/modules/package_manager/tests/src/Kernel/FailureMarkerTest.php b/core/modules/package_manager/tests/src/Kernel/FailureMarkerTest.php index a41de4a9220019324b5ea73750a5ccd78232594b..9ca7a0d3803ae48a8ff50e74c3d3007291a20a07 100644 --- a/core/modules/package_manager/tests/src/Kernel/FailureMarkerTest.php +++ b/core/modules/package_manager/tests/src/Kernel/FailureMarkerTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\package_manager\Kernel; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\package_manager\Event\CollectPathsToExcludeEvent; use Drupal\package_manager\Exception\StageFailureMarkerException; use Drupal\package_manager\FailureMarker; @@ -17,6 +18,8 @@ */ class FailureMarkerTest extends PackageManagerKernelTestBase { + use StringTranslationTrait; + /** * @covers ::getMessage * @testWith [true] @@ -24,7 +27,7 @@ class FailureMarkerTest extends PackageManagerKernelTestBase { */ public function testGetMessageWithoutThrowable(bool $include_backtrace): void { $failure_marker = $this->container->get(FailureMarker::class); - $failure_marker->write($this->createStage(), t('Disastrous catastrophe!')); + $failure_marker->write($this->createStage(), $this->t('Disastrous catastrophe!')); $this->assertMatchesRegularExpression('/^Disastrous catastrophe!$/', $failure_marker->getMessage($include_backtrace)); } @@ -36,7 +39,7 @@ public function testGetMessageWithoutThrowable(bool $include_backtrace): void { */ public function testGetMessageWithThrowable(bool $include_backtrace): void { $failure_marker = $this->container->get(FailureMarker::class); - $failure_marker->write($this->createStage(), t('Disastrous catastrophe!'), new \Exception('Witchcraft!')); + $failure_marker->write($this->createStage(), $this->t('Disastrous catastrophe!'), new \Exception('Witchcraft!')); $expected_pattern = $include_backtrace ? <<<REGEXP @@ -76,7 +79,7 @@ public function testExceptionForInvalidYaml(): void { */ public function testAssertNotExists(): void { $failure_marker = $this->container->get(FailureMarker::class); - $failure_marker->write($this->createStage(), t('Something wicked occurred here.'), new \Exception('Witchcraft!')); + $failure_marker->write($this->createStage(), $this->t('Something wicked occurred here.'), new \Exception('Witchcraft!')); $this->expectException(StageFailureMarkerException::class); $this->expectExceptionMessageMatches('/^Something wicked occurred here. Caused by Exception, with this message: Witchcraft!\nBacktrace:\n#0 .*/'); diff --git a/core/modules/package_manager/tests/src/Kernel/LockFileValidatorTest.php b/core/modules/package_manager/tests/src/Kernel/LockFileValidatorTest.php index bcd32f639dfbd3587080a0a4158b34781aa34421..a30c36a5d906c8782faecbaa074abe96169a7bc2 100644 --- a/core/modules/package_manager/tests/src/Kernel/LockFileValidatorTest.php +++ b/core/modules/package_manager/tests/src/Kernel/LockFileValidatorTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\package_manager\Kernel; use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\package_manager\ComposerInspector; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreCreateEvent; @@ -24,6 +25,8 @@ */ class LockFileValidatorTest extends PackageManagerKernelTestBase { + use StringTranslationTrait; + /** * The path of the active directory in the test project. * @@ -72,7 +75,7 @@ public function testCreateWithNoLock(): void { $project_root = $this->container->get(PathLocator::class)->getProjectRoot(); $lock_file_path = $project_root . DIRECTORY_SEPARATOR . 'composer.lock'; $no_lock = ValidationResult::createError([ - t('The active lock file (@file) does not exist.', ['@file' => $lock_file_path]), + $this->t('The active lock file (@file) does not exist.', ['@file' => $lock_file_path]), ]); $stage = $this->assertResults([$no_lock], PreCreateEvent::class); // The stage was not created successfully, so the status check should be @@ -111,9 +114,9 @@ public function testLockFileChanged(string $event_class): void { file_put_contents($this->activeDir . '/composer.lock', json_encode($lock, JSON_THROW_ON_ERROR)); }, $event_class); $result = ValidationResult::createError([ - t('Unexpected changes were detected in the active lock file (@file), 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.', + $this->t('Unexpected changes were detected in the active lock file (@file), 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.', ['@file' => $this->activeDir . '/composer.lock']), - ], t('Problem detected in lock file during stage operations.')); + ], $this->t('Problem detected in lock file during stage operations.')); $stage = $this->assertResults([$result], $event_class); // A status check should agree that there is an error here. $this->assertStatusCheckResults([$result], $stage); @@ -133,10 +136,10 @@ public function testLockFileDeleted(string $event_class): void { unlink($this->activeDir . '/composer.lock'); }, $event_class); $result = ValidationResult::createError([ - t('The active lock file (@file) does not exist.', [ + $this->t('The active lock file (@file) does not exist.', [ '@file' => $this->activeDir . '/composer.lock', ]), - ], t('Problem detected in lock file during stage operations.')); + ], $this->t('Problem detected in lock file during stage operations.')); $stage = $this->assertResults([$result], $event_class); // A status check should agree that there is an error here. $this->assertStatusCheckResults([$result], $stage); @@ -181,8 +184,8 @@ public function testApplyWithNoChange(): void { NoOpStager::setLockFileShouldChange(FALSE); $result = ValidationResult::createError([ - t('There appear to be no pending Composer operations because the active lock file (<PROJECT_ROOT>/composer.lock) and the staged lock file (<STAGE_DIR>/composer.lock) are identical.'), - ], t('Problem detected in lock file during stage operations.')); + $this->t('There appear to be no pending Composer operations because the active lock file (<PROJECT_ROOT>/composer.lock) and the staged lock file (<STAGE_DIR>/composer.lock) are identical.'), + ], $this->t('Problem detected in lock file during stage operations.')); $stage = $this->assertResults([$result], PreApplyEvent::class); // A status check shouldn't produce raise any errors, because it's only // during pre-apply that we care if there are any pending Composer diff --git a/core/modules/package_manager/tests/src/Kernel/OverwriteExistingPackagesValidatorTest.php b/core/modules/package_manager/tests/src/Kernel/OverwriteExistingPackagesValidatorTest.php index 93360a5c50065f334fd885b12973629d80b551c5..46b2adc2138566810bf665af90d664716d0468ad 100644 --- a/core/modules/package_manager/tests/src/Kernel/OverwriteExistingPackagesValidatorTest.php +++ b/core/modules/package_manager/tests/src/Kernel/OverwriteExistingPackagesValidatorTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\package_manager\Kernel; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\fixture_manipulator\ActiveFixtureManipulator; use Drupal\package_manager\ComposerInspector; use Drupal\package_manager\Event\PostCreateEvent; @@ -21,6 +22,7 @@ class OverwriteExistingPackagesValidatorTest extends PackageManagerKernelTestBase { use ComposerInstallersTrait; + use StringTranslationTrait; /** * {@inheritdoc} @@ -144,13 +146,13 @@ public function testNewPackagesOverwriteExisting(): void { $expected_results = [ ValidationResult::createError([ - t('The new package drupal/module_4 will be installed in the directory /modules/module_6, which already exists but is not managed by Composer.'), + $this->t('The new package drupal/module_4 will be installed in the directory /modules/module_6, which already exists but is not managed by Composer.'), ]), ValidationResult::createError([ - t('The new package drupal/other_module_1 will be installed in the directory /modules/module_1, which already exists but is not managed by Composer.'), + $this->t('The new package drupal/other_module_1 will be installed in the directory /modules/module_1, which already exists but is not managed by Composer.'), ]), ValidationResult::createError([ - t('The new package drupal/other_module_2 will be installed in the directory /modules/module_2, which already exists but is not managed by Composer.'), + $this->t('The new package drupal/other_module_2 will be installed in the directory /modules/module_2, which already exists but is not managed by Composer.'), ]), ]; $this->assertResults($expected_results, PreApplyEvent::class); diff --git a/core/modules/package_manager/tests/src/Kernel/PendingUpdatesValidatorTest.php b/core/modules/package_manager/tests/src/Kernel/PendingUpdatesValidatorTest.php index d8682d60fae04ae35e33815a0ab88895c6786fde..dd05283269bccf12292539bea917f0508a238559 100644 --- a/core/modules/package_manager/tests/src/Kernel/PendingUpdatesValidatorTest.php +++ b/core/modules/package_manager/tests/src/Kernel/PendingUpdatesValidatorTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\package_manager\Kernel; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Exception\StageEventException; use Drupal\package_manager\ValidationResult; @@ -15,6 +16,8 @@ */ class PendingUpdatesValidatorTest extends PackageManagerKernelTestBase { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -44,7 +47,7 @@ public function testPendingUpdateHook(): void { require_once __DIR__ . '/../../fixtures/db_update.php'; $result = ValidationResult::createError([ - t('Some modules have database updates pending. You should run the <a href="/update.php">database update script</a> immediately.'), + $this->t('Some modules have database updates pending. You should run the <a href="/update.php">database update script</a> immediately.'), ]); $this->assertStatusCheckResults([$result]); $this->assertResults([$result], PreCreateEvent::class); @@ -58,7 +61,7 @@ public function testPendingPostUpdate(): void { // will think it's pending. require_once __DIR__ . '/../../fixtures/post_update.php'; $result = ValidationResult::createError([ - t('Some modules have database updates pending. You should run the <a href="/update.php">database update script</a> immediately.'), + $this->t('Some modules have database updates pending. You should run the <a href="/update.php">database update script</a> immediately.'), ]); $this->assertStatusCheckResults([$result]); $this->assertResults([$result], PreCreateEvent::class); @@ -75,7 +78,7 @@ public function testPendingUpdateAfterStaged(): void { // will think it's pending. require_once __DIR__ . '/../../fixtures/post_update.php'; $result = ValidationResult::createError([ - t('Some modules have database updates pending. You should run the <a href="/update.php">database update script</a> immediately.'), + $this->t('Some modules have database updates pending. You should run the <a href="/update.php">database update script</a> immediately.'), ]); try { $stage->apply(); diff --git a/core/modules/package_manager/tests/src/Kernel/PhpTufValidatorTest.php b/core/modules/package_manager/tests/src/Kernel/PhpTufValidatorTest.php index d73d2961d98d199fd5346cf686a6fb476d85b941..3e244a0b3f3f970b7db0b56039c20508bc7b163a 100644 --- a/core/modules/package_manager/tests/src/Kernel/PhpTufValidatorTest.php +++ b/core/modules/package_manager/tests/src/Kernel/PhpTufValidatorTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\package_manager\Kernel; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\fixture_manipulator\ActiveFixtureManipulator; use Drupal\fixture_manipulator\FixtureManipulator; use Drupal\package_manager\Event\PreApplyEvent; @@ -22,6 +23,8 @@ */ class PhpTufValidatorTest extends PackageManagerKernelTestBase { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -72,12 +75,12 @@ public function testPluginNotInstalledInProjectRoot(): void { ->updateLock(); $messages = [ - t('The <code>php-tuf/composer-integration</code> plugin is not installed.'), + $this->t('The <code>php-tuf/composer-integration</code> plugin is not installed.'), // Composer automatically removes the plugin from the `allow-plugins` // list when the plugin package is removed. - t('The <code>php-tuf/composer-integration</code> plugin is not listed as an allowed plugin.'), + $this->t('The <code>php-tuf/composer-integration</code> plugin is not listed as an allowed plugin.'), ]; - $result = ValidationResult::createError($messages, t('The active directory is not protected by PHP-TUF, which is required to use Package Manager securely.')); + $result = ValidationResult::createError($messages, $this->t('The active directory is not protected by PHP-TUF, which is required to use Package Manager securely.')); $this->assertStatusCheckResults([$result]); $this->assertResults([$result], PreCreateEvent::class); } @@ -90,12 +93,12 @@ public function testPluginRemovedFromStagePreRequire(): void { ->removePackage(PhpTufValidator::PLUGIN_NAME); $messages = [ - t('The <code>php-tuf/composer-integration</code> plugin is not installed.'), + $this->t('The <code>php-tuf/composer-integration</code> plugin is not installed.'), // Composer automatically removes the plugin from the `allow-plugins` // list when the plugin package is removed. - t('The <code>php-tuf/composer-integration</code> plugin is not listed as an allowed plugin.'), + $this->t('The <code>php-tuf/composer-integration</code> plugin is not listed as an allowed plugin.'), ]; - $result = ValidationResult::createError($messages, t('The stage directory is not protected by PHP-TUF, which is required to use Package Manager securely.')); + $result = ValidationResult::createError($messages, $this->t('The stage directory is not protected by PHP-TUF, which is required to use Package Manager securely.')); $this->assertResults([$result], PreRequireEvent::class); } @@ -112,12 +115,12 @@ public function testPluginRemovedFromStagePreApply(): void { ->commitChanges($stage->getStageDirectory()); $messages = [ - t('The <code>php-tuf/composer-integration</code> plugin is not installed.'), + $this->t('The <code>php-tuf/composer-integration</code> plugin is not installed.'), // Composer automatically removes the plugin from the `allow-plugins` // list when the plugin package is removed. - t('The <code>php-tuf/composer-integration</code> plugin is not listed as an allowed plugin.'), + $this->t('The <code>php-tuf/composer-integration</code> plugin is not listed as an allowed plugin.'), ]; - $result = ValidationResult::createError($messages, t('The stage directory is not protected by PHP-TUF, which is required to use Package Manager securely.')); + $result = ValidationResult::createError($messages, $this->t('The stage directory is not protected by PHP-TUF, which is required to use Package Manager securely.')); try { $stage->apply(); $this->fail('Expected an exception but none was thrown.'); @@ -195,7 +198,7 @@ public static function providerInvalidConfigurationInStage(): \Generator { public function testInvalidConfigurationInProjectRoot(array $config, array $expected_messages): void { (new ActiveFixtureManipulator())->addConfig($config)->commitChanges()->updateLock(); - $result = ValidationResult::createError($expected_messages, t('The active directory is not protected by PHP-TUF, which is required to use Package Manager securely.')); + $result = ValidationResult::createError($expected_messages, $this->t('The active directory is not protected by PHP-TUF, which is required to use Package Manager securely.')); $this->assertStatusCheckResults([$result]); $this->assertResults([$result], PreCreateEvent::class); } @@ -230,7 +233,7 @@ public function testInvalidConfigurationInStage(array $config, array $expected_m ->removeSubscriber($lock_file_validator); } - $result = ValidationResult::createError($expected_messages, t('The stage directory is not protected by PHP-TUF, which is required to use Package Manager securely.')); + $result = ValidationResult::createError($expected_messages, $this->t('The stage directory is not protected by PHP-TUF, which is required to use Package Manager securely.')); $this->assertResults([$result], $event_class); } diff --git a/core/modules/package_manager/tests/src/Kernel/RsyncValidatorTest.php b/core/modules/package_manager/tests/src/Kernel/RsyncValidatorTest.php index e066100e1882e15a45165b915c895338914606bf..188c654929dd496aa4d71f4ac4307eaffb3cea4e 100644 --- a/core/modules/package_manager/tests/src/Kernel/RsyncValidatorTest.php +++ b/core/modules/package_manager/tests/src/Kernel/RsyncValidatorTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\package_manager\Kernel; use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\ValidationResult; use Drupal\package_manager\Validator\RsyncValidator; @@ -20,6 +21,8 @@ */ class RsyncValidatorTest extends PackageManagerKernelTestBase { + use StringTranslationTrait; + /** * The mocked executable finder. * @@ -61,14 +64,14 @@ public function testPreCreateFailsIfRsyncNotFound(): void { $this->executableFinder->find('rsync')->willThrow(new LogicException($message)); $result = ValidationResult::createError([ - t('<code>rsync</code> is not available.'), + $this->t('<code>rsync</code> is not available.'), ]); $this->assertResults([$result], PreCreateEvent::class); $this->enableModules(['help']); $result = ValidationResult::createError([ - t('<code>rsync</code> is not available. See the <a href="/admin/help/package_manager#package-manager-faq-rsync">Package Manager help</a> for more information on how to resolve this.'), + $this->t('<code>rsync</code> is not available. See the <a href="/admin/help/package_manager#package-manager-faq-rsync">Package Manager help</a> for more information on how to resolve this.'), ]); $this->assertResults([$result], PreCreateEvent::class); } diff --git a/core/modules/package_manager/tests/src/Kernel/StageBaseTest.php b/core/modules/package_manager/tests/src/Kernel/StageBaseTest.php index 0ccc219f7d3a94f39ab4a87a0771ee0cf71f6629..1b8fa9bdae1ff39395baed8328aaecae3cdb9c4a 100644 --- a/core/modules/package_manager/tests/src/Kernel/StageBaseTest.php +++ b/core/modules/package_manager/tests/src/Kernel/StageBaseTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\package_manager\Kernel; use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\package_manager\Event\CollectPathsToExcludeEvent; use Drupal\package_manager\Event\PreCreateEvent; @@ -30,6 +31,8 @@ */ class StageBaseTest extends PackageManagerKernelTestBase { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -311,7 +314,7 @@ public function testTempStoreMessageExpired(): void { $stage = $this->createStage(); $stage_id = $stage->create(); $stage->require(['drupal/core:9.8.1']); - $stage->destroy(TRUE, t('Force destroy stage.')); + $stage->destroy(TRUE, $this->t('Force destroy stage.')); // Delete the tempstore message stored for the previously destroyed stage. $tempstore = $this->container->get('tempstore.shared'); diff --git a/core/modules/package_manager/tests/src/Kernel/StageEventsTest.php b/core/modules/package_manager/tests/src/Kernel/StageEventsTest.php index 8782d27a44c3a42257c78f2318cb8c3dfed672d1..adffe440b1048757c43e78ecdf0d254fc5f79d9b 100644 --- a/core/modules/package_manager/tests/src/Kernel/StageEventsTest.php +++ b/core/modules/package_manager/tests/src/Kernel/StageEventsTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\package_manager\Kernel; use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\package_manager\Event\PostApplyEvent; use Drupal\package_manager\Event\PostCreateEvent; use Drupal\package_manager\Event\PostRequireEvent; @@ -28,6 +29,8 @@ */ class StageEventsTest extends PackageManagerKernelTestBase implements EventSubscriberInterface { + use StringTranslationTrait; + /** * The events that were fired, in the order they were fired. * @@ -134,7 +137,7 @@ public static function providerValidationResults(): array { * @dataProvider providerValidationResults */ public function testValidationResults(string $event_class): void { - $error_messages = [t('Burn, baby, burn')]; + $error_messages = [$this->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 { @@ -157,10 +160,10 @@ public function testAddResult(): void { $stage = $this->createStage(); $error = ValidationResult::createError([ - t('Burn, baby, burn!'), + $this->t('Burn, baby, burn!'), ]); $warning = ValidationResult::createWarning([ - t('The path ahead is scary...'), + $this->t('The path ahead is scary...'), ]); $excluded_paths = $this->createMock(PathListInterface::class); diff --git a/core/modules/package_manager/tests/src/Kernel/SymlinkValidatorTest.php b/core/modules/package_manager/tests/src/Kernel/SymlinkValidatorTest.php index 46d36bfb83c4212c6bc3c12131606007821851e6..ef6ed7eaf004eee66f31e6cc9f83dd78bac27ffe 100644 --- a/core/modules/package_manager/tests/src/Kernel/SymlinkValidatorTest.php +++ b/core/modules/package_manager/tests/src/Kernel/SymlinkValidatorTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\package_manager\Kernel; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Exception\StageEventException; use Drupal\package_manager\PathLocator; @@ -18,6 +19,8 @@ */ class SymlinkValidatorTest extends PackageManagerKernelTestBase { + use StringTranslationTrait; + /** * Tests that relative symlinks within the same package are supported. */ @@ -48,7 +51,7 @@ public function testHardLinks(): void { link($project_root . '/composer.json', $project_root . '/composer.link'); $result = ValidationResult::createError([ - t('The %which directory at %dir contains hard links, which is not supported. The first one is %file.', [ + $this->t('The %which directory at %dir contains hard links, which is not supported. The first one is %file.', [ '%which' => 'active', '%dir' => $project_root, '%file' => $project_root . '/composer.json', @@ -66,7 +69,7 @@ public function testAbsoluteSymlinks(): void { symlink($project_root . '/composer.json', $project_root . '/composer.link'); $result = ValidationResult::createError([ - t('The %which directory at %dir contains absolute links, which is not supported. The first one is %file.', [ + $this->t('The %which directory at %dir contains absolute links, which is not supported. The first one is %file.', [ '%which' => 'active', '%dir' => $project_root, '%file' => $project_root . '/composer.link', @@ -89,7 +92,7 @@ public function testSymlinkPointingOutsideProjectRoot(): void { chdir($project_root); symlink('../hello.txt', 'fail.txt'); $result = ValidationResult::createError([ - t('The %which directory at %dir contains links that point outside the codebase, which is not supported. The first one is %file.', [ + $this->t('The %which directory at %dir contains links that point outside the codebase, which is not supported. The first one is %file.', [ '%which' => 'active', '%dir' => $project_root, '%file' => $project_root . '/fail.txt', @@ -118,7 +121,7 @@ public function testSymlinkPointingOutsideStageDirectory(): void { symlink('../hello.txt', 'fail.txt'); $result = ValidationResult::createError([ - t('The %which directory at %dir contains links that point outside the codebase, which is not supported. The first one is %file.', [ + $this->t('The %which directory at %dir contains links that point outside the codebase, which is not supported. The first one is %file.', [ '%which' => 'staging', '%dir' => $stage_dir, '%file' => $stage_dir . '/fail.txt', @@ -169,7 +172,7 @@ public function testSymlinksNotAllowedOnWindows(): void { symlink('composer.json', 'composer.link'); $result = ValidationResult::createError([ - t('The %which directory at %dir contains links, which is not supported on Windows. The first one is %file.', [ + $this->t('The %which directory at %dir contains links, which is not supported on Windows. The first one is %file.', [ '%which' => 'active', '%dir' => $project_root, '%file' => $project_root . '/composer.link', diff --git a/core/phpcs.xml.dist b/core/phpcs.xml.dist index 47d0a73e4a306304b9b7b8c42309b20342ec9cf7..60105a430d96fa8e383750e6537b664057d74287 100644 --- a/core/phpcs.xml.dist +++ b/core/phpcs.xml.dist @@ -191,6 +191,7 @@ <include-pattern>*/ListBuilder/*</include-pattern> <include-pattern>*/tests/*/Form/*</include-pattern> <include-pattern>*/modules/system/tests/modules/*</include-pattern> + <include-pattern>*/Kernel*/*</include-pattern> </rule> <!-- Generic sniffs --> diff --git a/core/tests/Drupal/KernelTests/ConfigFormTestBase.php b/core/tests/Drupal/KernelTests/ConfigFormTestBase.php index aa3bda340b15341946ea95574142a41c443d8fda..2d605cd817482ab3dee30c488172ee5d00d4df7c 100644 --- a/core/tests/Drupal/KernelTests/ConfigFormTestBase.php +++ b/core/tests/Drupal/KernelTests/ConfigFormTestBase.php @@ -5,6 +5,7 @@ namespace Drupal\KernelTests; use Drupal\Core\Form\FormState; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Full generic test suite for any form that data with the configuration system. @@ -13,6 +14,9 @@ * For a full working implementation. */ abstract class ConfigFormTestBase extends KernelTestBase { + + use StringTranslationTrait; + /** * Form ID to use for testing. * @@ -54,7 +58,7 @@ public function testConfigForm(): void { $errors = $form_state->getErrors(); $valid_form = empty($errors); $values = print_r($values, TRUE); - $errors = $valid_form ? t('None') : implode(' ', $errors); + $errors = $valid_form ? $this->t('None') : implode(' ', $errors); $this->assertTrue($valid_form, sprintf('Input values: %s<br/>Validation handler errors: %s', $values, $errors)); foreach ($this->values as $data) { $this->assertEquals($this->config($data['#config_name'])->get($data['#config_key']), $data['#value']); diff --git a/core/tests/Drupal/KernelTests/Core/Common/XssUnitTest.php b/core/tests/Drupal/KernelTests/Core/Common/XssUnitTest.php index ce61fc72e76e67083d2343b7567c2bf612c6de59..91a6221be7e744f3416b47712493bc51c37d7b86 100644 --- a/core/tests/Drupal/KernelTests/Core/Common/XssUnitTest.php +++ b/core/tests/Drupal/KernelTests/Core/Common/XssUnitTest.php @@ -5,6 +5,7 @@ namespace Drupal\KernelTests\Core\Common; use Drupal\Component\Utility\UrlHelper; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\KernelTests\KernelTestBase; /** @@ -18,6 +19,8 @@ */ class XssUnitTest extends KernelTestBase { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -35,11 +38,11 @@ protected function setUp(): void { * Tests t() functionality. */ public function testT(): void { - $text = t('Simple text'); + $text = $this->t('Simple text'); $this->assertSame('Simple text', (string) $text, 't leaves simple text alone.'); - $text = t('Escaped text: @value', ['@value' => '<script>']); + $text = $this->t('Escaped text: @value', ['@value' => '<script>']); $this->assertSame('Escaped text: <script>', (string) $text, 't replaces and escapes string.'); - $text = t('Placeholder text: %value', ['%value' => '<script>']); + $text = $this->t('Placeholder text: %value', ['%value' => '<script>']); $this->assertSame('Placeholder text: <em class="placeholder"><script></em>', (string) $text, 't replaces, escapes and themes string.'); } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php index 97cfacb815e3b95c22f3b35f25f9de9b9216ab37..a428509dfe581be6fe0e988efc6ab9bde23c9376 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php @@ -15,6 +15,7 @@ use Drupal\Core\Field\FieldException; use Drupal\Core\Field\FieldStorageDefinitionEvents; use Drupal\Core\Language\LanguageInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\entity_test\FieldStorageDefinition; use Drupal\entity_test_update\Entity\EntityTestUpdate; @@ -31,6 +32,7 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase { use EntityDefinitionTestTrait; + use StringTranslationTrait; /** * The entity definition update manager. @@ -118,11 +120,11 @@ public function testEntityTypeUpdateWithoutData(): void { $this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.'); $expected = [ 'entity_test_update' => [ - t('The %entity_type entity type needs to be updated.', ['%entity_type' => $this->entityTypeManager->getDefinition('entity_test_update')->getLabel()]), + $this->t('The %entity_type entity type needs to be updated.', ['%entity_type' => $this->entityTypeManager->getDefinition('entity_test_update')->getLabel()]), // The revision key is now defined, so the revision field needs to be // created. - t('The %field_name field needs to be installed.', ['%field_name' => 'Revision ID']), - t('The %field_name field needs to be installed.', ['%field_name' => 'Default revision']), + $this->t('The %field_name field needs to be installed.', ['%field_name' => 'Revision ID']), + $this->t('The %field_name field needs to be installed.', ['%field_name' => 'Default revision']), ], ]; $this->assertEquals($expected, $this->entityDefinitionUpdateManager->getChangeSummary(), 'EntityDefinitionUpdateManager reports the expected change summary.'); @@ -662,7 +664,7 @@ public function testEntityIndexCreateDeleteWithoutData(): void { $this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.'); $expected = [ 'entity_test_update' => [ - t('The %entity_type entity type needs to be updated.', ['%entity_type' => $this->entityTypeManager->getDefinition('entity_test_update')->getLabel()]), + $this->t('The %entity_type entity type needs to be updated.', ['%entity_type' => $this->entityTypeManager->getDefinition('entity_test_update')->getLabel()]), ], ]; $this->assertEquals($expected, $this->entityDefinitionUpdateManager->getChangeSummary(), 'EntityDefinitionUpdateManager reports the expected change summary.'); @@ -679,7 +681,7 @@ public function testEntityIndexCreateDeleteWithoutData(): void { $this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.'); $expected = [ 'entity_test_update' => [ - t('The %entity_type entity type needs to be updated.', ['%entity_type' => $this->entityTypeManager->getDefinition('entity_test_update')->getLabel()]), + $this->t('The %entity_type entity type needs to be updated.', ['%entity_type' => $this->entityTypeManager->getDefinition('entity_test_update')->getLabel()]), ], ]; $this->assertEquals($expected, $this->entityDefinitionUpdateManager->getChangeSummary(), 'EntityDefinitionUpdateManager reports the expected change summary.'); @@ -821,7 +823,7 @@ public function testSingleActionCalls(): void { $message = 'A field cannot be installed on a non-existing entity type'; try { $storage_definition = BaseFieldDefinition::create('string') - ->setLabel(t('A new revisionable base field')) + ->setLabel($this->t('A new revisionable base field')) ->setRevisionable(TRUE); $this->entityDefinitionUpdateManager->installFieldStorageDefinition('bar', 'foo', 'entity_test', $storage_definition); $this->fail($message); @@ -838,7 +840,7 @@ public function testSingleActionCalls(): void { // Create a new base field. $this->addRevisionableBaseField(); $storage_definition = BaseFieldDefinition::create('string') - ->setLabel(t('A new revisionable base field')) + ->setLabel($this->t('A new revisionable base field')) ->setRevisionable(TRUE); $this->assertFalse($db_schema->fieldExists('entity_test_update', 'new_base_field'), "New field 'new_base_field' does not exist before applying the update."); $this->entityDefinitionUpdateManager->installFieldStorageDefinition('new_base_field', 'entity_test_update', 'entity_test', $storage_definition); @@ -853,7 +855,7 @@ public function testSingleActionCalls(): void { $storage_definition = BaseFieldDefinition::create('text') ->setName('new_base_field') ->setTargetEntityTypeId('entity_test_update') - ->setLabel(t('A new revisionable base field')) + ->setLabel($this->t('A new revisionable base field')) ->setRevisionable(TRUE); $this->entityDefinitionUpdateManager->updateFieldStorageDefinition($storage_definition); $this->assertFalse($db_schema->fieldExists('entity_test_update', 'new_base_field'), "Previous schema for 'new_base_field' no longer exists."); @@ -1003,7 +1005,7 @@ public function testInitialValue(): void { // Add a base field with an initial value. $this->addBaseField(); $storage_definition = BaseFieldDefinition::create('string') - ->setLabel(t('A new base field')) + ->setLabel($this->t('A new base field')) ->setInitialValue('test value'); $this->assertFalse($db_schema->fieldExists('entity_test_update', 'new_base_field'), "New field 'new_base_field' does not exist before applying the update."); @@ -1026,7 +1028,7 @@ public function testInitialValueFromFieldErrorHandling(): void { try { $this->addBaseField(); $storage_definition = BaseFieldDefinition::create('string') - ->setLabel(t('A new base field')) + ->setLabel($this->t('A new base field')) ->setInitialValueFromField('field_that_does_not_exist'); $this->entityDefinitionUpdateManager->installFieldStorageDefinition('new_base_field', 'entity_test_update', 'entity_test', $storage_definition); $this->fail('Using a non-existent field as initial value does not work.'); @@ -1038,7 +1040,7 @@ public function testInitialValueFromFieldErrorHandling(): void { try { $this->addBaseField(); $storage_definition = BaseFieldDefinition::create('integer') - ->setLabel(t('A new base field')) + ->setLabel($this->t('A new base field')) ->setInitialValueFromField('name'); $this->entityDefinitionUpdateManager->installFieldStorageDefinition('new_base_field', 'entity_test_update', 'entity_test', $storage_definition); $this->fail('Using a field of a different type as initial value does not work.'); @@ -1051,7 +1053,7 @@ public function testInitialValueFromFieldErrorHandling(): void { // Add a base field that will not be stored in the shared tables. $initial_field = BaseFieldDefinition::create('string') ->setName('initial_field') - ->setLabel(t('An initial field')) + ->setLabel($this->t('An initial field')) ->setCardinality(2); $this->state->set('entity_test_update.additional_base_field_definitions', ['initial_field' => $initial_field]); $this->entityDefinitionUpdateManager->installFieldStorageDefinition('initial_field', 'entity_test_update', 'entity_test', $initial_field); @@ -1060,7 +1062,7 @@ public function testInitialValueFromFieldErrorHandling(): void { // as the source of its initial values. $new_base_field = BaseFieldDefinition::create('string') ->setName('new_base_field') - ->setLabel(t('A new base field')) + ->setLabel($this->t('A new base field')) ->setInitialValueFromField('initial_field'); $this->state->set('entity_test_update.additional_base_field_definitions', ['initial_field' => $initial_field, 'new_base_field' => $new_base_field]); $this->entityDefinitionUpdateManager->installFieldStorageDefinition('new_base_field', 'entity_test_update', 'entity_test', $new_base_field); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php b/core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php index 1f0f9762070ddac280a20be38ecd587b2a242454..d0fdbf930f0383c004e625d3571e0158e2cae7c0 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/FieldableEntityDefinitionUpdateTest.php @@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Site\Settings; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\Tests\system\Functional\Entity\Traits\EntityDefinitionTestTrait; @@ -20,6 +21,7 @@ class FieldableEntityDefinitionUpdateTest extends EntityKernelTestBase { use EntityDefinitionTestTrait; + use StringTranslationTrait; /** * The entity definition update manager. @@ -107,8 +109,8 @@ protected function setUp(): void { // updated, so add it to the entity type that is being tested in order to // provide test coverage for this special case. $fields['changed'] = BaseFieldDefinition::create('changed') - ->setLabel(t('Changed')) - ->setDescription(t('The time that the content block was last edited.')) + ->setLabel($this->t('Changed')) + ->setDescription($this->t('The time that the content block was last edited.')) ->setTranslatable(TRUE) ->setRevisionable(TRUE); $this->state->set('entity_test_update.additional_base_field_definitions', $fields); diff --git a/core/tests/Drupal/KernelTests/Core/TypedData/TypedDataTest.php b/core/tests/Drupal/KernelTests/Core/TypedData/TypedDataTest.php index 525bef995c99c3914a2bf6f79892f90c2dd28777..c5443287f995a1a00d3dac67a7c7f9d35e9f0bfd 100644 --- a/core/tests/Drupal/KernelTests/Core/TypedData/TypedDataTest.php +++ b/core/tests/Drupal/KernelTests/Core/TypedData/TypedDataTest.php @@ -6,6 +6,7 @@ use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Field\BaseFieldDefinition; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\TypedData\ListDataDefinition; use Drupal\Core\TypedData\MapDataDefinition; @@ -31,6 +32,8 @@ */ class TypedDataTest extends KernelTestBase { + use StringTranslationTrait; + /** * The typed data manager to use. * @@ -610,7 +613,7 @@ public function testTypedDataValidation(): void { $this->assertEquals(1, $violations->count()); // Test translating violation messages. - $message = t('This value should be %limit or more.', ['%limit' => 5]); + $message = $this->t('This value should be %limit or more.', ['%limit' => 5]); $this->assertEquals($message, $violations[0]->getMessage(), 'Translated violation message retrieved.'); $this->assertEquals('', $violations[0]->getPropertyPath()); $this->assertSame($integer, $violations[0]->getRoot(), 'Root object returned.'); @@ -622,7 +625,7 @@ public function testTypedDataValidation(): void { ]); $violations = $this->typedDataManager->create($definition, "short")->validate(); $this->assertEquals(1, $violations->count()); - $message = t('This value is too short. It should have %limit characters or more.', ['%limit' => 10]); + $message = $this->t('This value is too short. It should have %limit characters or more.', ['%limit' => 10]); $this->assertEquals($message, $violations[0]->getMessage(), 'Translated violation message retrieved.'); // Test having multiple violations.