diff --git a/core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php b/core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php index 5bbca4227c66e4bd3a8e14f1ee20b17ca850ce3c..a4ba7e9d1872684cb68471e97318c267aabef6c0 100644 --- a/core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php +++ b/core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php @@ -7,6 +7,7 @@ use Drupal\Core\Database\Database; use Drupal\Core\File\FileExists; use Drupal\Core\Language\LanguageInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Tests\BrowserTestBase; @@ -20,6 +21,8 @@ */ class LocaleImportFunctionalTest extends BrowserTestBase { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -266,8 +269,8 @@ public function testLanguageContext(): void { // We cast the return value of t() to string so as to retrieve the // translated value, rendered as a string. - $this->assertSame('Svibanj', (string) t('May', [], ['langcode' => 'hr', 'context' => 'Long month name']), 'Long month name context is working.'); - $this->assertSame('Svi.', (string) t('May', [], ['langcode' => 'hr']), 'Default context is working.'); + $this->assertSame('Svibanj', (string) $this->t('May', [], ['langcode' => 'hr', 'context' => 'Long month name']), 'Long month name context is working.'); + $this->assertSame('Svi.', (string) $this->t('May', [], ['langcode' => 'hr']), 'Default context is working.'); } /** @@ -282,7 +285,7 @@ public function testEmptyMsgstr(): void { ]); $this->assertSession()->pageTextContains("One translation file imported. 1 translations were added, 0 translations were updated and 0 translations were removed."); - $this->assertSame('Műveletek', (string) t('Operations', [], ['langcode' => $langcode]), 'String imported and translated.'); + $this->assertSame('Műveletek', (string) $this->t('Operations', [], ['langcode' => $langcode]), 'String imported and translated.'); // Try importing a .po file. $this->importPoFile($this->getPoFileWithEmptyMsgstr(), [ diff --git a/core/modules/locale/tests/src/Functional/LocaleTranslationUiTest.php b/core/modules/locale/tests/src/Functional/LocaleTranslationUiTest.php index 24bd122a86ea3b052d15722ac428e6fe388a629d..8e9b2b56d128e903e800f2d62a5899ed6ce4aa4f 100644 --- a/core/modules/locale/tests/src/Functional/LocaleTranslationUiTest.php +++ b/core/modules/locale/tests/src/Functional/LocaleTranslationUiTest.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\locale\Functional; use Drupal\Core\Site\Settings; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Database\Database; use Drupal\language\Entity\ConfigurableLanguage; @@ -20,6 +21,8 @@ */ class LocaleTranslationUiTest extends BrowserTestBase { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -83,7 +86,7 @@ public function testStringTranslation(): void { $this->drupalGet('admin/config/regional/language/add'); $this->submitForm($edit, 'Add custom language'); // Add string. - t($name, [], ['langcode' => $langcode])->render(); + $this->t($name, [], ['langcode' => $langcode])->render(); // Reset locale cache. $this->container->get('string_translation')->reset(); $this->assertSession()->responseContains('"edit-languages-' . $langcode . '-weight"'); @@ -165,15 +168,15 @@ public function testStringTranslation(): void { $this->assertSession()->pageTextContains($translation_to_en); $this->assertNotEquals($translation, $name); - $this->assertEquals($translation, t($name, [], ['langcode' => $langcode]), 't() works for non-English.'); + $this->assertEquals($translation, $this->t($name, [], ['langcode' => $langcode]), 't() works for non-English.'); // Refresh the locale() cache to get fresh data from t() below. We are in // the same HTTP request and therefore t() is not refreshed by saving the // translation above. $this->container->get('string_translation')->reset(); // Now we should get the proper fresh translation from t(). $this->assertNotEquals($translation_to_en, $name); - $this->assertEquals($translation_to_en, t($name, [], ['langcode' => 'en']), 't() works for English.'); - $this->assertTrue(t($name, [], ['langcode' => LanguageInterface::LANGCODE_SYSTEM]) == $name, 't() works for LanguageInterface::LANGCODE_SYSTEM.'); + $this->assertEquals($translation_to_en, $this->t($name, [], ['langcode' => 'en']), 't() works for English.'); + $this->assertTrue($this->t($name, [], ['langcode' => LanguageInterface::LANGCODE_SYSTEM]) == $name, 't() works for LanguageInterface::LANGCODE_SYSTEM.'); $search = [ 'string' => $name, @@ -367,7 +370,7 @@ public function testStringValidation(): void { $this->drupalGet('admin/config/regional/language/add'); $this->submitForm($edit, 'Add custom language'); // Add string. - t($name, [], ['langcode' => $langcode])->render(); + $this->t($name, [], ['langcode' => $langcode])->render(); // Reset locale cache. $search = [ 'string' => $name, @@ -436,7 +439,7 @@ public function testStringSearch(): void { $this->submitForm($edit, 'Add custom language'); // Add string. - t($name, [], ['langcode' => $langcode])->render(); + $this->t($name, [], ['langcode' => $langcode])->render(); // Reset locale cache. $this->container->get('string_translation')->reset(); $this->drupalLogout(); diff --git a/core/modules/locale/tests/src/Functional/LocaleUpdateTest.php b/core/modules/locale/tests/src/Functional/LocaleUpdateTest.php index 3d0c9b804a7c9276a3fb8ba007660386c14beaf0..bcd4aacc6e7fd11fb170b7e3442871e579d61eac 100644 --- a/core/modules/locale/tests/src/Functional/LocaleUpdateTest.php +++ b/core/modules/locale/tests/src/Functional/LocaleUpdateTest.php @@ -6,6 +6,7 @@ use Drupal\Core\Database\Database; use Drupal\Core\Language\LanguageInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; // cspell:ignore extraday lundi @@ -16,6 +17,8 @@ */ class LocaleUpdateTest extends LocaleUpdateBase { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -169,13 +172,13 @@ public function testUpdateImportSourceRemote(): void { // Check whether existing translations have (not) been overwritten. // cSpell:disable - $this->assertEquals('Januar_1', t('January', [], ['langcode' => 'de']), 'Translation of January'); - $this->assertEquals('Februar_2', t('February', [], ['langcode' => 'de']), 'Translation of February'); - $this->assertEquals('Marz_2', t('March', [], ['langcode' => 'de']), 'Translation of March'); - $this->assertEquals('April_2', t('April', [], ['langcode' => 'de']), 'Translation of April'); - $this->assertEquals('Mai_customized', t('May', [], ['langcode' => 'de']), 'Translation of May'); - $this->assertEquals('Juni', t('June', [], ['langcode' => 'de']), 'Translation of June'); - $this->assertEquals('Montag', t('Monday', [], ['langcode' => 'de']), 'Translation of Monday'); + $this->assertEquals('Januar_1', $this->t('January', [], ['langcode' => 'de']), 'Translation of January'); + $this->assertEquals('Februar_2', $this->t('February', [], ['langcode' => 'de']), 'Translation of February'); + $this->assertEquals('Marz_2', $this->t('March', [], ['langcode' => 'de']), 'Translation of March'); + $this->assertEquals('April_2', $this->t('April', [], ['langcode' => 'de']), 'Translation of April'); + $this->assertEquals('Mai_customized', $this->t('May', [], ['langcode' => 'de']), 'Translation of May'); + $this->assertEquals('Juni', $this->t('June', [], ['langcode' => 'de']), 'Translation of June'); + $this->assertEquals('Montag', $this->t('Monday', [], ['langcode' => 'de']), 'Translation of Monday'); // cSpell:enable } @@ -229,13 +232,13 @@ public function testUpdateImportSourceLocal(): void { // Check whether existing translations have (not) been overwritten. // cSpell:disable - $this->assertEquals('Januar_customized', t('January', [], ['langcode' => 'de']), 'Translation of January'); - $this->assertEquals('Februar_2', t('February', [], ['langcode' => 'de']), 'Translation of February'); - $this->assertEquals('Marz_2', t('March', [], ['langcode' => 'de']), 'Translation of March'); - $this->assertEquals('April_2', t('April', [], ['langcode' => 'de']), 'Translation of April'); - $this->assertEquals('Mai_customized', t('May', [], ['langcode' => 'de']), 'Translation of May'); - $this->assertEquals('Juni', t('June', [], ['langcode' => 'de']), 'Translation of June'); - $this->assertEquals('Montag', t('Monday', [], ['langcode' => 'de']), 'Translation of Monday'); + $this->assertEquals('Januar_customized', $this->t('January', [], ['langcode' => 'de']), 'Translation of January'); + $this->assertEquals('Februar_2', $this->t('February', [], ['langcode' => 'de']), 'Translation of February'); + $this->assertEquals('Marz_2', $this->t('March', [], ['langcode' => 'de']), 'Translation of March'); + $this->assertEquals('April_2', $this->t('April', [], ['langcode' => 'de']), 'Translation of April'); + $this->assertEquals('Mai_customized', $this->t('May', [], ['langcode' => 'de']), 'Translation of May'); + $this->assertEquals('Juni', $this->t('June', [], ['langcode' => 'de']), 'Translation of June'); + $this->assertEquals('Montag', $this->t('Monday', [], ['langcode' => 'de']), 'Translation of Monday'); // cSpell:enable } @@ -269,13 +272,13 @@ public function testUpdateImportModeNonCustomized(): void { // Check whether existing translations have (not) been overwritten. // cSpell:disable - $this->assertEquals('Januar_customized', t('January', [], ['langcode' => 'de']), 'Translation of January'); - $this->assertEquals('Februar_customized', t('February', [], ['langcode' => 'de']), 'Translation of February'); - $this->assertEquals('Marz_2', t('March', [], ['langcode' => 'de']), 'Translation of March'); - $this->assertEquals('April_2', t('April', [], ['langcode' => 'de']), 'Translation of April'); - $this->assertEquals('Mai_customized', t('May', [], ['langcode' => 'de']), 'Translation of May'); - $this->assertEquals('Juni', t('June', [], ['langcode' => 'de']), 'Translation of June'); - $this->assertEquals('Montag', t('Monday', [], ['langcode' => 'de']), 'Translation of Monday'); + $this->assertEquals('Januar_customized', $this->t('January', [], ['langcode' => 'de']), 'Translation of January'); + $this->assertEquals('Februar_customized', $this->t('February', [], ['langcode' => 'de']), 'Translation of February'); + $this->assertEquals('Marz_2', $this->t('March', [], ['langcode' => 'de']), 'Translation of March'); + $this->assertEquals('April_2', $this->t('April', [], ['langcode' => 'de']), 'Translation of April'); + $this->assertEquals('Mai_customized', $this->t('May', [], ['langcode' => 'de']), 'Translation of May'); + $this->assertEquals('Juni', $this->t('June', [], ['langcode' => 'de']), 'Translation of June'); + $this->assertEquals('Montag', $this->t('Monday', [], ['langcode' => 'de']), 'Translation of Monday'); // cSpell:enable } diff --git a/core/modules/navigation/tests/src/Functional/NavigationLogoTest.php b/core/modules/navigation/tests/src/Functional/NavigationLogoTest.php index aaf1c183de3834af116be95c1d3f37c77b132194..2825f3b9ee816a59f1b9727fc2445b42703eeff2 100644 --- a/core/modules/navigation/tests/src/Functional/NavigationLogoTest.php +++ b/core/modules/navigation/tests/src/Functional/NavigationLogoTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\navigation\Functional; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\file\Entity\File; use Drupal\Tests\BrowserTestBase; use Drupal\Tests\TestFileCreationTrait; @@ -15,6 +16,7 @@ */ class NavigationLogoTest extends BrowserTestBase { + use StringTranslationTrait; use TestFileCreationTrait; /** @@ -91,7 +93,7 @@ public function testSettingsLogoOptionsForm(): void { 'logo_provider' => 'custom', 'logo_path' => $logo_file->getFileUri(), ]; - $this->submitForm($edit, t('Save configuration')); + $this->submitForm($edit, $this->t('Save configuration')); // Refresh the page to verify custom logo is placed. $this->drupalGet('/admin/config/user-interface/navigation/settings'); $this->assertSession()->elementExists('css', 'a.admin-toolbar__logo > img'); @@ -102,7 +104,7 @@ public function testSettingsLogoOptionsForm(): void { 'logo_provider' => 'custom', 'logo_path' => 'core/misc/logo/drupal-logo.svg', ]; - $this->submitForm($edit, t('Save configuration')); + $this->submitForm($edit, $this->t('Save configuration')); // Refresh the page to verify custom logo is placed. $this->drupalGet('/admin/config/user-interface/navigation/settings'); $this->assertSession()->elementExists('css', 'a.admin-toolbar__logo > img'); @@ -114,7 +116,7 @@ public function testSettingsLogoOptionsForm(): void { 'logo_provider' => 'custom', 'files[logo_upload]' => $this->fileSystem->realpath($file->uri), ]; - $this->submitForm($edit, t('Save configuration')); + $this->submitForm($edit, $this->t('Save configuration')); $this->assertSession()->statusMessageContains('The image was resized to fit within the navigation logo expected dimensions of 40x40 pixels. The new dimensions of the resized image are 40x27 pixels.'); // Refresh the page to verify custom logo is placed. $this->drupalGet('/admin/config/user-interface/navigation/settings'); diff --git a/core/modules/node/tests/src/Functional/NodeTypeTranslationTest.php b/core/modules/node/tests/src/Functional/NodeTypeTranslationTest.php index 84b56ff3ec668dc717d17727f8952c9722f5fd0f..a8f608d2ab133216d6b374ade09609526980ee2f 100644 --- a/core/modules/node/tests/src/Functional/NodeTypeTranslationTest.php +++ b/core/modules/node/tests/src/Functional/NodeTypeTranslationTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\node\Functional; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\Tests\BrowserTestBase; @@ -18,6 +19,8 @@ */ class NodeTypeTranslationTest extends BrowserTestBase { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -125,7 +128,7 @@ public function testNodeTypeTranslation(): void { $this->drupalGet("$langcode/node/add/$type"); // This is a Spanish page, so ensure the text asserted is translated in // Spanish and not French by adding the langcode option. - $this->assertSession()->responseContains(t('Create @name', ['@name' => $translated_name], ['langcode' => $langcode])); + $this->assertSession()->responseContains($this->t('Create @name', ['@name' => $translated_name], ['langcode' => $langcode])); // Check the name is translated with admin theme for editing. $this->drupalGet('admin/appearance'); @@ -133,7 +136,7 @@ public function testNodeTypeTranslation(): void { $this->drupalGet("$langcode/node/add/$type"); // This is a Spanish page, so ensure the text asserted is translated in // Spanish and not French by adding the langcode option. - $this->assertSession()->responseContains(t('Create @name', ['@name' => $translated_name], ['langcode' => $langcode])); + $this->assertSession()->responseContains($this->t('Create @name', ['@name' => $translated_name], ['langcode' => $langcode])); } /** diff --git a/core/modules/shortcut/tests/src/Functional/Rest/ShortcutResourceTestBase.php b/core/modules/shortcut/tests/src/Functional/Rest/ShortcutResourceTestBase.php index df94f82824cd666d7d45d5effe35230efed7b613..563d23280804488e3b57f0b5a4a60829c5c89248 100644 --- a/core/modules/shortcut/tests/src/Functional/Rest/ShortcutResourceTestBase.php +++ b/core/modules/shortcut/tests/src/Functional/Rest/ShortcutResourceTestBase.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\shortcut\Functional\Rest; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\shortcut\Entity\Shortcut; use Drupal\shortcut\Entity\ShortcutSet; use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase; @@ -13,6 +14,8 @@ */ abstract class ShortcutResourceTestBase extends EntityResourceTestBase { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -56,7 +59,7 @@ protected function createEntity() { // Create shortcut. $shortcut = Shortcut::create([ 'shortcut_set' => 'default', - 'title' => t('Comments'), + 'title' => $this->t('Comments'), 'weight' => -20, 'link' => [ 'uri' => 'internal:/admin/content/comment', diff --git a/core/modules/system/tests/src/Functional/Rest/ActionResourceTestBase.php b/core/modules/system/tests/src/Functional/Rest/ActionResourceTestBase.php index 8cd01e2643d785533ebeddac19f68bd1bcd84196..8edb96f9ee944d7f1aa898f007f62f58db682d65 100644 --- a/core/modules/system/tests/src/Functional/Rest/ActionResourceTestBase.php +++ b/core/modules/system/tests/src/Functional/Rest/ActionResourceTestBase.php @@ -4,12 +4,15 @@ namespace Drupal\Tests\system\Functional\Rest; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Tests\rest\Functional\EntityResource\ConfigEntityResourceTestBase; use Drupal\system\Entity\Action; use Drupal\user\RoleInterface; abstract class ActionResourceTestBase extends ConfigEntityResourceTestBase { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -39,7 +42,7 @@ protected function createEntity() { $action = Action::create([ 'id' => 'user_add_role_action.' . RoleInterface::ANONYMOUS_ID, 'type' => 'user', - 'label' => t('Add the anonymous role to the selected users'), + 'label' => $this->t('Add the anonymous role to the selected users'), 'configuration' => [ 'rid' => RoleInterface::ANONYMOUS_ID, ], diff --git a/core/modules/toolbar/tests/src/Functional/ToolbarAdminMenuTest.php b/core/modules/toolbar/tests/src/Functional/ToolbarAdminMenuTest.php index 9d0bbd8c6af4bde15d45ba31714d379b34d91eb8..d4648aa24214367d1bc8a86f8e1de2d4b5aa1911 100644 --- a/core/modules/toolbar/tests/src/Functional/ToolbarAdminMenuTest.php +++ b/core/modules/toolbar/tests/src/Functional/ToolbarAdminMenuTest.php @@ -6,6 +6,7 @@ use Drupal\Core\EventSubscriber\MainContentViewSubscriber; use Drupal\Core\Language\LanguageInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\Tests\BrowserTestBase; @@ -31,6 +32,8 @@ */ class ToolbarAdminMenuTest extends BrowserTestBase { + use StringTranslationTrait; + /** * A user with permission to access the administrative toolbar. * @@ -309,7 +312,7 @@ public function testLocaleTranslationSubtreesHashCacheClear(): void { $this->drupalGet('admin/config/regional/language/add'); $this->submitForm($edit, 'Add custom language'); // phpcs:ignore Drupal.Semantics.FunctionT.NotLiteralString - t($name, [], ['langcode' => $langcode]); + $this->t($name, [], ['langcode' => $langcode]); // Reset locale cache. $this->container->get('string_translation')->reset(); $this->assertSession()->responseContains('"edit-languages-' . $langcode . '-weight"'); diff --git a/core/phpcs.xml.dist b/core/phpcs.xml.dist index 60105a430d96fa8e383750e6537b664057d74287..bd8ff3e6d62f33fce79b7a24f65f51349daa6f0f 100644 --- a/core/phpcs.xml.dist +++ b/core/phpcs.xml.dist @@ -192,6 +192,7 @@ <include-pattern>*/tests/*/Form/*</include-pattern> <include-pattern>*/modules/system/tests/modules/*</include-pattern> <include-pattern>*/Kernel*/*</include-pattern> + <include-pattern>*/tests/*/Functional*/*</include-pattern> </rule> <!-- Generic sniffs --> diff --git a/core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationMultipleLanguageNonInteractiveTest.php b/core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationMultipleLanguageNonInteractiveTest.php index 8a47151e7d4958777a4f581320db37bdf774a114..89039734192f939887800d42187f5ab12ae1febe 100644 --- a/core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationMultipleLanguageNonInteractiveTest.php +++ b/core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationMultipleLanguageNonInteractiveTest.php @@ -4,6 +4,7 @@ namespace Drupal\FunctionalTests\Installer; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Tests\BrowserTestBase; // cspell:ignore montag @@ -15,6 +16,8 @@ */ class InstallerTranslationMultipleLanguageNonInteractiveTest extends BrowserTestBase { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -124,7 +127,7 @@ public function testTranslationsLoaded(): void { $this->assertEquals('Anonymous es', $override_es->get('anonymous')); // Test translation from locale_test module. - $this->assertEquals('Montag', t('Monday', [], ['langcode' => 'de'])); + $this->assertEquals('Montag', $this->t('Monday', [], ['langcode' => 'de'])); } /**