From ee894196deb1f857bcba96ea792f5f7fc6383844 Mon Sep 17 00:00:00 2001
From: Dave Long <dave@longwaveconsulting.com>
Date: Tue, 7 Jan 2025 18:54:25 +0000
Subject: [PATCH] Issue #3497403 by quietone, longwave: Fix
 DrupalPractice.Objects.GlobalFunction in system test modules

---
 .../src/Controller/CommonTestController.php   |  9 +++++---
 .../src/TestController.php                    |  4 ++--
 .../src/Controller/DatabaseTestController.php | 19 ++++++++++-------
 .../DriverTestMysql/Install/Tasks.php         |  2 +-
 .../Install/Tasks.php                         |  2 +-
 .../DriverTestPgsql/Install/Tasks.php         |  2 +-
 .../Driver/Database/dummydb/Install/Tasks.php |  2 +-
 .../src/Hook/EntityReferenceTestHooks.php     |  5 ++++-
 .../src/Hook/EntitySchemaTestHooks.php        |  9 +++++---
 .../entity_test/src/EntityTestForm.php        |  6 +++---
 .../entity_test/src/EntityTestListBuilder.php |  4 ++--
 .../entity_test/src/Hook/EntityTestHooks.php  | 21 +++++++++++--------
 .../src/Hook/EntityTestOperationHooks.php     |  5 ++++-
 ...xperimentalModuleRequirementsTestHooks.php |  5 ++++-
 .../src/Hook/ExperimentalModuleTestHooks.php  |  5 ++++-
 .../tests/modules/form_test/src/Callbacks.php |  5 ++++-
 .../form_test/src/Hook/FormTestHooks.php      |  5 ++++-
 .../src/Hook/LinkGenerationTestHooks.php      |  5 ++++-
 .../src/Controller/MenuTestController.php     |  2 +-
 .../src/Hook/Requirements1TestHooks.php       |  5 ++++-
 .../service_provider_test/src/TestClass.php   |  5 ++++-
 .../system_test/src/Hook/SystemTestHooks.php  | 15 +++++++------
 .../system_test/src/MockFileTransfer.php      |  6 +++++-
 .../src/Controller/TestPageTestController.php | 13 +++++++-----
 .../src/Hook/UpdateScriptTestHooks.php        |  5 ++++-
 core/phpcs.xml.dist                           |  1 +
 26 files changed, 110 insertions(+), 57 deletions(-)

diff --git a/core/modules/system/tests/modules/common_test/src/Controller/CommonTestController.php b/core/modules/system/tests/modules/common_test/src/Controller/CommonTestController.php
index 3ee758d7523f..c08da9d4107b 100644
--- a/core/modules/system/tests/modules/common_test/src/Controller/CommonTestController.php
+++ b/core/modules/system/tests/modules/common_test/src/Controller/CommonTestController.php
@@ -6,6 +6,7 @@
 
 use Drupal\Component\Utility\Html;
 use Drupal\Core\Extension\ExtensionList;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 use Drupal\Core\Url;
 use Symfony\Component\HttpFoundation\Response;
 
@@ -14,6 +15,8 @@
  */
 class CommonTestController {
 
+  use StringTranslationTrait;
+
   /**
    * Returns links to the current page, with and without query strings.
    *
@@ -24,7 +27,7 @@ public function typeLinkActiveClass() {
     return [
       'no_query' => [
         '#type' => 'link',
-        '#title' => t('Link with no query string'),
+        '#title' => $this->t('Link with no query string'),
         '#url' => Url::fromRoute('<current>'),
         '#options' => [
           'set_active_class' => TRUE,
@@ -32,7 +35,7 @@ public function typeLinkActiveClass() {
       ],
       'with_query' => [
         '#type' => 'link',
-        '#title' => t('Link with a query string'),
+        '#title' => $this->t('Link with a query string'),
         '#url' => Url::fromRoute('<current>'),
         '#options' => [
           'query' => [
@@ -44,7 +47,7 @@ public function typeLinkActiveClass() {
       ],
       'with_query_reversed' => [
         '#type' => 'link',
-        '#title' => t('Link with the same query string in reverse order'),
+        '#title' => $this->t('Link with the same query string in reverse order'),
         '#url' => Url::fromRoute('<current>'),
         '#options' => [
           'query' => [
diff --git a/core/modules/system/tests/modules/container_rebuild_test/src/TestController.php b/core/modules/system/tests/modules/container_rebuild_test/src/TestController.php
index bc7704eb45dc..28320aa51e95 100644
--- a/core/modules/system/tests/modules/container_rebuild_test/src/TestController.php
+++ b/core/modules/system/tests/modules/container_rebuild_test/src/TestController.php
@@ -53,11 +53,11 @@ public function showModuleInfo(string $module, string $function) {
    *   A render array.
    */
   public function containerReset() {
-    $this->messenger()->addMessage(t('Before the container was reset.'));
+    $this->messenger()->addMessage($this->t('Before the container was reset.'));
     $this->kernel->resetContainer();
     // The container has been reset, therefore we need to get the new service.
     $this->messenger = NULL;
-    $this->messenger()->addMessage(t('After the container was reset.'));
+    $this->messenger()->addMessage($this->t('After the container was reset.'));
     return [];
   }
 
diff --git a/core/modules/system/tests/modules/database_test/src/Controller/DatabaseTestController.php b/core/modules/system/tests/modules/database_test/src/Controller/DatabaseTestController.php
index 829a92cb4193..6634b9d27400 100644
--- a/core/modules/system/tests/modules/database_test/src/Controller/DatabaseTestController.php
+++ b/core/modules/system/tests/modules/database_test/src/Controller/DatabaseTestController.php
@@ -8,6 +8,7 @@
 use Drupal\Core\Database\Connection;
 use Drupal\Core\Database\Query\PagerSelectExtender;
 use Drupal\Core\Database\Query\TableSortExtender;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\HttpFoundation\JsonResponse;
 
@@ -16,6 +17,8 @@
  */
 class DatabaseTestController extends ControllerBase {
 
+  use StringTranslationTrait;
+
   /**
    * The database connection.
    *
@@ -104,10 +107,10 @@ public function pagerQueryOdd($limit) {
    */
   public function testTablesort() {
     $header = [
-      'tid' => ['data' => t('Task ID'), 'field' => 'tid', 'sort' => 'desc'],
-      'pid' => ['data' => t('Person ID'), 'field' => 'pid'],
-      'task' => ['data' => t('Task'), 'field' => 'task'],
-      'priority' => ['data' => t('Priority'), 'field' => 'priority'],
+      'tid' => ['data' => $this->t('Task ID'), 'field' => 'tid', 'sort' => 'desc'],
+      'pid' => ['data' => $this->t('Person ID'), 'field' => 'pid'],
+      'task' => ['data' => $this->t('Task'), 'field' => 'task'],
+      'priority' => ['data' => $this->t('Priority'), 'field' => 'priority'],
     ];
 
     $query = $this->connection->select('test_task', 't');
@@ -136,10 +139,10 @@ public function testTablesort() {
    */
   public function testTablesortFirst() {
     $header = [
-      'tid' => ['data' => t('Task ID'), 'field' => 'tid', 'sort' => 'desc'],
-      'pid' => ['data' => t('Person ID'), 'field' => 'pid'],
-      'task' => ['data' => t('Task'), 'field' => 'task'],
-      'priority' => ['data' => t('Priority'), 'field' => 'priority'],
+      'tid' => ['data' => $this->t('Task ID'), 'field' => 'tid', 'sort' => 'desc'],
+      'pid' => ['data' => $this->t('Person ID'), 'field' => 'pid'],
+      'task' => ['data' => $this->t('Task'), 'field' => 'task'],
+      'priority' => ['data' => $this->t('Priority'), 'field' => 'priority'],
     ];
 
     $query = $this->connection->select('test_task', 't');
diff --git a/core/modules/system/tests/modules/driver_test/src/Driver/Database/DriverTestMysql/Install/Tasks.php b/core/modules/system/tests/modules/driver_test/src/Driver/Database/DriverTestMysql/Install/Tasks.php
index a4d205bc7dd9..d7d91f0b8ff5 100644
--- a/core/modules/system/tests/modules/driver_test/src/Driver/Database/DriverTestMysql/Install/Tasks.php
+++ b/core/modules/system/tests/modules/driver_test/src/Driver/Database/DriverTestMysql/Install/Tasks.php
@@ -15,7 +15,7 @@ class Tasks extends CoreTasks {
    * {@inheritdoc}
    */
   public function name() {
-    return t('MySQL by the driver_test module');
+    return $this->t('MySQL by the driver_test module');
   }
 
 }
diff --git a/core/modules/system/tests/modules/driver_test/src/Driver/Database/DriverTestMysqlDeprecatedVersion/Install/Tasks.php b/core/modules/system/tests/modules/driver_test/src/Driver/Database/DriverTestMysqlDeprecatedVersion/Install/Tasks.php
index 981d67563cc6..17a2e89500d0 100644
--- a/core/modules/system/tests/modules/driver_test/src/Driver/Database/DriverTestMysqlDeprecatedVersion/Install/Tasks.php
+++ b/core/modules/system/tests/modules/driver_test/src/Driver/Database/DriverTestMysqlDeprecatedVersion/Install/Tasks.php
@@ -15,7 +15,7 @@ class Tasks extends CoreTasks {
    * {@inheritdoc}
    */
   public function name() {
-    return t('MySQL deprecated version by the driver_test module');
+    return $this->t('MySQL deprecated version by the driver_test module');
   }
 
 }
diff --git a/core/modules/system/tests/modules/driver_test/src/Driver/Database/DriverTestPgsql/Install/Tasks.php b/core/modules/system/tests/modules/driver_test/src/Driver/Database/DriverTestPgsql/Install/Tasks.php
index 9e4eb0711558..07bb3704b905 100644
--- a/core/modules/system/tests/modules/driver_test/src/Driver/Database/DriverTestPgsql/Install/Tasks.php
+++ b/core/modules/system/tests/modules/driver_test/src/Driver/Database/DriverTestPgsql/Install/Tasks.php
@@ -15,7 +15,7 @@ class Tasks extends CoreTasks {
    * {@inheritdoc}
    */
   public function name() {
-    return t('PostgreSQL by the driver_test module');
+    return $this->t('PostgreSQL by the driver_test module');
   }
 
 }
diff --git a/core/modules/system/tests/modules/dummydb/src/Driver/Database/dummydb/Install/Tasks.php b/core/modules/system/tests/modules/dummydb/src/Driver/Database/dummydb/Install/Tasks.php
index b220fe037431..52a3082e48a7 100644
--- a/core/modules/system/tests/modules/dummydb/src/Driver/Database/dummydb/Install/Tasks.php
+++ b/core/modules/system/tests/modules/dummydb/src/Driver/Database/dummydb/Install/Tasks.php
@@ -17,7 +17,7 @@ class Tasks extends CoreTasks {
    * {@inheritdoc}
    */
   public function name() {
-    return t('DummyDB');
+    return $this->t('DummyDB');
   }
 
 }
diff --git a/core/modules/system/tests/modules/entity_reference_test/src/Hook/EntityReferenceTestHooks.php b/core/modules/system/tests/modules/entity_reference_test/src/Hook/EntityReferenceTestHooks.php
index df4c6f66ceeb..2954e0257938 100644
--- a/core/modules/system/tests/modules/entity_reference_test/src/Hook/EntityReferenceTestHooks.php
+++ b/core/modules/system/tests/modules/entity_reference_test/src/Hook/EntityReferenceTestHooks.php
@@ -7,12 +7,15 @@
 use Drupal\Core\Field\BaseFieldDefinition;
 use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Hook\Attribute\Hook;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 
 /**
  * Hook implementations for entity_reference_test.
  */
 class EntityReferenceTestHooks {
 
+  use StringTranslationTrait;
+
   /**
    * Implements hook_entity_base_field_info().
    */
@@ -20,7 +23,7 @@ class EntityReferenceTestHooks {
   public function entityBaseFieldInfo(EntityTypeInterface $entity_type) {
     $fields = [];
     if ($entity_type->id() === 'entity_test') {
-      $fields['user_role'] = BaseFieldDefinition::create('entity_reference')->setLabel(t('User role'))->setDescription(t('The role of the associated user.'))->setSetting('target_type', 'user_role')->setSetting('handler', 'default');
+      $fields['user_role'] = BaseFieldDefinition::create('entity_reference')->setLabel($this->t('User role'))->setDescription($this->t('The role of the associated user.'))->setSetting('target_type', 'user_role')->setSetting('handler', 'default');
     }
     return $fields;
   }
diff --git a/core/modules/system/tests/modules/entity_schema_test/src/Hook/EntitySchemaTestHooks.php b/core/modules/system/tests/modules/entity_schema_test/src/Hook/EntitySchemaTestHooks.php
index 620bca0a9e6f..ec28bd8cb27c 100644
--- a/core/modules/system/tests/modules/entity_schema_test/src/Hook/EntitySchemaTestHooks.php
+++ b/core/modules/system/tests/modules/entity_schema_test/src/Hook/EntitySchemaTestHooks.php
@@ -5,6 +5,7 @@
 namespace Drupal\entity_schema_test\Hook;
 
 use Drupal\Core\Field\FieldDefinition;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 use Drupal\entity_test\FieldStorageDefinition;
 use Drupal\entity_test\Entity\EntityTestMulRev;
 use Drupal\Core\Field\BaseFieldDefinition;
@@ -17,6 +18,8 @@
  */
 class EntitySchemaTestHooks {
 
+  use StringTranslationTrait;
+
   /**
    * Implements hook_entity_type_alter().
    */
@@ -43,11 +46,11 @@ public function entityTypeAlter(array &$entity_types) : void {
   #[Hook('entity_base_field_info')]
   public function entityBaseFieldInfo(EntityTypeInterface $entity_type) {
     if ($entity_type->id() == 'entity_test_update') {
-      $definitions['custom_base_field'] = BaseFieldDefinition::create('string')->setName('custom_base_field')->setLabel(t('A custom base field'));
+      $definitions['custom_base_field'] = BaseFieldDefinition::create('string')->setName('custom_base_field')->setLabel($this->t('A custom base field'));
       if (\Drupal::state()->get('entity_schema_update')) {
         $definitions += EntityTestMulRev::baseFieldDefinitions($entity_type);
         // And add a revision log.
-        $definitions['revision_log'] = BaseFieldDefinition::create('string_long')->setLabel(t('Revision log message'))->setDescription(t('The log entry explaining the changes in this revision.'))->setRevisionable(TRUE);
+        $definitions['revision_log'] = BaseFieldDefinition::create('string_long')->setLabel($this->t('Revision log message'))->setDescription($this->t('The log entry explaining the changes in this revision.'))->setRevisionable(TRUE);
       }
       return $definitions;
     }
@@ -59,7 +62,7 @@ public function entityBaseFieldInfo(EntityTypeInterface $entity_type) {
   #[Hook('entity_field_storage_info')]
   public function entityFieldStorageInfo(EntityTypeInterface $entity_type) {
     if ($entity_type->id() == 'entity_test_update') {
-      $definitions['custom_bundle_field'] = FieldStorageDefinition::create('string')->setName('custom_bundle_field')->setLabel(t('A custom bundle field'))->setRevisionable(TRUE)->setTargetEntityTypeId($entity_type->id());
+      $definitions['custom_bundle_field'] = FieldStorageDefinition::create('string')->setName('custom_bundle_field')->setLabel($this->t('A custom bundle field'))->setRevisionable(TRUE)->setTargetEntityTypeId($entity_type->id());
       return $definitions;
     }
   }
diff --git a/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php b/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php
index a63241bd4003..e029ba031058 100644
--- a/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php
+++ b/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php
@@ -38,7 +38,7 @@ public function form(array $form, FormStateInterface $form_state) {
     if ($entity->getEntityType()->hasKey('revision') && !$entity->isNew()) {
       $form['revision'] = [
         '#type' => 'checkbox',
-        '#title' => t('Create new revision'),
+        '#title' => $this->t('Create new revision'),
         '#default_value' => $entity->isNewRevision(),
       ];
     }
@@ -62,10 +62,10 @@ public function save(array $form, FormStateInterface $form_state) {
       $status = $entity->save();
 
       if ($is_new) {
-        $message = t('%entity_type @id has been created.', ['@id' => $entity->id(), '%entity_type' => $entity->getEntityTypeId()]);
+        $message = $this->t('%entity_type @id has been created.', ['@id' => $entity->id(), '%entity_type' => $entity->getEntityTypeId()]);
       }
       else {
-        $message = t('%entity_type @id has been updated.', ['@id' => $entity->id(), '%entity_type' => $entity->getEntityTypeId()]);
+        $message = $this->t('%entity_type @id has been updated.', ['@id' => $entity->id(), '%entity_type' => $entity->getEntityTypeId()]);
       }
       $this->messenger()->addStatus($message);
 
diff --git a/core/modules/system/tests/modules/entity_test/src/EntityTestListBuilder.php b/core/modules/system/tests/modules/entity_test/src/EntityTestListBuilder.php
index 7c516ab72697..7a68ccb810da 100644
--- a/core/modules/system/tests/modules/entity_test/src/EntityTestListBuilder.php
+++ b/core/modules/system/tests/modules/entity_test/src/EntityTestListBuilder.php
@@ -18,8 +18,8 @@ class EntityTestListBuilder extends EntityListBuilder {
    * {@inheritdoc}
    */
   public function buildHeader() {
-    $header['label'] = t('Label');
-    $header['id'] = t('Machine name');
+    $header['label'] = $this->t('Label');
+    $header['id'] = $this->t('Machine name');
     return $header + parent::buildHeader();
   }
 
diff --git a/core/modules/system/tests/modules/entity_test/src/Hook/EntityTestHooks.php b/core/modules/system/tests/modules/entity_test/src/Hook/EntityTestHooks.php
index c8b7a55f5b52..64b73958f502 100644
--- a/core/modules/system/tests/modules/entity_test/src/Hook/EntityTestHooks.php
+++ b/core/modules/system/tests/modules/entity_test/src/Hook/EntityTestHooks.php
@@ -6,6 +6,7 @@
 
 use Drupal\Core\Access\AccessResultInterface;
 use Drupal\Core\Database\Query\AlterableInterface;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 use Drupal\Core\Url;
 use Drupal\Component\Render\FormattableMarkup;
 use Drupal\Core\Entity\Entity\EntityFormDisplay;
@@ -26,6 +27,8 @@
  */
 class EntityTestHooks {
 
+  use StringTranslationTrait;
+
   /**
    * Implements hook_entity_type_alter().
    */
@@ -84,10 +87,10 @@ public function entityBaseFieldInfo(EntityTypeInterface $entity_type) {
       ]);
     }
     if ($entity_type->id() == 'entity_test_mulrev' && \Drupal::state()->get('entity_test.field_test_item')) {
-      $fields['field_test_item'] = BaseFieldDefinition::create('field_test')->setLabel(t('Field test'))->setDescription(t('A field test.'))->setRevisionable(TRUE)->setTranslatable(TRUE);
+      $fields['field_test_item'] = BaseFieldDefinition::create('field_test')->setLabel($this->t('Field test'))->setDescription($this->t('A field test.'))->setRevisionable(TRUE)->setTranslatable(TRUE);
     }
     if ($entity_type->id() == 'entity_test_mulrev' && \Drupal::state()->get('entity_test.multi_column')) {
-      $fields['description'] = BaseFieldDefinition::create('shape')->setLabel(t('Some custom description'))->setTranslatable(TRUE);
+      $fields['description'] = BaseFieldDefinition::create('shape')->setLabel($this->t('Some custom description'))->setTranslatable(TRUE);
     }
     return $fields;
   }
@@ -164,12 +167,12 @@ public function entityViewModeInfoAlter(&$view_modes): void {
       if ($entity_info[$entity_type]->getProvider() == 'entity_test' && !isset($view_modes[$entity_type])) {
         $view_modes[$entity_type] = [
           'full' => [
-            'label' => t('Full object'),
+            'label' => $this->t('Full object'),
             'status' => TRUE,
             'cache' => TRUE,
           ],
           'teaser' => [
-            'label' => t('Teaser'),
+            'label' => $this->t('Teaser'),
             'status' => TRUE,
             'cache' => TRUE,
           ],
@@ -186,7 +189,7 @@ public function entityFormModeInfoAlter(&$form_modes): void {
     $entity_info = \Drupal::entityTypeManager()->getDefinitions();
     foreach ($entity_info as $entity_type => $info) {
       if ($entity_info[$entity_type]->getProvider() == 'entity_test') {
-        $form_modes[$entity_type]['compact'] = ['label' => t('Compact version'), 'status' => TRUE];
+        $form_modes[$entity_type]['compact'] = ['label' => $this->t('Compact version'), 'status' => TRUE];
       }
     }
   }
@@ -212,14 +215,14 @@ public function entityExtraFieldInfo() {
               // just used in \Drupal\Tests\field_ui\Kernel\EntityDisplayTest to test
               // the behavior of entity display objects.
         'display_extra_field' => [
-          'label' => t('Display extra field'),
-          'description' => t('An extra field on the display side.'),
+          'label' => $this->t('Display extra field'),
+          'description' => $this->t('An extra field on the display side.'),
           'weight' => 5,
           'visible' => TRUE,
         ],
         'display_extra_field_hidden' => [
-          'label' => t('Display extra field (hidden)'),
-          'description' => t('An extra field on the display side, hidden by default.'),
+          'label' => $this->t('Display extra field (hidden)'),
+          'description' => $this->t('An extra field on the display side, hidden by default.'),
           'visible' => FALSE,
         ],
       ],
diff --git a/core/modules/system/tests/modules/entity_test_operation/src/Hook/EntityTestOperationHooks.php b/core/modules/system/tests/modules/entity_test_operation/src/Hook/EntityTestOperationHooks.php
index 66a56340d88b..0c92bea81b87 100644
--- a/core/modules/system/tests/modules/entity_test_operation/src/Hook/EntityTestOperationHooks.php
+++ b/core/modules/system/tests/modules/entity_test_operation/src/Hook/EntityTestOperationHooks.php
@@ -4,6 +4,7 @@
 
 namespace Drupal\entity_test_operation\Hook;
 
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 use Drupal\Core\Url;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Hook\Attribute\Hook;
@@ -13,6 +14,8 @@
  */
 class EntityTestOperationHooks {
 
+  use StringTranslationTrait;
+
   /**
    * Implements hook_entity_operation().
    */
@@ -20,7 +23,7 @@ class EntityTestOperationHooks {
   public function entityOperation(EntityInterface $entity): array {
     return [
       'test' => [
-        'title' => t('Front page'),
+        'title' => $this->t('Front page'),
         'url' => Url::fromRoute('<front>'),
         'weight' => 0,
       ],
diff --git a/core/modules/system/tests/modules/experimental_module_requirements_test/src/Hook/ExperimentalModuleRequirementsTestHooks.php b/core/modules/system/tests/modules/experimental_module_requirements_test/src/Hook/ExperimentalModuleRequirementsTestHooks.php
index cfd042c50e36..21fb30ec2a46 100644
--- a/core/modules/system/tests/modules/experimental_module_requirements_test/src/Hook/ExperimentalModuleRequirementsTestHooks.php
+++ b/core/modules/system/tests/modules/experimental_module_requirements_test/src/Hook/ExperimentalModuleRequirementsTestHooks.php
@@ -5,12 +5,15 @@
 namespace Drupal\experimental_module_requirements_test\Hook;
 
 use Drupal\Core\Hook\Attribute\Hook;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 
 /**
  * Hook implementations for experimental_module_requirements_test.
  */
 class ExperimentalModuleRequirementsTestHooks {
 
+  use StringTranslationTrait;
+
   /**
    * Implements hook_help().
    */
@@ -19,7 +22,7 @@ public function help($route_name) {
     switch ($route_name) {
       case 'help.page.experimental_module_requirements_test':
         // Make the help text conform to core standards.
-        return t('The Experimental Requirements Test module is not done yet. It may eat your data, but you can read the <a href=":url">online documentation for the Experimental Requirements Test module</a>.', [':url' => 'http://www.example.com']);
+        return $this->t('The Experimental Requirements Test module is not done yet. It may eat your data, but you can read the <a href=":url">online documentation for the Experimental Requirements Test module</a>.', [':url' => 'http://www.example.com']);
     }
   }
 
diff --git a/core/modules/system/tests/modules/experimental_module_test/src/Hook/ExperimentalModuleTestHooks.php b/core/modules/system/tests/modules/experimental_module_test/src/Hook/ExperimentalModuleTestHooks.php
index 6dbd3f5b1a6f..c76245d20312 100644
--- a/core/modules/system/tests/modules/experimental_module_test/src/Hook/ExperimentalModuleTestHooks.php
+++ b/core/modules/system/tests/modules/experimental_module_test/src/Hook/ExperimentalModuleTestHooks.php
@@ -6,12 +6,15 @@
 
 use Drupal\Core\Routing\RouteMatchInterface;
 use Drupal\Core\Hook\Attribute\Hook;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 
 /**
  * Hook implementations for experimental_module_test.
  */
 class ExperimentalModuleTestHooks {
 
+  use StringTranslationTrait;
+
   /**
    * Implements hook_help().
    */
@@ -20,7 +23,7 @@ public function help($route_name, RouteMatchInterface $route_match) {
     switch ($route_name) {
       case 'help.page.experimental_module_test':
         // Make the help text conform to core standards.
-        return t('The Experimental Test module is not done yet. It may eat your data, but you can read the <a href=":url">online documentation for the Experimental Test module</a>.', [':url' => 'http://www.example.com']);
+        return $this->t('The Experimental Test module is not done yet. It may eat your data, but you can read the <a href=":url">online documentation for the Experimental Test module</a>.', [':url' => 'http://www.example.com']);
     }
   }
 
diff --git a/core/modules/system/tests/modules/form_test/src/Callbacks.php b/core/modules/system/tests/modules/form_test/src/Callbacks.php
index 1eb90b44bf32..1943c9ea8111 100644
--- a/core/modules/system/tests/modules/form_test/src/Callbacks.php
+++ b/core/modules/system/tests/modules/form_test/src/Callbacks.php
@@ -5,12 +5,15 @@
 namespace Drupal\form_test;
 
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 
 /**
  * Simple class for testing methods as Form API callbacks.
  */
 class Callbacks {
 
+  use StringTranslationTrait;
+
   /**
    * Form element validation handler for 'name' in form_test_validate_form().
    */
@@ -40,7 +43,7 @@ public function validateName(&$element, FormStateInterface $form_state) {
 
     if ($triggered) {
       // Output the element's value from $form_state.
-      \Drupal::messenger()->addStatus(t('@label value: @value', ['@label' => $element['#title'], '@value' => $form_state->getValue('name')]));
+      \Drupal::messenger()->addStatus($this->t('@label value: @value', ['@label' => $element['#title'], '@value' => $form_state->getValue('name')]));
 
       // Trigger a form validation error to see our changes.
       $form_state->setErrorByName('');
diff --git a/core/modules/system/tests/modules/form_test/src/Hook/FormTestHooks.php b/core/modules/system/tests/modules/form_test/src/Hook/FormTestHooks.php
index 29f0d6cb1bd1..cda2b92b3477 100644
--- a/core/modules/system/tests/modules/form_test/src/Hook/FormTestHooks.php
+++ b/core/modules/system/tests/modules/form_test/src/Hook/FormTestHooks.php
@@ -6,6 +6,7 @@
 
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Hook\Attribute\Hook;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 use Drupal\form_test\Callbacks;
 
 /**
@@ -13,6 +14,8 @@
  */
 class FormTestHooks {
 
+  use StringTranslationTrait;
+
   /**
    * Implements hook_form_FORM_ID_alter().
    */
@@ -54,7 +57,7 @@ public function systemFormFormTestAlterFormAlter(&$form, FormStateInterface $for
   public function formUserRegisterFormAlter(&$form, FormStateInterface $form_state) : void {
     $form['test_rebuild'] = [
       '#type' => 'submit',
-      '#value' => t('Rebuild'),
+      '#value' => $this->t('Rebuild'),
       '#submit' => [
         [Callbacks::class, 'userRegisterFormRebuild'],
       ],
diff --git a/core/modules/system/tests/modules/link_generation_test/src/Hook/LinkGenerationTestHooks.php b/core/modules/system/tests/modules/link_generation_test/src/Hook/LinkGenerationTestHooks.php
index e134e54c7c60..1762abc87be5 100644
--- a/core/modules/system/tests/modules/link_generation_test/src/Hook/LinkGenerationTestHooks.php
+++ b/core/modules/system/tests/modules/link_generation_test/src/Hook/LinkGenerationTestHooks.php
@@ -5,12 +5,15 @@
 namespace Drupal\link_generation_test\Hook;
 
 use Drupal\Core\Hook\Attribute\Hook;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 
 /**
  * Hook implementations for link_generation_test.
  */
 class LinkGenerationTestHooks {
 
+  use StringTranslationTrait;
+
   /**
    * Implements hook_link_alter().
    */
@@ -19,7 +22,7 @@ public function linkAlter(&$variables): void {
     if (\Drupal::state()->get('link_generation_test_link_alter', FALSE)) {
       // Add a text to the end of links.
       if (\Drupal::state()->get('link_generation_test_link_alter_safe', FALSE)) {
-        $variables['text'] = t('@text <strong>Test!</strong>', ['@text' => $variables['text']]);
+        $variables['text'] = $this->t('@text <strong>Test!</strong>', ['@text' => $variables['text']]);
       }
       else {
         $variables['text'] .= ' <strong>Test!</strong>';
diff --git a/core/modules/system/tests/modules/menu_test/src/Controller/MenuTestController.php b/core/modules/system/tests/modules/menu_test/src/Controller/MenuTestController.php
index 648d596423d3..24b29753e847 100644
--- a/core/modules/system/tests/modules/menu_test/src/Controller/MenuTestController.php
+++ b/core/modules/system/tests/modules/menu_test/src/Controller/MenuTestController.php
@@ -87,7 +87,7 @@ public function menuTestCallback() {
   public function titleCallback(array $_title_arguments = [], $_title = '') {
     $_title_arguments += ['case_number' => '2', 'title' => $_title];
     // phpcs:ignore Drupal.Semantics.FunctionT.NotLiteralString
-    return t($_title_arguments['title']) . ' - Case ' . $_title_arguments['case_number'];
+    return $this->t($_title_arguments['title']) . ' - Case ' . $_title_arguments['case_number'];
   }
 
   /**
diff --git a/core/modules/system/tests/modules/requirements1_test/src/Hook/Requirements1TestHooks.php b/core/modules/system/tests/modules/requirements1_test/src/Hook/Requirements1TestHooks.php
index f122ea913fbd..c766f6f423ae 100644
--- a/core/modules/system/tests/modules/requirements1_test/src/Hook/Requirements1TestHooks.php
+++ b/core/modules/system/tests/modules/requirements1_test/src/Hook/Requirements1TestHooks.php
@@ -5,19 +5,22 @@
 namespace Drupal\requirements1_test\Hook;
 
 use Drupal\Core\Hook\Attribute\Hook;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 
 /**
  * Hook implementations for requirements1_test.
  */
 class Requirements1TestHooks {
 
+  use StringTranslationTrait;
+
   /**
    * Implements hook_requirements_alter().
    */
   #[Hook('requirements_alter')]
   public function requirementsAlter(array &$requirements) : void {
     // Change the title.
-    $requirements['requirements1_test_alterable']['title'] = t('Requirements 1 Test - Changed');
+    $requirements['requirements1_test_alterable']['title'] = $this->t('Requirements 1 Test - Changed');
     // Decrease the severity.
     $requirements['requirements1_test_alterable']['severity'] = REQUIREMENT_WARNING;
     // Delete 'requirements1_test_deletable',
diff --git a/core/modules/system/tests/modules/service_provider_test/src/TestClass.php b/core/modules/system/tests/modules/service_provider_test/src/TestClass.php
index 4cf60159fa39..87babf9b96ee 100644
--- a/core/modules/system/tests/modules/service_provider_test/src/TestClass.php
+++ b/core/modules/system/tests/modules/service_provider_test/src/TestClass.php
@@ -6,6 +6,7 @@
 
 use Drupal\Core\State\StateInterface;
 use Drupal\Core\DestructableInterface;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 use Symfony\Component\HttpKernel\Event\ResponseEvent;
 use Symfony\Component\HttpKernel\Event\RequestEvent;
@@ -13,6 +14,8 @@
 
 class TestClass implements EventSubscriberInterface, DestructableInterface {
 
+  use StringTranslationTrait;
+
   /**
    * The state keyvalue collection.
    *
@@ -34,7 +37,7 @@ public function __construct(StateInterface $state) {
    * A simple kernel listener method.
    */
   public function onKernelRequestTest(RequestEvent $event) {
-    \Drupal::messenger()->addStatus(t('The service_provider_test event subscriber fired!'));
+    \Drupal::messenger()->addStatus($this->t('The service_provider_test event subscriber fired!'));
   }
 
   /**
diff --git a/core/modules/system/tests/modules/system_test/src/Hook/SystemTestHooks.php b/core/modules/system/tests/modules/system_test/src/Hook/SystemTestHooks.php
index 355ac85fc6c2..7b21b5c1067f 100644
--- a/core/modules/system/tests/modules/system_test/src/Hook/SystemTestHooks.php
+++ b/core/modules/system/tests/modules/system_test/src/Hook/SystemTestHooks.php
@@ -7,12 +7,15 @@
 use Drupal\Core\Extension\Extension;
 use Drupal\Core\Routing\RouteMatchInterface;
 use Drupal\Core\Hook\Attribute\Hook;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 
 /**
  * Hook implementations for system_test.
  */
 class SystemTestHooks {
 
+  use StringTranslationTrait;
+
   /**
    * Implements hook_help().
    */
@@ -21,8 +24,8 @@ public function help($route_name, RouteMatchInterface $route_match) {
     switch ($route_name) {
       case 'help.page.system_test':
         $output = '';
-        $output .= '<h2>' . t('Test Help Page') . '</h2>';
-        $output .= '<p>' . t('This is a test help page for the system_test module for the purpose of testing if the "Help" link displays properly.') . '</p>';
+        $output .= '<h2>' . $this->t('Test Help Page') . '</h2>';
+        $output .= '<p>' . $this->t('This is a test help page for the system_test module for the purpose of testing if the "Help" link displays properly.') . '</p>';
         return $output;
     }
   }
@@ -34,7 +37,7 @@ public function help($route_name, RouteMatchInterface $route_match) {
   public function modulesInstalled($modules): void {
     if (\Drupal::state()->get('system_test.verbose_module_hooks')) {
       foreach ($modules as $module) {
-        \Drupal::messenger()->addStatus(t('hook_modules_installed fired for @module', ['@module' => $module]));
+        \Drupal::messenger()->addStatus($this->t('hook_modules_installed fired for @module', ['@module' => $module]));
       }
     }
   }
@@ -46,7 +49,7 @@ public function modulesInstalled($modules): void {
   public function modulesUninstalled($modules, $is_syncing): void {
     if (\Drupal::state()->get('system_test.verbose_module_hooks')) {
       foreach ($modules as $module) {
-        \Drupal::messenger()->addStatus(t('hook_modules_uninstalled fired for @module', ['@module' => $module]));
+        \Drupal::messenger()->addStatus($this->t('hook_modules_uninstalled fired for @module', ['@module' => $module]));
       }
     }
     // Save the config.installer isSyncing() value to state to check that it is
@@ -104,7 +107,7 @@ public function pageAttachments(array &$page): void {
     // \Drupal::service('path.matcher')->isFrontPage().
     $frontpage = \Drupal::state()->get('system_test.front_page_output', 0);
     if ($frontpage && \Drupal::service('path.matcher')->isFrontPage()) {
-      \Drupal::messenger()->addStatus(t('On front page.'));
+      \Drupal::messenger()->addStatus($this->t('On front page.'));
     }
   }
 
@@ -115,7 +118,7 @@ public function pageAttachments(array &$page): void {
   public function filetransferInfo() {
     return [
       'system_test' => [
-        'title' => t('System Test FileTransfer'),
+        'title' => $this->t('System Test FileTransfer'),
         'class' => 'Drupal\system_test\MockFileTransfer',
         'weight' => -10,
       ],
diff --git a/core/modules/system/tests/modules/system_test/src/MockFileTransfer.php b/core/modules/system/tests/modules/system_test/src/MockFileTransfer.php
index 7e4b669843d4..308286c69b5a 100644
--- a/core/modules/system/tests/modules/system_test/src/MockFileTransfer.php
+++ b/core/modules/system/tests/modules/system_test/src/MockFileTransfer.php
@@ -4,11 +4,15 @@
 
 namespace Drupal\system_test;
 
+use Drupal\Core\StringTranslation\StringTranslationTrait;
+
 /**
  * Mock FileTransfer object to test the settings form functionality.
  */
 class MockFileTransfer {
 
+  use StringTranslationTrait;
+
   /**
    * Returns a Drupal\system_test\MockFileTransfer object.
    *
@@ -26,7 +30,7 @@ public function getSettingsForm() {
     $form = [];
     $form['system_test_username'] = [
       '#type' => 'textfield',
-      '#title' => t('System Test Username'),
+      '#title' => $this->t('System Test Username'),
     ];
     return $form;
   }
diff --git a/core/modules/system/tests/modules/test_page_test/src/Controller/TestPageTestController.php b/core/modules/system/tests/modules/test_page_test/src/Controller/TestPageTestController.php
index 29bd6680d409..ea4e06fd5637 100644
--- a/core/modules/system/tests/modules/test_page_test/src/Controller/TestPageTestController.php
+++ b/core/modules/system/tests/modules/test_page_test/src/Controller/TestPageTestController.php
@@ -4,6 +4,7 @@
 
 namespace Drupal\test_page_test\Controller;
 
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 use Drupal\user\Entity\Role;
 
 /**
@@ -11,14 +12,16 @@
  */
 class TestPageTestController {
 
+  use StringTranslationTrait;
+
   /**
    * Returns a test page and sets the title.
    */
   public function testPage() {
-    $link_text = t('Visually identical test links');
+    $link_text = $this->t('Visually identical test links');
     return [
-      '#title' => t('Test page'),
-      '#markup' => t('Test page text.') . "<a href=\"/user/login\">$link_text</a><a href=\"/user/register\">$link_text</a>",
+      '#title' => $this->t('Test page'),
+      '#markup' => $this->t('Test page text.') . "<a href=\"/user/login\">$link_text</a><a href=\"/user/register\">$link_text</a>",
       '#attached' => [
         'drupalSettings' => [
           'test-setting' => 'azAZ09();.,\\\/-_{}',
@@ -34,8 +37,8 @@ public function testPageVarDump() {
     $role = Role::create(['id' => 'test_role', 'label' => 'Test role']);
     dump($role);
     return [
-      '#title' => t('Test page with var dump'),
-      '#markup' => t('Test page text.'),
+      '#title' => $this->t('Test page with var dump'),
+      '#markup' => $this->t('Test page text.'),
     ];
   }
 
diff --git a/core/modules/system/tests/modules/update_script_test/src/Hook/UpdateScriptTestHooks.php b/core/modules/system/tests/modules/update_script_test/src/Hook/UpdateScriptTestHooks.php
index 230fb7b7e25b..668582e865c8 100644
--- a/core/modules/system/tests/modules/update_script_test/src/Hook/UpdateScriptTestHooks.php
+++ b/core/modules/system/tests/modules/update_script_test/src/Hook/UpdateScriptTestHooks.php
@@ -6,12 +6,15 @@
 
 use Drupal\Core\Extension\Extension;
 use Drupal\Core\Hook\Attribute\Hook;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 
 /**
  * Hook implementations for update_script_test.
  */
 class UpdateScriptTestHooks {
 
+  use StringTranslationTrait;
+
   /**
    * Implements hook_cache_flush().
    *
@@ -22,7 +25,7 @@ class UpdateScriptTestHooks {
    */
   #[Hook('cache_flush')]
   public function cacheFlush(): void {
-    \Drupal::messenger()->addStatus(t('hook_cache_flush() invoked for update_script_test.module.'));
+    \Drupal::messenger()->addStatus($this->t('hook_cache_flush() invoked for update_script_test.module.'));
   }
 
   /**
diff --git a/core/phpcs.xml.dist b/core/phpcs.xml.dist
index 4534ec882e3b..5cd466001454 100644
--- a/core/phpcs.xml.dist
+++ b/core/phpcs.xml.dist
@@ -190,6 +190,7 @@
     <include-pattern>*/Plugin/*</include-pattern>
     <include-pattern>*/ListBuilder/*</include-pattern>
     <include-pattern>*/tests/*/Form/*</include-pattern>
+    <include-pattern>*/modules/system/tests/modules/*</include-pattern>
   </rule>
 
   <!-- Generic sniffs -->
-- 
GitLab