From e39262bf5beb646d5b82d75ec6960612c8d9ba9c Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Thu, 11 Jul 2019 09:06:33 +0100 Subject: [PATCH] =?UTF-8?q?Issue=20#2228741=20by=20rpayanm,=20mikelutz,=20?= =?UTF-8?q?voleger,=20epari.siva,=20malotor,=20Rolf=20van=20de=20Krol,=20q?= =?UTF-8?q?uietone,=20Mile23,=20andypost,=20ianthomas=5Fuk,=20Lendude,=20a?= =?UTF-8?q?lexpott,=20dawehner,=20xjm,=20G=C3=A1bor=20Hojtsy,=20Berdir,=20?= =?UTF-8?q?catch:=20Replace=20calls=20to=20format=5Fstring()=20with=20Drup?= =?UTF-8?q?al\Component\Render\FormattableMarkup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/includes/bootstrap.inc | 10 +- core/lib/Drupal/Core/Test/AssertMailTrait.php | 6 +- .../src/Tests/AggregatorTestBase.php | 7 +- .../src/Functional/AggregatorAdminTest.php | 4 +- .../Functional/AggregatorRenderingTest.php | 2 +- .../src/Functional/AggregatorTestBase.php | 7 +- .../tests/src/Functional/FeedParserTest.php | 7 +- .../src/Functional/UpdateFeedItemTest.php | 5 +- .../tests/src/Functional/UpdateFeedTest.php | 4 +- .../block/tests/src/Functional/BlockTest.php | 3 +- .../src/Functional/Views/DisplayBlockTest.php | 5 +- .../Functional/BlockContentCreationTest.php | 11 +- .../Functional/BlockContentRevisionsTest.php | 3 +- .../src/Functional/BlockContentTypeTest.php | 3 +- .../Functional/BlockContentValidationTest.php | 4 +- .../tests/src/Functional/PageEditTest.php | 3 +- .../book/tests/src/Functional/BookTest.php | 3 +- .../tests/src/Functional/BookTestTrait.php | 4 +- .../comment/src/Tests/CommentTestBase.php | 11 +- .../src/Functional/CommentFieldsTest.php | 3 +- .../src/Functional/CommentLanguageTest.php | 3 +- .../src/Functional/CommentNonNodeTest.php | 5 +- .../tests/src/Functional/CommentPagerTest.php | 6 +- .../tests/src/Functional/CommentTestBase.php | 11 +- .../src/Functional/CommentThreadingTest.php | 5 +- .../Functional/CommentTokenReplaceTest.php | 4 +- .../Views/DefaultViewRecentCommentsTest.php | 3 +- .../tests/config_test/src/ConfigTestForm.php | 5 +- .../tests/src/Functional/ConfigEntityTest.php | 8 +- .../src/Functional/ConfigImportUITest.php | 32 +-- .../Functional/ConfigTranslationUiTest.php | 4 +- .../src/Functional/ContactSitewideTest.php | 7 +- .../Tests/ContentTranslationUITestBase.php | 10 +- .../ContentTranslationSettingsTest.php | 3 +- .../ContentTranslationSyncImageTest.php | 7 +- .../ContentTranslationUITestBase.php | 6 +- .../ContentTranslationWorkflowsTest.php | 4 +- .../src/Functional/DateTimeFieldTest.php | 12 +- .../dblog/tests/src/Functional/DbLogTest.php | 13 +- .../dblog/tests/src/Kernel/DbLogTest.php | 7 +- .../src/Functional/EditorSecurityTest.php | 5 +- .../modules/field/src/Tests/FieldTestBase.php | 3 +- .../EntityReferenceIntegrationTest.php | 2 +- .../tests/src/Functional/FieldTestBase.php | 3 +- .../src/Functional/String/StringFieldTest.php | 3 +- .../src/Functional/TranslationWebTest.php | 3 +- .../field/tests/src/Kernel/DisplayApiTest.php | 19 +- .../EntityReferenceFormatterTest.php | 5 +- .../src/Kernel/FieldAttachStorageTest.php | 9 +- .../tests/src/Kernel/FieldDataCountTest.php | 3 +- .../tests/src/Kernel/FieldKernelTestBase.php | 3 +- .../src/Kernel/FieldTypePluginManagerTest.php | 4 +- .../tests/src/Kernel/TranslationTest.php | 7 +- .../Functional/ManageFieldsFunctionalTest.php | 6 +- .../file/src/Tests/FileFieldTestBase.php | 11 +- .../file/src/Tests/FileManagedTestBase.php | 11 +- .../src/Functional/FileFieldDisplayTest.php | 2 +- .../src/Functional/FileFieldPathTest.php | 7 +- .../src/Functional/FileFieldTestBase.php | 11 +- .../src/Functional/FileFieldValidateTest.php | 13 +- .../src/Functional/FileFieldWidgetTest.php | 3 +- .../src/Functional/FileManagedTestBase.php | 11 +- .../src/Functional/FileTokenReplaceTest.php | 5 +- .../FileFieldWidgetTest.php | 3 +- .../src/Kernel/FileManagedUnitTestBase.php | 11 +- .../file/tests/src/Kernel/MoveTest.php | 3 +- .../Plugin/Filter/FilterTestPlaceholders.php | 3 +- .../Functional/FilterHtmlImageSecureTest.php | 3 +- .../filter/tests/src/Kernel/FilterAPITest.php | 3 +- .../tests/src/Kernel/FilterCrudTest.php | 9 +- .../tests/src/Kernel/FilterKernelTest.php | 13 +- .../tests/src/Functional/ForumBlockTest.php | 11 +- .../forum/tests/src/Functional/ForumTest.php | 5 +- .../help/tests/src/Functional/HelpTest.php | 5 +- .../src/Functional/ImageAdminStylesTest.php | 24 +- .../ImageFieldDefaultImagesTest.php | 33 +-- .../src/Functional/ImageFieldDisplayTest.php | 3 +- .../src/Functional/ImageStyleFlushTest.php | 9 +- .../Functional/LanguageConfigurationTest.php | 3 +- .../LanguageNegotiationInfoTest.php | 11 +- .../LanguageUILanguageNegotiationTest.php | 7 +- .../Functional/LocaleImportFunctionalTest.php | 3 +- .../tests/src/Functional/LocaleUpdateBase.php | 2 +- core/modules/node/src/Tests/NodeTestBase.php | 3 +- .../src/Functional/NodeLoadMultipleTest.php | 5 +- .../tests/src/Functional/NodeTestBase.php | 3 +- .../src/Functional/NodeTranslationUITest.php | 5 +- .../src/Functional/Views/FrontPageTest.php | 3 +- .../src/Kernel/NodeAccessRecordsTest.php | 3 +- .../tests/src/Kernel/NodeTokenReplaceTest.php | 2 +- .../src/Functional/OptionsFieldUITest.php | 3 +- .../search/src/Tests/SearchTestBase.php | 4 +- .../SearchConfigSettingsFormTest.php | 3 +- .../Functional/SearchNumberMatchingTest.php | 5 +- .../src/Functional/SearchNumbersTest.php | 3 +- .../src/Functional/ShortcutLinksTest.php | 4 +- .../Functional/ShortcutTranslationUITest.php | 5 +- .../modules/simpletest/src/KernelTestBase.php | 8 +- .../Tests/SimpleTestErrorCollectorTest.php | 9 +- .../simpletest/src/Tests/SimpleTestTest.php | 3 +- core/modules/simpletest/src/WebTestBase.php | 10 +- .../Functional/StatisticsTokenReplaceTest.php | 4 +- .../src/Tests/Menu/AssertBreadcrumbTrait.php | 3 +- .../Tests/Menu/AssertMenuActiveTrailTrait.php | 3 +- .../src/Tests/Module/ModuleTestBase.php | 17 +- .../Tests/System/SystemConfigFormTestBase.php | 3 +- .../modules/entity_test/entity_test.module | 3 +- .../tests/src/Functional/Cache/ClearTest.php | 3 +- .../tests/src/Functional/Common/UrlTest.php | 13 +- .../Database/SelectPagerDefaultTest.php | 5 +- .../Database/SelectTableSortDefaultTest.php | 6 +- .../src/Functional/Entity/EntityFormTest.php | 23 +- .../Entity/EntityOperationsTest.php | 3 +- .../EntityReferenceSelectionAccessTest.php | 5 +- .../Functional/Entity/EntityRevisionsTest.php | 29 +-- .../src/Functional/Form/CheckboxTest.php | 7 +- .../tests/src/Functional/Form/ElementTest.php | 9 +- .../tests/src/Functional/Form/FormTest.php | 22 +- .../Form/LanguageSelectElementTest.php | 9 +- .../Functional/Form/StateValuesCleanTest.php | 16 +- .../src/Functional/Form/ValidationTest.php | 3 +- .../Functional/Menu/AssertBreadcrumbTrait.php | 3 +- .../Menu/AssertMenuActiveTrailTrait.php | 3 +- .../src/Functional/Menu/LocalTasksTest.php | 3 +- .../src/Functional/Module/InstallTest.php | 5 +- .../src/Functional/Module/ModuleTestBase.php | 17 +- .../Path/UrlAlterFunctionalTest.php | 5 +- .../src/Functional/Session/SessionTest.php | 3 +- .../Functional/System/ErrorHandlerTest.php | 12 +- .../FunctionalJavascript/FrameworkTest.php | 19 +- .../src/Kernel/Block/SystemMenuBlockTest.php | 5 +- .../tests/src/Kernel/Common/AddFeedTest.php | 3 +- .../Kernel/Common/FormElementsRenderTest.php | 3 +- .../src/Kernel/Common/SystemListingTest.php | 5 +- .../Kernel/Extension/ModuleHandlerTest.php | 3 +- .../src/Kernel/Form/ProgrammaticTest.php | 5 +- .../tests/src/Kernel/Theme/ThemeTest.php | 3 +- .../Kernel/Token/TokenReplaceKernelTest.php | 4 +- .../tests/src/Functional/LoadMultipleTest.php | 3 +- .../tests/src/Functional/TermTest.php | 7 +- .../tests/src/Functional/TokenReplaceTest.php | 7 +- .../tests/src/Kernel/TermValidationTest.php | 3 +- .../tests/src/Kernel/TextFormatterTest.php | 3 +- .../text/tests/src/Kernel/TextSummaryTest.php | 3 +- core/modules/tour/src/Tests/TourTestBase.php | 7 +- .../tests/src/Functional/TourTestBase.php | 7 +- .../tests/src/Functional/TrackerTest.php | 5 +- .../src/Functional/UserTokenReplaceTest.php | 2 +- .../src/Tests/ViewResultAssertionTrait.php | 3 +- .../tests/src/Functional/BulkFormTest.php | 5 +- .../tests/src/Functional/DefaultViewsTest.php | 7 +- .../src/Functional/Handler/FieldWebTest.php | 11 +- .../src/Functional/Handler/HandlerAllTest.php | 3 +- .../Functional/Plugin/ArgumentDefaultTest.php | 3 +- .../src/Functional/Plugin/FilterTest.php | 7 +- .../src/Kernel/Handler/AreaEntityTest.php | 7 +- .../src/Kernel/Handler/FieldCounterTest.php | 13 +- .../src/Kernel/Handler/FieldKernelTest.php | 13 +- .../views/tests/src/Kernel/ModuleTest.php | 6 +- .../src/Kernel/Plugin/DisplayExtenderTest.php | 3 +- .../src/Kernel/Plugin/StyleMappingTest.php | 3 +- .../tests/src/Kernel/PluginInstanceTest.php | 5 +- .../tests/src/Kernel/QueryGroupByTest.php | 5 +- .../tests/src/Kernel/TokenReplaceTest.php | 7 +- .../tests/src/Kernel/ViewExecutableTest.php | 5 +- .../tests/src/Kernel/ViewStorageTest.php | 19 +- .../views/tests/src/Kernel/ViewsHooksTest.php | 5 +- .../tests/src/Functional/AnalyzeTest.php | 4 +- .../tests/src/Functional/DefaultViewsTest.php | 3 +- .../src/Functional/DisplayAttachmentTest.php | 3 +- .../tests/src/Functional/StorageTest.php | 3 +- .../views_ui/tests/src/Kernel/TagTest.php | 3 +- .../FunctionalTests/MailCaptureTest.php | 3 +- .../Drupal/KernelTests/AssertContentTrait.php | 2 +- .../Drupal/KernelTests/ConfigFormTestBase.php | 3 +- .../Core/Bootstrap/FormatStringTest.php | 26 +++ .../Core/Config/ConfigCRUDTest.php | 2 +- .../Core/Config/ConfigEntityStorageTest.php | 3 +- .../Core/Database/ConnectionTest.php | 7 +- .../Core/Database/ConnectionUnitTest.php | 5 +- .../Core/Database/InsertLobTest.php | 4 +- .../KernelTests/Core/Database/SchemaTest.php | 13 +- .../Core/Database/SelectComplexTest.php | 5 +- .../Core/Database/TransactionTest.php | 5 +- .../Core/Database/UpdateLobTest.php | 4 +- .../Core/Entity/ContentEntityCloneTest.php | 4 +- .../Entity/EntityAccessControlHandlerTest.php | 3 +- .../KernelTests/Core/Entity/EntityApiTest.php | 15 +- .../Core/Entity/EntityFieldTest.php | 215 +++++++++--------- .../Core/Entity/EntityTranslationTest.php | 96 ++++---- .../KernelTests/Core/File/DirectoryTest.php | 5 +- .../KernelTests/Core/File/MimeTypeTest.php | 8 +- .../KernelTests/Core/File/NameMungingTest.php | 12 +- .../Core/Installer/InstallerLanguageTest.php | 5 +- .../KernelTests/Core/Path/AliasTest.php | 9 +- 195 files changed, 893 insertions(+), 695 deletions(-) create mode 100644 core/tests/Drupal/KernelTests/Core/Bootstrap/FormatStringTest.php diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index ef9090c8d3c..dcfd1dfff39 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -354,17 +354,17 @@ function t($string, array $args = [], array $options = []) { /** * Formats a string for HTML display by replacing variable placeholders. * + * @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. + * Use \Drupal\Component\Render\FormattableMarkup instead. + * + * @see https://www.drupal.org/node/2302363 * @see \Drupal\Component\Render\FormattableMarkup::placeholderFormat() * @see \Drupal\Component\Render\FormattableMarkup * @see t() * @ingroup sanitization - * - * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0. - * Use \Drupal\Component\Render\FormattableMarkup. - * - * @see https://www.drupal.org/node/2302363 */ function format_string($string, array $args) { + @trigger_error("format_string() is deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Component\Render\FormattableMarkup instead. See https://www.drupal.org/node/2302363", E_USER_DEPRECATED); return new FormattableMarkup($string, $args); } diff --git a/core/lib/Drupal/Core/Test/AssertMailTrait.php b/core/lib/Drupal/Core/Test/AssertMailTrait.php index bd020207f01..ab89bdc1669 100644 --- a/core/lib/Drupal/Core/Test/AssertMailTrait.php +++ b/core/lib/Drupal/Core/Test/AssertMailTrait.php @@ -2,6 +2,8 @@ namespace Drupal\Core\Test; +use Drupal\Component\Render\FormattableMarkup; + /** * Provides methods for testing emails sent during test runs. */ @@ -103,7 +105,7 @@ trait AssertMailTrait { } } if (!$message) { - $message = format_string('Expected text found in @field of email message: "@expected".', ['@field' => $field_name, '@expected' => $string]); + $message = new FormattableMarkup('Expected text found in @field of email message: "@expected".', ['@field' => $field_name, '@expected' => $string]); } return $this->assertTrue($string_found, $message, $group); } @@ -134,7 +136,7 @@ trait AssertMailTrait { $mail = end($mails); $regex_found = preg_match("/$regex/", $mail[$field_name]); if (!$message) { - $message = format_string('Expected text found in @field of email message: "@expected".', ['@field' => $field_name, '@expected' => $regex]); + $message = new FormattableMarkup('Expected text found in @field of email message: "@expected".', ['@field' => $field_name, '@expected' => $regex]); } return $this->assertTrue($regex_found, $message, $group); } diff --git a/core/modules/aggregator/src/Tests/AggregatorTestBase.php b/core/modules/aggregator/src/Tests/AggregatorTestBase.php index d603309da1e..1feb188102c 100644 --- a/core/modules/aggregator/src/Tests/AggregatorTestBase.php +++ b/core/modules/aggregator/src/Tests/AggregatorTestBase.php @@ -4,6 +4,7 @@ namespace Drupal\aggregator\Tests; @trigger_error(__NAMESPACE__ . '\AggregatorTestBase is deprecated for removal before Drupal 9.0.0. Use \Drupal\Tests\aggregator\Functional\AggregatorTestBase instead. See https://www.drupal.org/node/2999939', E_USER_DEPRECATED); +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Url; use Drupal\aggregator\Entity\Feed; use Drupal\Component\Utility\Html; @@ -70,7 +71,7 @@ abstract class AggregatorTestBase extends WebTestBase { public function createFeed($feed_url = NULL, array $edit = []) { $edit = $this->getFeedEditArray($feed_url, $edit); $this->drupalPostForm('aggregator/sources/add', $edit, t('Save')); - $this->assertText(t('The feed @name has been added.', ['@name' => $edit['title[0][value]']]), format_string('The feed @name has been added.', ['@name' => $edit['title[0][value]']])); + $this->assertText(t('The feed @name has been added.', ['@name' => $edit['title[0][value]']]), new FormattableMarkup('The feed @name has been added.', ['@name' => $edit['title[0][value]']])); // Verify that the creation message contains a link to a feed. $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'aggregator/sources/']); @@ -181,7 +182,7 @@ abstract class AggregatorTestBase extends WebTestBase { public function updateFeedItems(FeedInterface $feed, $expected_count = NULL) { // First, let's ensure we can get to the rss xml. $this->drupalGet($feed->getUrl()); - $this->assertResponse(200, format_string(':url is reachable.', [':url' => $feed->getUrl()])); + $this->assertResponse(200, new FormattableMarkup(':url is reachable.', [':url' => $feed->getUrl()])); // Attempt to access the update link directly without an access token. $this->drupalGet('admin/config/services/aggregator/update/' . $feed->id()); @@ -200,7 +201,7 @@ abstract class AggregatorTestBase extends WebTestBase { if ($expected_count !== NULL) { $feed->item_count = count($feed->items); - $this->assertEqual($expected_count, $feed->item_count, format_string('Total items in feed equal to the total items in database (@val1 != @val2)', ['@val1' => $expected_count, '@val2' => $feed->item_count])); + $this->assertEqual($expected_count, $feed->item_count, new FormattableMarkup('Total items in feed equal to the total items in database (@val1 != @val2)', ['@val1' => $expected_count, '@val2' => $feed->item_count])); } } diff --git a/core/modules/aggregator/tests/src/Functional/AggregatorAdminTest.php b/core/modules/aggregator/tests/src/Functional/AggregatorAdminTest.php index b3f904c12d8..53c1745a800 100644 --- a/core/modules/aggregator/tests/src/Functional/AggregatorAdminTest.php +++ b/core/modules/aggregator/tests/src/Functional/AggregatorAdminTest.php @@ -2,6 +2,8 @@ namespace Drupal\Tests\aggregator\Functional; +use Drupal\Component\Render\FormattableMarkup; + /** * Tests aggregator admin pages. * @@ -35,7 +37,7 @@ class AggregatorAdminTest extends AggregatorTestBase { $this->assertText(t('The configuration options have been saved.')); foreach ($edit as $name => $value) { - $this->assertFieldByName($name, $value, format_string('"@name" has correct default value.', ['@name' => $name])); + $this->assertFieldByName($name, $value, new FormattableMarkup('"@name" has correct default value.', ['@name' => $name])); } // Check for our test processor settings form. diff --git a/core/modules/aggregator/tests/src/Functional/AggregatorRenderingTest.php b/core/modules/aggregator/tests/src/Functional/AggregatorRenderingTest.php index a5703402ed1..1c58269af56 100644 --- a/core/modules/aggregator/tests/src/Functional/AggregatorRenderingTest.php +++ b/core/modules/aggregator/tests/src/Functional/AggregatorRenderingTest.php @@ -62,7 +62,7 @@ class AggregatorRenderingTest extends AggregatorTestBase { // Find the expected read_more link. $href = $feed->toUrl()->toString(); $links = $this->xpath('//a[@href = :href]', [':href' => $href]); - $this->assert(isset($links[0]), format_string('Link to href %href found.', ['%href' => $href])); + $this->assert(isset($links[0]), new FormattableMarkup('Link to href %href found.', ['%href' => $href])); $cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags'); $cache_tags = explode(' ', $cache_tags_header); $this->assertTrue(in_array('aggregator_feed:' . $feed->id(), $cache_tags)); diff --git a/core/modules/aggregator/tests/src/Functional/AggregatorTestBase.php b/core/modules/aggregator/tests/src/Functional/AggregatorTestBase.php index 5459d6f2ed2..b4c80d0bd3a 100644 --- a/core/modules/aggregator/tests/src/Functional/AggregatorTestBase.php +++ b/core/modules/aggregator/tests/src/Functional/AggregatorTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\aggregator\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Url; use Drupal\aggregator\Entity\Feed; use Drupal\Component\Utility\Html; @@ -63,7 +64,7 @@ abstract class AggregatorTestBase extends BrowserTestBase { public function createFeed($feed_url = NULL, array $edit = []) { $edit = $this->getFeedEditArray($feed_url, $edit); $this->drupalPostForm('aggregator/sources/add', $edit, t('Save')); - $this->assertText(t('The feed @name has been added.', ['@name' => $edit['title[0][value]']]), format_string('The feed @name has been added.', ['@name' => $edit['title[0][value]']])); + $this->assertText(t('The feed @name has been added.', ['@name' => $edit['title[0][value]']]), new FormattableMarkup('The feed @name has been added.', ['@name' => $edit['title[0][value]']])); // Verify that the creation message contains a link to a feed. $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'aggregator/sources/']); @@ -174,7 +175,7 @@ abstract class AggregatorTestBase extends BrowserTestBase { public function updateFeedItems(FeedInterface $feed, $expected_count = NULL) { // First, let's ensure we can get to the rss xml. $this->drupalGet($feed->getUrl()); - $this->assertResponse(200, format_string(':url is reachable.', [':url' => $feed->getUrl()])); + $this->assertResponse(200, new FormattableMarkup(':url is reachable.', [':url' => $feed->getUrl()])); // Attempt to access the update link directly without an access token. $this->drupalGet('admin/config/services/aggregator/update/' . $feed->id()); @@ -193,7 +194,7 @@ abstract class AggregatorTestBase extends BrowserTestBase { if ($expected_count !== NULL) { $feed->item_count = count($feed->items); - $this->assertEqual($expected_count, $feed->item_count, format_string('Total items in feed equal to the total items in database (@val1 != @val2)', ['@val1' => $expected_count, '@val2' => $feed->item_count])); + $this->assertEqual($expected_count, $feed->item_count, new FormattableMarkup('Total items in feed equal to the total items in database (@val1 != @val2)', ['@val1' => $expected_count, '@val2' => $feed->item_count])); } } diff --git a/core/modules/aggregator/tests/src/Functional/FeedParserTest.php b/core/modules/aggregator/tests/src/Functional/FeedParserTest.php index 0d448197050..71e88212cbf 100644 --- a/core/modules/aggregator/tests/src/Functional/FeedParserTest.php +++ b/core/modules/aggregator/tests/src/Functional/FeedParserTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\aggregator\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\aggregator\FeedStorageInterface; use Drupal\Core\Url; use Drupal\aggregator\Entity\Feed; @@ -32,7 +33,7 @@ class FeedParserTest extends AggregatorTestBase { $feed = $this->createFeed($this->getRSS091Sample()); $feed->refreshItems(); $this->drupalGet('aggregator/sources/' . $feed->id()); - $this->assertResponse(200, format_string('Feed %name exists.', ['%name' => $feed->label()])); + $this->assertResponse(200, new FormattableMarkup('Feed %name exists.', ['%name' => $feed->label()])); $this->assertText('First example feed item title'); $this->assertLinkByHref('http://example.com/example-turns-one'); $this->assertText('First example feed item description.'); @@ -55,7 +56,7 @@ class FeedParserTest extends AggregatorTestBase { $feed = $this->createFeed($this->getAtomSample()); $feed->refreshItems(); $this->drupalGet('aggregator/sources/' . $feed->id()); - $this->assertResponse(200, format_string('Feed %name exists.', ['%name' => $feed->label()])); + $this->assertResponse(200, new FormattableMarkup('Feed %name exists.', ['%name' => $feed->label()])); $this->assertText('Atom-Powered Robots Run Amok'); $this->assertLinkByHref('http://example.org/2003/12/13/atom03'); $this->assertText('Some text.'); @@ -79,7 +80,7 @@ class FeedParserTest extends AggregatorTestBase { $feed = $this->createFeed($this->getHtmlEntitiesSample()); $feed->refreshItems(); $this->drupalGet('aggregator/sources/' . $feed->id()); - $this->assertResponse(200, format_string('Feed %name exists.', ['%name' => $feed->label()])); + $this->assertResponse(200, new FormattableMarkup('Feed %name exists.', ['%name' => $feed->label()])); $this->assertRaw("Quote" Amp&"); } diff --git a/core/modules/aggregator/tests/src/Functional/UpdateFeedItemTest.php b/core/modules/aggregator/tests/src/Functional/UpdateFeedItemTest.php index fd2a742443c..2e4015e8664 100644 --- a/core/modules/aggregator/tests/src/Functional/UpdateFeedItemTest.php +++ b/core/modules/aggregator/tests/src/Functional/UpdateFeedItemTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\aggregator\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\aggregator\Entity\Feed; use Drupal\aggregator\Entity\Item; @@ -38,7 +39,7 @@ class UpdateFeedItemTest extends AggregatorTestBase { $this->assertResponse(200); $this->drupalPostForm('aggregator/sources/add', $edit, t('Save')); - $this->assertText(t('The feed @name has been added.', ['@name' => $edit['title[0][value]']]), format_string('The feed @name has been added.', ['@name' => $edit['title[0][value]']])); + $this->assertText(t('The feed @name has been added.', ['@name' => $edit['title[0][value]']]), new FormattableMarkup('The feed @name has been added.', ['@name' => $edit['title[0][value]']])); // Verify that the creation message contains a link to a feed. $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'aggregator/sources/']); @@ -62,7 +63,7 @@ class UpdateFeedItemTest extends AggregatorTestBase { $feed->refreshItems(); $after = Item::load(array_values($iids)[0])->getPostedTime(); - $this->assertTrue($before === $after, format_string('Publish timestamp of feed item was not updated (@before === @after)', ['@before' => $before, '@after' => $after])); + $this->assertTrue($before === $after, new FormattableMarkup('Publish timestamp of feed item was not updated (@before === @after)', ['@before' => $before, '@after' => $after])); // Make sure updating items works even after uninstalling a module // that provides the selected plugins. diff --git a/core/modules/aggregator/tests/src/Functional/UpdateFeedTest.php b/core/modules/aggregator/tests/src/Functional/UpdateFeedTest.php index 408da55337a..62e5c4227b4 100644 --- a/core/modules/aggregator/tests/src/Functional/UpdateFeedTest.php +++ b/core/modules/aggregator/tests/src/Functional/UpdateFeedTest.php @@ -2,6 +2,8 @@ namespace Drupal\Tests\aggregator\Functional; +use Drupal\Component\Render\FormattableMarkup; + /** * Update feed test. * @@ -25,7 +27,7 @@ class UpdateFeedTest extends AggregatorTestBase { $edit[$same_field] = $feed->{$same_field}->value; } $this->drupalPostForm('aggregator/sources/' . $feed->id() . '/configure', $edit, t('Save')); - $this->assertText(t('The feed @name has been updated.', ['@name' => $edit['title[0][value]']]), format_string('The feed %name has been updated.', ['%name' => $edit['title[0][value]']])); + $this->assertText(t('The feed @name has been updated.', ['@name' => $edit['title[0][value]']]), new FormattableMarkup('The feed %name has been updated.', ['%name' => $edit['title[0][value]']])); // Verify that the creation message contains a link to a feed. $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'aggregator/sources/']); diff --git a/core/modules/block/tests/src/Functional/BlockTest.php b/core/modules/block/tests/src/Functional/BlockTest.php index f54f7a6831f..3ee8203984d 100644 --- a/core/modules/block/tests/src/Functional/BlockTest.php +++ b/core/modules/block/tests/src/Functional/BlockTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\block\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Html; use Drupal\block\Entity\Block; use Drupal\Core\Url; @@ -336,7 +337,7 @@ class BlockTest extends BlockTestBase { $this->drupalPostForm('admin/structure/block', $edit, t('Save blocks')); // Confirm that the block was moved to the proper region. - $this->assertText(t('The block settings have been updated.'), format_string('Block successfully moved to %region_name region.', ['%region_name' => $region])); + $this->assertText(t('The block settings have been updated.'), new FormattableMarkup('Block successfully moved to %region_name region.', ['%region_name' => $region])); // Confirm that the block is being displayed. $this->drupalGet(''); diff --git a/core/modules/block/tests/src/Functional/Views/DisplayBlockTest.php b/core/modules/block/tests/src/Functional/Views/DisplayBlockTest.php index 7b5d5e45ddc..17658e462f0 100644 --- a/core/modules/block/tests/src/Functional/Views/DisplayBlockTest.php +++ b/core/modules/block/tests/src/Functional/Views/DisplayBlockTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\block\Functional\Views; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Serialization\Json; use Drupal\Component\Utility\Crypt; use Drupal\Core\Site\Settings; @@ -366,8 +367,8 @@ class DisplayBlockTest extends ViewTestBase { $cached_id = 'block:block=' . $cached_block->id() . ':langcode=en|entity.view.edit_form:view=test_view_block:location=block&name=test_view_block&display_id=block_1&langcode=en'; $cached_id_token = Crypt::hmacBase64($cached_id, Settings::getHashSalt() . $this->container->get('private_key')->get()); // @see \Drupal\contextual\Tests\ContextualDynamicContextTest:assertContextualLinkPlaceHolder() - $this->assertRaw('<div' . new Attribute(['data-contextual-id' => $id, 'data-contextual-token' => $id_token]) . '></div>', format_string('Contextual link placeholder with id @id exists.', ['@id' => $id])); - $this->assertRaw('<div' . new Attribute(['data-contextual-id' => $cached_id, 'data-contextual-token' => $cached_id_token]) . '></div>', format_string('Contextual link placeholder with id @id exists.', ['@id' => $cached_id])); + $this->assertRaw('<div' . new Attribute(['data-contextual-id' => $id, 'data-contextual-token' => $id_token]) . '></div>', new FormattableMarkup('Contextual link placeholder with id @id exists.', ['@id' => $id])); + $this->assertRaw('<div' . new Attribute(['data-contextual-id' => $cached_id, 'data-contextual-token' => $cached_id_token]) . '></div>', new FormattableMarkup('Contextual link placeholder with id @id exists.', ['@id' => $cached_id])); // Get server-rendered contextual links. // @see \Drupal\contextual\Tests\ContextualDynamicContextTest:renderContextualLinks() diff --git a/core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php b/core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php index 361bade5f83..a1b5f97a77b 100644 --- a/core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php +++ b/core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\block_content\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\block_content\Entity\BlockContent; use Drupal\Core\Database\Database; @@ -53,7 +54,7 @@ class BlockContentCreationTest extends BlockContentTestBase { $this->drupalPostForm('block/add/basic', $edit, t('Save')); // Check that the Basic block has been created. - $this->assertRaw(format_string('@block %name has been created.', [ + $this->assertRaw(new FormattableMarkup('@block %name has been created.', [ '@block' => 'basic', '%name' => $edit['info[0][value]'], ]), 'Basic block created.'); @@ -73,7 +74,7 @@ class BlockContentCreationTest extends BlockContentTestBase { $this->drupalPostForm('block/add/basic', $edit, t('Save')); // Check that the Basic block has been created. - $this->assertRaw(format_string('A custom block with block description %value already exists.', [ + $this->assertRaw(new FormattableMarkup('A custom block with block description %value already exists.', [ '%value' => $edit['info[0][value]'], ])); $this->assertResponse(200); @@ -102,7 +103,7 @@ class BlockContentCreationTest extends BlockContentTestBase { $this->drupalPostForm('block/add/basic', $edit, t('Save')); // Check that the Basic block has been created. - $this->assertRaw(format_string('@block %name has been created.', [ + $this->assertRaw(new FormattableMarkup('@block %name has been created.', [ '@block' => 'basic', '%name' => $edit['info[0][value]'], ]), 'Basic block created.'); @@ -155,7 +156,7 @@ class BlockContentCreationTest extends BlockContentTestBase { $this->drupalPostForm('block/add/basic', $edit, t('Save')); // Check that the Basic block has been created. - $this->assertRaw(format_string('A custom block with block description %value already exists.', [ + $this->assertRaw(new FormattableMarkup('A custom block with block description %value already exists.', [ '%value' => $edit['info[0][value]'], ])); $this->assertResponse(200); @@ -175,7 +176,7 @@ class BlockContentCreationTest extends BlockContentTestBase { $this->drupalPostForm('block/add', $edit, t('Save')); // Check that the block has been created and that it is a basic block. - $this->assertRaw(format_string('@block %name has been created.', [ + $this->assertRaw(new FormattableMarkup('@block %name has been created.', [ '@block' => 'basic', '%name' => $edit['info[0][value]'], ]), 'Basic block created.'); diff --git a/core/modules/block_content/tests/src/Functional/BlockContentRevisionsTest.php b/core/modules/block_content/tests/src/Functional/BlockContentRevisionsTest.php index 3218e7fc0fe..89708bb73aa 100644 --- a/core/modules/block_content/tests/src/Functional/BlockContentRevisionsTest.php +++ b/core/modules/block_content/tests/src/Functional/BlockContentRevisionsTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\block_content\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\block_content\Entity\BlockContent; use Drupal\user\Entity\User; use Drupal\user\UserInterface; @@ -74,7 +75,7 @@ class BlockContentRevisionsTest extends BlockContentTestBase { ->getStorage('block_content') ->loadRevision($revision_id); // Verify revision log is the same. - $this->assertEqual($loaded->getRevisionLogMessage(), $logs[$delta], format_string('Correct log message found for revision @revision', [ + $this->assertEqual($loaded->getRevisionLogMessage(), $logs[$delta], new FormattableMarkup('Correct log message found for revision @revision', [ '@revision' => $loaded->getRevisionId(), ])); if ($delta > 0) { diff --git a/core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php b/core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php index d1e662008d8..e5b8660b3dd 100644 --- a/core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php +++ b/core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\block_content\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\block_content\Entity\BlockContentType; use Drupal\Component\Utility\Html; use Drupal\Core\Url; @@ -115,7 +116,7 @@ class BlockContentTypeTest extends BlockContentTestBase { 'label' => 'Bar', ]; $this->drupalGet('admin/structure/block/block-content/manage/basic'); - $this->assertTitle(format_string('Edit @type custom block type | Drupal', ['@type' => 'basic'])); + $this->assertTitle(new FormattableMarkup('Edit @type custom block type | Drupal', ['@type' => 'basic'])); $this->drupalPostForm(NULL, $edit, t('Save')); $front_page_path = Url::fromRoute('<front>')->toString(); $this->assertBreadcrumb('admin/structure/block/block-content/manage/basic/fields', [ diff --git a/core/modules/block_content/tests/src/Functional/BlockContentValidationTest.php b/core/modules/block_content/tests/src/Functional/BlockContentValidationTest.php index bfa84082c1c..7baaffd4074 100644 --- a/core/modules/block_content/tests/src/Functional/BlockContentValidationTest.php +++ b/core/modules/block_content/tests/src/Functional/BlockContentValidationTest.php @@ -2,6 +2,8 @@ namespace Drupal\Tests\block_content\Functional; +use Drupal\Component\Render\FormattableMarkup; + /** * Tests block content validation constraints. * @@ -32,7 +34,7 @@ class BlockContentValidationTest extends BlockContentTestBase { // Make sure the violation is on the info property $this->assertEqual($violations[0]->getPropertyPath(), 'info'); // Make sure the message is correct. - $this->assertEqual($violations[0]->getMessage(), format_string('A custom block with block description %value already exists.', [ + $this->assertEqual($violations[0]->getMessage(), new FormattableMarkup('A custom block with block description %value already exists.', [ '%value' => $block->label(), ])); } diff --git a/core/modules/block_content/tests/src/Functional/PageEditTest.php b/core/modules/block_content/tests/src/Functional/PageEditTest.php index e751c70b097..3edd7108e91 100644 --- a/core/modules/block_content/tests/src/Functional/PageEditTest.php +++ b/core/modules/block_content/tests/src/Functional/PageEditTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\block_content\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\block_content\Entity\BlockContent; /** @@ -64,7 +65,7 @@ class PageEditTest extends BlockContentTestBase { // Test deleting the block. $this->drupalGet("block/" . $revised_block->id()); $this->clickLink(t('Delete')); - $this->assertText(format_string('Are you sure you want to delete the custom block @label?', ['@label' => $revised_block->label()])); + $this->assertText(new FormattableMarkup('Are you sure you want to delete the custom block @label?', ['@label' => $revised_block->label()])); } } diff --git a/core/modules/book/tests/src/Functional/BookTest.php b/core/modules/book/tests/src/Functional/BookTest.php index 38fdf54ac5b..0361d49a61e 100644 --- a/core/modules/book/tests/src/Functional/BookTest.php +++ b/core/modules/book/tests/src/Functional/BookTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\book\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Cache\Cache; use Drupal\Tests\BrowserTestBase; use Drupal\user\RoleInterface; @@ -247,7 +248,7 @@ class BookTest extends BrowserTestBase { $nodes = $this->createBook(); $this->drupalGet('<front>'); $this->assertText($block->label(), 'Book navigation block is displayed.'); - $this->assertText($this->book->label(), format_string('Link to book root (@title) is displayed.', ['@title' => $nodes[0]->label()])); + $this->assertText($this->book->label(), new FormattableMarkup('Link to book root (@title) is displayed.', ['@title' => $nodes[0]->label()])); $this->assertNoText($nodes[0]->label(), 'No links to individual book pages are displayed.'); } diff --git a/core/modules/book/tests/src/Functional/BookTestTrait.php b/core/modules/book/tests/src/Functional/BookTestTrait.php index 67520c4851f..3da6b865a7e 100644 --- a/core/modules/book/tests/src/Functional/BookTestTrait.php +++ b/core/modules/book/tests/src/Functional/BookTestTrait.php @@ -94,10 +94,10 @@ trait BookTestTrait { // Check outline structure. if ($nodes !== NULL) { - $this->assertPattern($this->generateOutlinePattern($nodes), format_string('Node @number outline confirmed.', ['@number' => $number])); + $this->assertPattern($this->generateOutlinePattern($nodes), new FormattableMarkup('Node @number outline confirmed.', ['@number' => $number])); } else { - $this->pass(format_string('Node %number does not have outline.', ['%number' => $number])); + $this->pass(new FormattableMarkup('Node %number does not have outline.', ['%number' => $number])); } // Check previous, up, and next links. diff --git a/core/modules/comment/src/Tests/CommentTestBase.php b/core/modules/comment/src/Tests/CommentTestBase.php index 4c239816047..0c6cc1b5ced 100644 --- a/core/modules/comment/src/Tests/CommentTestBase.php +++ b/core/modules/comment/src/Tests/CommentTestBase.php @@ -4,6 +4,7 @@ namespace Drupal\comment\Tests; @trigger_error(__NAMESPACE__ . '\CommentTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Use \Drupal\Tests\comment\Functional\CommentTestBase instead. See http://www.drupal.org/node/2908490', E_USER_DEPRECATED); +use Drupal\Component\Render\FormattableMarkup; use Drupal\comment\Entity\CommentType; use Drupal\comment\Entity\Comment; use Drupal\comment\CommentInterface; @@ -272,7 +273,7 @@ abstract class CommentTestBase extends WebTestBase { $mode_text = 'required'; break; } - $this->setCommentSettings('preview', $mode, format_string('Comment preview @mode_text.', ['@mode_text' => $mode_text]), $field_name); + $this->setCommentSettings('preview', $mode, new FormattableMarkup('Comment preview @mode_text.', ['@mode_text' => $mode_text]), $field_name); } /** @@ -299,7 +300,7 @@ abstract class CommentTestBase extends WebTestBase { * - 2: Contact information required. */ public function setCommentAnonymous($level) { - $this->setCommentSettings('anonymous', $level, format_string('Anonymous commenting set to level @level.', ['@level' => $level])); + $this->setCommentSettings('anonymous', $level, new FormattableMarkup('Anonymous commenting set to level @level.', ['@level' => $level])); } /** @@ -312,7 +313,7 @@ abstract class CommentTestBase extends WebTestBase { * Defaults to 'comment'. */ public function setCommentsPerPage($number, $field_name = 'comment') { - $this->setCommentSettings('per_page', $number, format_string('Number of comments per page set to @number.', ['@number' => $number]), $field_name); + $this->setCommentSettings('per_page', $number, new FormattableMarkup('Number of comments per page set to @number.', ['@number' => $number]), $field_name); } /** @@ -364,10 +365,10 @@ abstract class CommentTestBase extends WebTestBase { if ($operation == 'delete') { $this->drupalPostForm(NULL, [], t('Delete')); - $this->assertRaw(\Drupal::translation()->formatPlural(1, 'Deleted 1 comment.', 'Deleted @count comments.'), format_string('Operation "@operation" was performed on comment.', ['@operation' => $operation])); + $this->assertRaw(\Drupal::translation()->formatPlural(1, 'Deleted 1 comment.', 'Deleted @count comments.'), new FormattableMarkup('Operation "@operation" was performed on comment.', ['@operation' => $operation])); } else { - $this->assertText(t('The update has been performed.'), format_string('Operation "@operation" was performed on comment.', ['@operation' => $operation])); + $this->assertText(t('The update has been performed.'), new FormattableMarkup('Operation "@operation" was performed on comment.', ['@operation' => $operation])); } } diff --git a/core/modules/comment/tests/src/Functional/CommentFieldsTest.php b/core/modules/comment/tests/src/Functional/CommentFieldsTest.php index 1cb6382f127..23ec524f330 100644 --- a/core/modules/comment/tests/src/Functional/CommentFieldsTest.php +++ b/core/modules/comment/tests/src/Functional/CommentFieldsTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\comment\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldConfig; @@ -51,7 +52,7 @@ class CommentFieldsTest extends CommentTestBase { $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); $this->assertTrue($field_storage, 'The comment_body field exists'); $field = FieldConfig::loadByName('comment', 'comment', 'comment_body'); - $this->assertTrue(isset($field), format_string('The comment_body field is present for comments on type @type', ['@type' => $type_name])); + $this->assertTrue(isset($field), new FormattableMarkup('The comment_body field is present for comments on type @type', ['@type' => $type_name])); // Test adding a field that defaults to CommentItemInterface::CLOSED. $this->addDefaultCommentField('node', 'test_node_type', 'who_likes_ponies', CommentItemInterface::CLOSED, 'who_likes_ponies'); diff --git a/core/modules/comment/tests/src/Functional/CommentLanguageTest.php b/core/modules/comment/tests/src/Functional/CommentLanguageTest.php index ce9a9abb043..7ed1b428517 100644 --- a/core/modules/comment/tests/src/Functional/CommentLanguageTest.php +++ b/core/modules/comment/tests/src/Functional/CommentLanguageTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\comment\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\comment\Entity\Comment; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\comment\Tests\CommentTestTrait; @@ -119,7 +120,7 @@ class CommentLanguageTest extends BrowserTestBase { ->execute(); $comment = Comment::load(reset($cids)); $args = ['%node_language' => $node_langcode, '%comment_language' => $comment->langcode->value, '%langcode' => $langcode]; - $this->assertEqual($comment->langcode->value, $langcode, format_string('The comment posted with content language %langcode and belonging to the node with language %node_language has language %comment_language', $args)); + $this->assertEqual($comment->langcode->value, $langcode, new FormattableMarkup('The comment posted with content language %langcode and belonging to the node with language %node_language has language %comment_language', $args)); $this->assertEqual($comment->comment_body->value, $comment_values[$node_langcode][$langcode], 'Comment body correctly stored.'); } } diff --git a/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php b/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php index 505dbf2743c..ceae6f33668 100644 --- a/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php +++ b/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\comment\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\comment\CommentInterface; use Drupal\comment\Entity\Comment; use Drupal\comment\Entity\CommentType; @@ -226,10 +227,10 @@ class CommentNonNodeTest extends BrowserTestBase { if ($operation == 'delete') { $this->drupalPostForm(NULL, [], t('Delete')); - $this->assertRaw(\Drupal::translation()->formatPlural(1, 'Deleted 1 comment.', 'Deleted @count comments.'), format_string('Operation "@operation" was performed on comment.', ['@operation' => $operation])); + $this->assertRaw(\Drupal::translation()->formatPlural(1, 'Deleted 1 comment.', 'Deleted @count comments.'), new FormattableMarkup('Operation "@operation" was performed on comment.', ['@operation' => $operation])); } else { - $this->assertText(t('The update has been performed.'), format_string('Operation "@operation" was performed on comment.', ['@operation' => $operation])); + $this->assertText(t('The update has been performed.'), new FormattableMarkup('Operation "@operation" was performed on comment.', ['@operation' => $operation])); } } diff --git a/core/modules/comment/tests/src/Functional/CommentPagerTest.php b/core/modules/comment/tests/src/Functional/CommentPagerTest.php index 3c4d46b1c11..56adbf7a81d 100644 --- a/core/modules/comment/tests/src/Functional/CommentPagerTest.php +++ b/core/modules/comment/tests/src/Functional/CommentPagerTest.php @@ -219,7 +219,7 @@ class CommentPagerTest extends CommentTestBase { foreach ($comment_anchors as $anchor) { $result_order[] = substr($anchor->getAttribute('id'), 8); } - return $this->assertEqual($expected_cids, $result_order, format_string('Comment order: expected @expected, returned @returned.', ['@expected' => implode(',', $expected_cids), '@returned' => implode(',', $result_order)])); + return $this->assertEqual($expected_cids, $result_order, new FormattableMarkup('Comment order: expected @expected, returned @returned.', ['@expected' => implode(',', $expected_cids), '@returned' => implode(',', $result_order)])); } /** @@ -285,7 +285,7 @@ class CommentPagerTest extends CommentTestBase { foreach ($expected_pages as $new_replies => $expected_page) { $returned_page = \Drupal::entityTypeManager()->getStorage('comment') ->getNewCommentPageNumber($node->get('comment')->comment_count, $new_replies, $node, 'comment'); - $this->assertIdentical($expected_page, $returned_page, format_string('Flat mode, @new replies: expected page @expected, returned page @returned.', ['@new' => $new_replies, '@expected' => $expected_page, '@returned' => $returned_page])); + $this->assertIdentical($expected_page, $returned_page, new FormattableMarkup('Flat mode, @new replies: expected page @expected, returned page @returned.', ['@new' => $new_replies, '@expected' => $expected_page, '@returned' => $returned_page])); } $this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Switched to threaded mode.'); @@ -310,7 +310,7 @@ class CommentPagerTest extends CommentTestBase { foreach ($expected_pages as $new_replies => $expected_page) { $returned_page = \Drupal::entityTypeManager()->getStorage('comment') ->getNewCommentPageNumber($node->get('comment')->comment_count, $new_replies, $node, 'comment'); - $this->assertEqual($expected_page, $returned_page, format_string('Threaded mode, @new replies: expected page @expected, returned page @returned.', ['@new' => $new_replies, '@expected' => $expected_page, '@returned' => $returned_page])); + $this->assertEqual($expected_page, $returned_page, new FormattableMarkup('Threaded mode, @new replies: expected page @expected, returned page @returned.', ['@new' => $new_replies, '@expected' => $expected_page, '@returned' => $returned_page])); } } diff --git a/core/modules/comment/tests/src/Functional/CommentTestBase.php b/core/modules/comment/tests/src/Functional/CommentTestBase.php index e9907b3bea1..531c7076be1 100644 --- a/core/modules/comment/tests/src/Functional/CommentTestBase.php +++ b/core/modules/comment/tests/src/Functional/CommentTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\comment\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\comment\Entity\CommentType; use Drupal\comment\Entity\Comment; use Drupal\comment\CommentInterface; @@ -268,7 +269,7 @@ abstract class CommentTestBase extends BrowserTestBase { $mode_text = 'required'; break; } - $this->setCommentSettings('preview', $mode, format_string('Comment preview @mode_text.', ['@mode_text' => $mode_text]), $field_name); + $this->setCommentSettings('preview', $mode, new FormattableMarkup('Comment preview @mode_text.', ['@mode_text' => $mode_text]), $field_name); } /** @@ -295,7 +296,7 @@ abstract class CommentTestBase extends BrowserTestBase { * - 2: Contact information required. */ public function setCommentAnonymous($level) { - $this->setCommentSettings('anonymous', $level, format_string('Anonymous commenting set to level @level.', ['@level' => $level])); + $this->setCommentSettings('anonymous', $level, new FormattableMarkup('Anonymous commenting set to level @level.', ['@level' => $level])); } /** @@ -308,7 +309,7 @@ abstract class CommentTestBase extends BrowserTestBase { * Defaults to 'comment'. */ public function setCommentsPerPage($number, $field_name = 'comment') { - $this->setCommentSettings('per_page', $number, format_string('Number of comments per page set to @number.', ['@number' => $number]), $field_name); + $this->setCommentSettings('per_page', $number, new FormattableMarkup('Number of comments per page set to @number.', ['@number' => $number]), $field_name); } /** @@ -360,10 +361,10 @@ abstract class CommentTestBase extends BrowserTestBase { if ($operation == 'delete') { $this->drupalPostForm(NULL, [], t('Delete')); - $this->assertRaw(\Drupal::translation()->formatPlural(1, 'Deleted 1 comment.', 'Deleted @count comments.'), format_string('Operation "@operation" was performed on comment.', ['@operation' => $operation])); + $this->assertRaw(\Drupal::translation()->formatPlural(1, 'Deleted 1 comment.', 'Deleted @count comments.'), new FormattableMarkup('Operation "@operation" was performed on comment.', ['@operation' => $operation])); } else { - $this->assertText(t('The update has been performed.'), format_string('Operation "@operation" was performed on comment.', ['@operation' => $operation])); + $this->assertText(t('The update has been performed.'), new FormattableMarkup('Operation "@operation" was performed on comment.', ['@operation' => $operation])); } } diff --git a/core/modules/comment/tests/src/Functional/CommentThreadingTest.php b/core/modules/comment/tests/src/Functional/CommentThreadingTest.php index ee6aed7d4c7..2e2b6868f6e 100644 --- a/core/modules/comment/tests/src/Functional/CommentThreadingTest.php +++ b/core/modules/comment/tests/src/Functional/CommentThreadingTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\comment\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\comment\CommentManagerInterface; /** @@ -137,7 +138,7 @@ class CommentThreadingTest extends CommentTestBase { // </article> $pattern = "//article[@id='comment-$cid']//p[contains(@class, 'parent')]//a[contains(@href, 'comment-$pid')]"; - $this->assertFieldByXpath($pattern, NULL, format_string( + $this->assertFieldByXpath($pattern, NULL, new FormattableMarkup( 'Comment %cid has a link to parent %pid.', [ '%cid' => $cid, @@ -160,7 +161,7 @@ class CommentThreadingTest extends CommentTestBase { // </article> $pattern = "//article[@id='comment-$cid']//p[contains(@class, 'parent')]"; - $this->assertNoFieldByXpath($pattern, NULL, format_string( + $this->assertNoFieldByXpath($pattern, NULL, new FormattableMarkup( 'Comment %cid does not have a link to a parent.', [ '%cid' => $cid, diff --git a/core/modules/comment/tests/src/Functional/CommentTokenReplaceTest.php b/core/modules/comment/tests/src/Functional/CommentTokenReplaceTest.php index cc0cc1df9cb..32670f5f197 100644 --- a/core/modules/comment/tests/src/Functional/CommentTokenReplaceTest.php +++ b/core/modules/comment/tests/src/Functional/CommentTokenReplaceTest.php @@ -143,7 +143,7 @@ class CommentTokenReplaceTest extends CommentTestBase { $comment->setOwnerId(0)->setAuthorName($author_name); $input = '[comment:author]'; $output = $token_service->replace($input, ['comment' => $comment], ['langcode' => $language_interface->getId()]); - $this->assertEqual($output, Html::escape($author_name), format_string('Comment author token %token replaced.', ['%token' => $input])); + $this->assertEqual($output, Html::escape($author_name), new FormattableMarkup('Comment author token %token replaced.', ['%token' => $input])); // Add comment field to user and term entities. $this->addDefaultCommentField('user', 'user', 'comment', CommentItemInterface::OPEN, 'comment_user'); $this->addDefaultCommentField('taxonomy_term', 'tags', 'comment', CommentItemInterface::OPEN, 'comment_term'); @@ -181,7 +181,7 @@ class CommentTokenReplaceTest extends CommentTestBase { foreach ($tests as $input => $expected) { $output = $token_service->replace($input, ['entity' => $node, 'node' => $node, 'user' => $user, 'term' => $term], ['langcode' => $language_interface->getId()]); - $this->assertEqual($output, $expected, format_string('Comment token %token replaced.', ['%token' => $input])); + $this->assertEqual($output, $expected, new FormattableMarkup('Comment token %token replaced.', ['%token' => $input])); } } diff --git a/core/modules/comment/tests/src/Functional/Views/DefaultViewRecentCommentsTest.php b/core/modules/comment/tests/src/Functional/Views/DefaultViewRecentCommentsTest.php index 4085f4f47bf..9ba4d85e77d 100644 --- a/core/modules/comment/tests/src/Functional/Views/DefaultViewRecentCommentsTest.php +++ b/core/modules/comment/tests/src/Functional/Views/DefaultViewRecentCommentsTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\comment\Functional\Views; +use Drupal\Component\Render\FormattableMarkup; use Drupal\comment\CommentInterface; use Drupal\comment\Entity\Comment; use Drupal\comment\Tests\CommentTestTrait; @@ -131,7 +132,7 @@ class DefaultViewRecentCommentsTest extends ViewTestBase { // Check the number of results given by the display is the expected. $this->assertEqual(count($view->result), $this->blockDisplayResults, - format_string('There are exactly @results comments. Expected @expected', + new FormattableMarkup('There are exactly @results comments. Expected @expected', ['@results' => count($view->result), '@expected' => $this->blockDisplayResults] ) ); diff --git a/core/modules/config/tests/config_test/src/ConfigTestForm.php b/core/modules/config/tests/config_test/src/ConfigTestForm.php index 163359613d0..49cc1958322 100644 --- a/core/modules/config/tests/config_test/src/ConfigTestForm.php +++ b/core/modules/config/tests/config_test/src/ConfigTestForm.php @@ -2,6 +2,7 @@ namespace Drupal\config_test; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Entity\EntityForm; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; @@ -138,10 +139,10 @@ class ConfigTestForm extends EntityForm { $status = $entity->save(); if ($status === SAVED_UPDATED) { - $this->messenger()->addStatus(format_string('%label configuration has been updated.', ['%label' => $entity->label()])); + $this->messenger()->addStatus(new FormattableMarkup('%label configuration has been updated.', ['%label' => $entity->label()])); } else { - $this->messenger()->addStatus(format_string('%label configuration has been created.', ['%label' => $entity->label()])); + $this->messenger()->addStatus(new FormattableMarkup('%label configuration has been created.', ['%label' => $entity->label()])); } $form_state->setRedirectUrl($this->entity->toUrl('collection')); diff --git a/core/modules/config/tests/src/Functional/ConfigEntityTest.php b/core/modules/config/tests/src/Functional/ConfigEntityTest.php index 2b72ef51178..649085c3ffe 100644 --- a/core/modules/config/tests/src/Functional/ConfigEntityTest.php +++ b/core/modules/config/tests/src/Functional/ConfigEntityTest.php @@ -238,9 +238,9 @@ class ConfigEntityTest extends BrowserTestBase { $label1 = $this->randomMachineName(); $label2 = $this->randomMachineName(); $label3 = $this->randomMachineName(); - $message_insert = format_string('%label configuration has been created.', ['%label' => $label1]); - $message_update = format_string('%label configuration has been updated.', ['%label' => $label2]); - $message_delete = format_string('The test configuration %label has been deleted.', ['%label' => $label2]); + $message_insert = new FormattableMarkup('%label configuration has been created.', ['%label' => $label1]); + $message_update = new FormattableMarkup('%label configuration has been updated.', ['%label' => $label2]); + $message_delete = new FormattableMarkup('The test configuration %label has been deleted.', ['%label' => $label2]); // Create a configuration entity. $edit = [ @@ -311,7 +311,7 @@ class ConfigEntityTest extends BrowserTestBase { ]; $this->drupalPostForm('admin/structure/config_test/add', $edit, 'Save'); $this->assertResponse(200); - $message_insert = format_string('%label configuration has been created.', ['%label' => $edit['label']]); + $message_insert = new FormattableMarkup('%label configuration has been created.', ['%label' => $edit['label']]); $this->assertRaw($message_insert); $this->assertLinkByHref('admin/structure/config_test/manage/0'); $this->assertLinkByHref('admin/structure/config_test/manage/0/delete'); diff --git a/core/modules/config/tests/src/Functional/ConfigImportUITest.php b/core/modules/config/tests/src/Functional/ConfigImportUITest.php index b3b125c2219..e295510b8ff 100644 --- a/core/modules/config/tests/src/Functional/ConfigImportUITest.php +++ b/core/modules/config/tests/src/Functional/ConfigImportUITest.php @@ -292,7 +292,7 @@ class ConfigImportUITest extends BrowserTestBase { // Load the diff UI and verify that the diff reflects the change. $this->drupalGet('admin/config/development/configuration/sync/diff/' . $config_name); $this->assertNoRaw('&nbsp;'); - $this->assertTitle(format_string('View changes of @config_name | Drupal', ['@config_name' => $config_name])); + $this->assertTitle(new FormattableMarkup('View changes of @config_name | Drupal', ['@config_name' => $config_name])); // The following assertions do not use $this::assertEscaped() because // \Drupal\Component\Diff\DiffFormatter adds markup that signifies what has @@ -453,11 +453,11 @@ class ConfigImportUITest extends BrowserTestBase { $this->drupalGet('admin/config/development/configuration'); // The node type, body field and entity displays will be scheduled for // removal. - $this->assertText(format_string('node.type.@type', ['@type' => $node_type->id()])); - $this->assertText(format_string('field.field.node.@type.body', ['@type' => $node_type->id()])); - $this->assertText(format_string('core.entity_view_display.node.@type.teaser', ['@type' => $node_type->id()])); - $this->assertText(format_string('core.entity_view_display.node.@type.default', ['@type' => $node_type->id()])); - $this->assertText(format_string('core.entity_form_display.node.@type.default', ['@type' => $node_type->id()])); + $this->assertText(new FormattableMarkup('node.type.@type', ['@type' => $node_type->id()])); + $this->assertText(new FormattableMarkup('field.field.node.@type.body', ['@type' => $node_type->id()])); + $this->assertText(new FormattableMarkup('core.entity_view_display.node.@type.teaser', ['@type' => $node_type->id()])); + $this->assertText(new FormattableMarkup('core.entity_view_display.node.@type.default', ['@type' => $node_type->id()])); + $this->assertText(new FormattableMarkup('core.entity_form_display.node.@type.default', ['@type' => $node_type->id()])); // Attempt to import configuration and verify that an error message appears // and the node type, body field and entity displays are still scheduled for @@ -465,22 +465,22 @@ class ConfigImportUITest extends BrowserTestBase { $this->drupalPostForm(NULL, [], t('Import all')); $validation_message = t('Entities exist of type %entity_type and %bundle_label %bundle. These entities need to be deleted before importing.', ['%entity_type' => $node->getEntityType()->getLabel(), '%bundle_label' => $node->getEntityType()->getBundleLabel(), '%bundle' => $node_type->label()]); $this->assertRaw($validation_message); - $this->assertText(format_string('node.type.@type', ['@type' => $node_type->id()])); - $this->assertText(format_string('field.field.node.@type.body', ['@type' => $node_type->id()])); - $this->assertText(format_string('core.entity_view_display.node.@type.teaser', ['@type' => $node_type->id()])); - $this->assertText(format_string('core.entity_view_display.node.@type.default', ['@type' => $node_type->id()])); - $this->assertText(format_string('core.entity_form_display.node.@type.default', ['@type' => $node_type->id()])); + $this->assertText(new FormattableMarkup('node.type.@type', ['@type' => $node_type->id()])); + $this->assertText(new FormattableMarkup('field.field.node.@type.body', ['@type' => $node_type->id()])); + $this->assertText(new FormattableMarkup('core.entity_view_display.node.@type.teaser', ['@type' => $node_type->id()])); + $this->assertText(new FormattableMarkup('core.entity_view_display.node.@type.default', ['@type' => $node_type->id()])); + $this->assertText(new FormattableMarkup('core.entity_form_display.node.@type.default', ['@type' => $node_type->id()])); // Delete the node and try to import again. $node->delete(); $this->drupalPostForm(NULL, [], t('Import all')); $this->assertNoRaw($validation_message); $this->assertText(t('There are no configuration changes to import.')); - $this->assertNoText(format_string('node.type.@type', ['@type' => $node_type->id()])); - $this->assertNoText(format_string('field.field.node.@type.body', ['@type' => $node_type->id()])); - $this->assertNoText(format_string('core.entity_view_display.node.@type.teaser', ['@type' => $node_type->id()])); - $this->assertNoText(format_string('core.entity_view_display.node.@type.default', ['@type' => $node_type->id()])); - $this->assertNoText(format_string('core.entity_form_display.node.@type.default', ['@type' => $node_type->id()])); + $this->assertNoText(new FormattableMarkup('node.type.@type', ['@type' => $node_type->id()])); + $this->assertNoText(new FormattableMarkup('field.field.node.@type.body', ['@type' => $node_type->id()])); + $this->assertNoText(new FormattableMarkup('core.entity_view_display.node.@type.teaser', ['@type' => $node_type->id()])); + $this->assertNoText(new FormattableMarkup('core.entity_view_display.node.@type.default', ['@type' => $node_type->id()])); + $this->assertNoText(new FormattableMarkup('core.entity_form_display.node.@type.default', ['@type' => $node_type->id()])); } /** diff --git a/core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php b/core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php index d2a0608f2d1..748a9ecabfb 100644 --- a/core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php +++ b/core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php @@ -1084,12 +1084,12 @@ class ConfigTranslationUiTest extends BrowserTestBase { */ protected function getTranslation($config_name, $key, $langcode) { $settings_locations = $this->localeStorage->getLocations(['type' => 'configuration', 'name' => $config_name]); - $this->assertTrue(!empty($settings_locations), format_string('Configuration locations found for %config_name.', ['%config_name' => $config_name])); + $this->assertTrue(!empty($settings_locations), new FormattableMarkup('Configuration locations found for %config_name.', ['%config_name' => $config_name])); if (!empty($settings_locations)) { $source = $this->container->get('config.factory')->get($config_name)->get($key); $source_string = $this->localeStorage->findString(['source' => $source, 'type' => 'configuration']); - $this->assertTrue(!empty($source_string), format_string('Found string for %config_name.%key.', ['%config_name' => $config_name, '%key' => $key])); + $this->assertTrue(!empty($source_string), new FormattableMarkup('Found string for %config_name.%key.', ['%config_name' => $config_name, '%key' => $key])); if (!empty($source_string)) { $conditions = [ diff --git a/core/modules/contact/tests/src/Functional/ContactSitewideTest.php b/core/modules/contact/tests/src/Functional/ContactSitewideTest.php index 9d7eee3e5d9..aef0aa65749 100644 --- a/core/modules/contact/tests/src/Functional/ContactSitewideTest.php +++ b/core/modules/contact/tests/src/Functional/ContactSitewideTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\contact\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Url; use Drupal\contact\Entity\ContactForm; use Drupal\Core\Mail\MailFormatHelper; @@ -103,7 +104,7 @@ class ContactSitewideTest extends BrowserTestBase { $edit_link = $this->xpath('//a[@href=:href]', [ ':href' => Url::fromRoute('entity.contact_form.edit_form', ['contact_form' => 'personal'])->toString(), ]); - $this->assertTrue(empty($edit_link), format_string('No link containing href %href found.', + $this->assertTrue(empty($edit_link), new FormattableMarkup('No link containing href %href found.', ['%href' => 'admin/structure/contact/manage/personal'] )); $this->assertNoLinkByHref('admin/structure/contact/manage/personal/delete'); @@ -150,7 +151,7 @@ class ContactSitewideTest extends BrowserTestBase { $max_length = EntityTypeInterface::BUNDLE_MAX_LENGTH; $max_length_exceeded = $max_length + 1; $this->addContactForm($id = mb_strtolower($this->randomMachineName($max_length_exceeded)), $label = $this->randomMachineName($max_length_exceeded), implode(',', [$recipients[0]]), '', TRUE); - $this->assertText(format_string('Machine-readable name cannot be longer than @max characters but is currently @exceeded characters long.', ['@max' => $max_length, '@exceeded' => $max_length_exceeded])); + $this->assertText(new FormattableMarkup('Machine-readable name cannot be longer than @max characters but is currently @exceeded characters long.', ['@max' => $max_length, '@exceeded' => $max_length_exceeded])); $this->addContactForm($id = mb_strtolower($this->randomMachineName($max_length)), $label = $this->randomMachineName($max_length), implode(',', [$recipients[0]]), '', TRUE); $this->assertText(t('Contact form @label has been added.', ['@label' => $label])); @@ -567,7 +568,7 @@ class ContactSitewideTest extends BrowserTestBase { else { $this->drupalPostForm("admin/structure/contact/manage/$id/delete", [], t('Delete')); $this->assertRaw(t('The contact form %label has been deleted.', ['%label' => $contact_form->label()])); - $this->assertFalse(ContactForm::load($id), format_string('Form %contact_form not found', ['%contact_form' => $contact_form->label()])); + $this->assertFalse(ContactForm::load($id), new FormattableMarkup('Form %contact_form not found', ['%contact_form' => $contact_form->label()])); } } } diff --git a/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php b/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php index 5a8a4cf519a..961ab955149 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php @@ -103,7 +103,7 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase { foreach ($values[$default_langcode] as $property => $value) { $stored_value = $this->getValue($translation, $property, $default_langcode); $value = is_array($value) ? $value[0]['value'] : $value; - $message = format_string('@property correctly stored in the default language.', ['@property' => $property]); + $message = new FormattableMarkup('@property correctly stored in the default language.', ['@property' => $property]); $this->assertEqual($stored_value, $value, $message); } @@ -208,7 +208,7 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase { foreach ($property_values as $property => $value) { $stored_value = $this->getValue($translation, $property, $langcode); $value = is_array($value) ? $value[0]['value'] : $value; - $message = format_string('%property correctly stored with language %language.', ['%property' => $property, '%language' => $langcode]); + $message = new FormattableMarkup('%property correctly stored with language %language.', ['%property' => $property, '%language' => $langcode]); $this->assertEqual($stored_value, $value, $message); } } @@ -231,10 +231,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase { $language = new Language(['id' => $langcode]); $view_url = $entity->toUrl('canonical', ['language' => $language])->toString(); $elements = $this->xpath('//table//a[@href=:href]', [':href' => $view_url]); - $this->assertEqual((string) $elements[0], $entity->getTranslation($langcode)->label(), format_string('Label correctly shown for %language translation.', ['%language' => $langcode])); + $this->assertEqual((string) $elements[0], $entity->getTranslation($langcode)->label(), new FormattableMarkup('Label correctly shown for %language translation.', ['%language' => $langcode])); $edit_path = $entity->toUrl('edit-form', ['language' => $language])->toString(); $elements = $this->xpath('//table//ul[@class="dropbutton"]/li/a[@href=:href]', [':href' => $edit_path]); - $this->assertEqual((string) $elements[0], t('Edit'), format_string('Edit link correct for %language translation.', ['%language' => $langcode])); + $this->assertEqual((string) $elements[0], t('Edit'), new FormattableMarkup('Edit link correct for %language translation.', ['%language' => $langcode])); } } } @@ -569,7 +569,7 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase { $entity = $storage->load($this->entityId); $this->assertEqual( $entity->getChangedTimeAcrossTranslations(), $entity->getTranslation($langcode)->getChangedTime(), - format_string('Changed time for language %language is the latest change over all languages.', ['%language' => $language->getName()]) + new FormattableMarkup('Changed time for language %language is the latest change over all languages.', ['%language' => $language->getName()]) ); } diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php index 5d0f179b67d..8b6565a6c51 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\content_translation\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\comment\Tests\CommentTestTrait; use Drupal\Core\Field\Entity\BaseFieldOverride; @@ -238,7 +239,7 @@ class ContentTranslationSettingsTest extends BrowserTestBase { protected function assertSettings($entity_type, $bundle, $enabled, $edit) { $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration')); $args = ['@entity_type' => $entity_type, '@bundle' => $bundle, '@enabled' => $enabled ? 'enabled' : 'disabled']; - $message = format_string('Translation for entity @entity_type (@bundle) is @enabled.', $args); + $message = new FormattableMarkup('Translation for entity @entity_type (@bundle) is @enabled.', $args); return $this->assertEqual(\Drupal::service('content_translation.manager')->isEnabled($entity_type, $bundle), $enabled, $message); } diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php index e091f7fb266..cc5f5c0e70c 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\content_translation\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Entity\EntityInterface; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; @@ -203,13 +204,13 @@ class ContentTranslationSyncImageTest extends ContentTranslationTestBase { $value = $values[$default_langcode][$item->target_id]; $source_item = $translation->{$this->fieldName}->get($delta); $assert = $item->target_id == $source_item->target_id && $item->alt == $value['alt'] && $item->title == $value['title']; - $this->assertTrue($assert, format_string('Field item @fid has been successfully synchronized.', ['@fid' => $item->target_id])); + $this->assertTrue($assert, new FormattableMarkup('Field item @fid has been successfully synchronized.', ['@fid' => $item->target_id])); $fids[$item->target_id] = TRUE; } // Check that the dropped value is the right one. $removed_fid = $this->files[0]->fid; - $this->assertTrue(!isset($fids[$removed_fid]), format_string('Field item @fid has been correctly removed.', ['@fid' => $removed_fid])); + $this->assertTrue(!isset($fids[$removed_fid]), new FormattableMarkup('Field item @fid has been correctly removed.', ['@fid' => $removed_fid])); // Add back an item for the dropped value and perform synchronization again. $values[$langcode][$removed_fid] = [ @@ -233,7 +234,7 @@ class ContentTranslationSyncImageTest extends ContentTranslationTestBase { $value = $values[$fid_langcode][$item->target_id]; $source_item = $translation->{$this->fieldName}->get($delta); $assert = $item->target_id == $source_item->target_id && $item->alt == $value['alt'] && $item->title == $value['title']; - $this->assertTrue($assert, format_string('Field item @fid has been successfully synchronized.', ['@fid' => $item->target_id])); + $this->assertTrue($assert, new FormattableMarkup('Field item @fid has been successfully synchronized.', ['@fid' => $item->target_id])); } } diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php index 024f95e91eb..617d816af0b 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php @@ -96,7 +96,7 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase { foreach ($values[$default_langcode] as $property => $value) { $stored_value = $this->getValue($translation, $property, $default_langcode); $value = is_array($value) ? $value[0]['value'] : $value; - $message = format_string('@property correctly stored in the default language.', ['@property' => $property]); + $message = new FormattableMarkup('@property correctly stored in the default language.', ['@property' => $property]); $this->assertEqual($stored_value, $value, $message); } @@ -201,7 +201,7 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase { foreach ($property_values as $property => $value) { $stored_value = $this->getValue($translation, $property, $langcode); $value = is_array($value) ? $value[0]['value'] : $value; - $message = format_string('%property correctly stored with language %language.', ['%property' => $property, '%language' => $langcode]); + $message = new FormattableMarkup('%property correctly stored with language %language.', ['%property' => $property, '%language' => $langcode]); $this->assertEqual($stored_value, $value, $message); } } @@ -562,7 +562,7 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase { $entity = $storage->load($this->entityId); $this->assertEqual( $entity->getChangedTimeAcrossTranslations(), $entity->getTranslation($langcode)->getChangedTime(), - format_string('Changed time for language %language is the latest change over all languages.', ['%language' => $language->getName()]) + new FormattableMarkup('Changed time for language %language is the latest change over all languages.', ['%language' => $language->getName()]) ); } diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php index 04dbb9e0b4c..2407d4f4411 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php @@ -133,10 +133,10 @@ class ContentTranslationWorkflowsTest extends ContentTranslationTestBase { foreach ($ops as $op => $label) { if ($op != $current_op) { - $this->assertNoLink($label, format_string('No %op link found.', ['%op' => $label])); + $this->assertNoLink($label, new FormattableMarkup('No %op link found.', ['%op' => $label])); } else { - $this->assertLink($label, 0, format_string('%op link found.', ['%op' => $label])); + $this->assertLink($label, 0, new FormattableMarkup('%op link found.', ['%op' => $label])); } } } diff --git a/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php b/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php index 96e13dc699e..179bc51cc8d 100644 --- a/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php +++ b/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php @@ -806,7 +806,7 @@ class DateTimeFieldTest extends DateTestBase { "{$field_name}[0][value][time]" => '00:00:00', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid year value %date has been caught.', ['%date' => $date_value])); + $this->assertText('date is invalid', new FormattableMarkup('Invalid year value %date has been caught.', ['%date' => $date_value])); $date_value = '2012-75-01'; $edit = [ @@ -814,7 +814,7 @@ class DateTimeFieldTest extends DateTestBase { "{$field_name}[0][value][time]" => '00:00:00', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid month value %date has been caught.', ['%date' => $date_value])); + $this->assertText('date is invalid', new FormattableMarkup('Invalid month value %date has been caught.', ['%date' => $date_value])); $date_value = '2012-12-99'; $edit = [ @@ -822,7 +822,7 @@ class DateTimeFieldTest extends DateTestBase { "{$field_name}[0][value][time]" => '00:00:00', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid day value %date has been caught.', ['%date' => $date_value])); + $this->assertText('date is invalid', new FormattableMarkup('Invalid day value %date has been caught.', ['%date' => $date_value])); $date_value = '2012-12-01'; $time_value = ''; @@ -840,7 +840,7 @@ class DateTimeFieldTest extends DateTestBase { "{$field_name}[0][value][time]" => $time_value, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid hour value %time has been caught.', ['%time' => $time_value])); + $this->assertText('date is invalid', new FormattableMarkup('Invalid hour value %time has been caught.', ['%time' => $time_value])); $date_value = '2012-12-01'; $time_value = '12:99:00'; @@ -849,7 +849,7 @@ class DateTimeFieldTest extends DateTestBase { "{$field_name}[0][value][time]" => $time_value, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid minute value %time has been caught.', ['%time' => $time_value])); + $this->assertText('date is invalid', new FormattableMarkup('Invalid minute value %time has been caught.', ['%time' => $time_value])); $date_value = '2012-12-01'; $time_value = '12:15:99'; @@ -858,7 +858,7 @@ class DateTimeFieldTest extends DateTestBase { "{$field_name}[0][value][time]" => $time_value, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid second value %time has been caught.', ['%time' => $time_value])); + $this->assertText('date is invalid', new FormattableMarkup('Invalid second value %time has been caught.', ['%time' => $time_value])); } /** diff --git a/core/modules/dblog/tests/src/Functional/DbLogTest.php b/core/modules/dblog/tests/src/Functional/DbLogTest.php index 7e8c3bea755..006af599287 100644 --- a/core/modules/dblog/tests/src/Functional/DbLogTest.php +++ b/core/modules/dblog/tests/src/Functional/DbLogTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\dblog\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Unicode; use Drupal\Core\Database\Database; @@ -180,7 +181,7 @@ class DbLogTest extends BrowserTestBase { // Check row limit variable. $current_limit = $this->config('dblog.settings')->get('row_limit'); - $this->assertTrue($current_limit == $row_limit, format_string('[Cache] Row limit variable of @count equals row limit of @limit', ['@count' => $current_limit, '@limit' => $row_limit])); + $this->assertTrue($current_limit == $row_limit, new FormattableMarkup('[Cache] Row limit variable of @count equals row limit of @limit', ['@count' => $current_limit, '@limit' => $row_limit])); } /** @@ -339,7 +340,7 @@ class DbLogTest extends BrowserTestBase { $this->assertResponse(200); // Retrieve the user object. $user = user_load_by_name($name); - $this->assertTrue($user != NULL, format_string('User @name was loaded', ['@name' => $name])); + $this->assertTrue($user != NULL, new FormattableMarkup('User @name was loaded', ['@name' => $name])); // pass_raw property is needed by drupalLogin. $user->passRaw = $pass; // Log in user. @@ -352,7 +353,7 @@ class DbLogTest extends BrowserTestBase { $ids[] = $row->wid; } $count_before = (isset($ids)) ? count($ids) : 0; - $this->assertTrue($count_before > 0, format_string('DBLog contains @count records for @name', ['@count' => $count_before, '@name' => $user->getAccountName()])); + $this->assertTrue($count_before > 0, new FormattableMarkup('DBLog contains @count records for @name', ['@count' => $count_before, '@name' => $user->getAccountName()])); // Log in the admin user. $this->drupalLogin($this->adminUser); @@ -422,7 +423,7 @@ class DbLogTest extends BrowserTestBase { $this->assertResponse(200); // Retrieve the node object. $node = $this->drupalGetNodeByTitle($title); - $this->assertTrue($node != NULL, format_string('Node @title was loaded', ['@title' => $title])); + $this->assertTrue($node != NULL, new FormattableMarkup('Node @title was loaded', ['@title' => $title])); // Edit the node. $edit = $this->getContentUpdate($type); $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save')); @@ -535,7 +536,7 @@ class DbLogTest extends BrowserTestBase { // Add a watchdog entry. $this->container->get('logger.dblog')->log($log['severity'], $log['message'], $log); // Make sure the table count has actually been incremented. - $this->assertEqual($count + 1, $connection->query('SELECT COUNT(*) FROM {watchdog}')->fetchField(), format_string('\Drupal\dblog\Logger\DbLog->log() added an entry to the dblog :count', [':count' => $count])); + $this->assertEqual($count + 1, $connection->query('SELECT COUNT(*) FROM {watchdog}')->fetchField(), new FormattableMarkup('\Drupal\dblog\Logger\DbLog->log() added an entry to the dblog :count', [':count' => $count])); // Log in the admin user. $this->drupalLogin($this->adminUser); // Post in order to clear the database table. @@ -544,7 +545,7 @@ class DbLogTest extends BrowserTestBase { $this->drupalPostForm(NULL, [], 'Confirm'); // Count the rows in watchdog that previously related to the deleted user. $count = $connection->query('SELECT COUNT(*) FROM {watchdog}')->fetchField(); - $this->assertEqual($count, 0, format_string('DBLog contains :count records after a clear.', [':count' => $count])); + $this->assertEqual($count, 0, new FormattableMarkup('DBLog contains :count records after a clear.', [':count' => $count])); } /** diff --git a/core/modules/dblog/tests/src/Kernel/DbLogTest.php b/core/modules/dblog/tests/src/Kernel/DbLogTest.php index 9f3340ebad1..b211cc7414b 100644 --- a/core/modules/dblog/tests/src/Kernel/DbLogTest.php +++ b/core/modules/dblog/tests/src/Kernel/DbLogTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\dblog\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Database\Database; use Drupal\KernelTests\KernelTestBase; use Drupal\Tests\dblog\Functional\FakeLogEntries; @@ -40,18 +41,18 @@ class DbLogTest extends KernelTestBase { $this->generateLogEntries($row_limit + 10); // Verify that the database log row count exceeds the row limit. $count = Database::getConnection()->query('SELECT COUNT(wid) FROM {watchdog}')->fetchField(); - $this->assertGreaterThan($row_limit, $count, format_string('Dblog row count of @count exceeds row limit of @limit', ['@count' => $count, '@limit' => $row_limit])); + $this->assertGreaterThan($row_limit, $count, new FormattableMarkup('Dblog row count of @count exceeds row limit of @limit', ['@count' => $count, '@limit' => $row_limit])); // Get the number of enabled modules. Cron adds a log entry for each module. $list = $this->container->get('module_handler')->getImplementations('cron'); $module_count = count($list); $cron_detailed_count = $this->runCron(); - $this->assertEquals($module_count + 2, $cron_detailed_count, format_string('Cron added @count of @expected new log entries', ['@count' => $cron_detailed_count, '@expected' => $module_count + 2])); + $this->assertEquals($module_count + 2, $cron_detailed_count, new FormattableMarkup('Cron added @count of @expected new log entries', ['@count' => $cron_detailed_count, '@expected' => $module_count + 2])); // Test disabling of detailed cron logging. $this->config('system.cron')->set('logging', 0)->save(); $cron_count = $this->runCron(); - $this->assertEquals(1, $cron_count, format_string('Cron added @count of @expected new log entries', ['@count' => $cron_count, '@expected' => 1])); + $this->assertEquals(1, $cron_count, new FormattableMarkup('Cron added @count of @expected new log entries', ['@count' => $cron_count, '@expected' => 1])); } /** diff --git a/core/modules/editor/tests/src/Functional/EditorSecurityTest.php b/core/modules/editor/tests/src/Functional/EditorSecurityTest.php index 55095c98c60..2428f70d6ea 100644 --- a/core/modules/editor/tests/src/Functional/EditorSecurityTest.php +++ b/core/modules/editor/tests/src/Functional/EditorSecurityTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\editor\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Serialization\Json; use Drupal\editor\Entity\Editor; use Drupal\filter\Entity\FilterFormat; @@ -276,7 +277,7 @@ class EditorSecurityTest extends BrowserTestBase { // Log in as each user that may edit the content, and assert the value. foreach ($expected as $case) { foreach ($case['users'] as $account) { - $this->pass(format_string('Scenario: sample %sample_id, %format.', [ + $this->pass(new FormattableMarkup('Scenario: sample %sample_id, %format.', [ '%sample_id' => $case['node_id'], '%format' => $case['format'], ])); @@ -401,7 +402,7 @@ class EditorSecurityTest extends BrowserTestBase { // Switch to every other text format/editor and verify the results. foreach ($case['switch_to'] as $format => $expected_filtered_value) { - $this->pass(format_string('Scenario: sample %sample_id, switch from %original_format to %format.', [ + $this->pass(new FormattableMarkup('Scenario: sample %sample_id, switch from %original_format to %format.', [ '%sample_id' => $case['node_id'], '%original_format' => $case['format'], '%format' => $format, diff --git a/core/modules/field/src/Tests/FieldTestBase.php b/core/modules/field/src/Tests/FieldTestBase.php index d160aba1dcb..6f7f71419fb 100644 --- a/core/modules/field/src/Tests/FieldTestBase.php +++ b/core/modules/field/src/Tests/FieldTestBase.php @@ -4,6 +4,7 @@ namespace Drupal\field\Tests; @trigger_error(__NAMESPACE__ . '\FieldTestBase is deprecated for removal before Drupal 9.0.0. Use Drupal\Tests\field\Functional\FieldTestBase instead. See https://www.drupal.org/node/2999939', E_USER_DEPRECATED); +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\simpletest\WebTestBase; @@ -65,7 +66,7 @@ abstract class FieldTestBase extends WebTestBase { $values = $field->getValue(); $this->assertEqual(count($values), count($expected_values), 'Expected number of values were saved.'); foreach ($expected_values as $key => $value) { - $this->assertEqual($values[$key][$column], $value, format_string('Value @value was saved correctly.', ['@value' => $value])); + $this->assertEqual($values[$key][$column], $value, new FormattableMarkup('Value @value was saved correctly.', ['@value' => $value])); } } diff --git a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceIntegrationTest.php b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceIntegrationTest.php index 39dd1632db3..9c67d043f77 100644 --- a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceIntegrationTest.php +++ b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceIntegrationTest.php @@ -188,7 +188,7 @@ class EntityReferenceIntegrationTest extends BrowserTestBase { $entity = current($this->container->get('entity_type.manager')->getStorage( $this->entityType)->loadByProperties(['name' => $entity_name])); - $this->assertTrue($entity, format_string('%entity_type: Entity found in the database.', ['%entity_type' => $this->entityType])); + $this->assertTrue($entity, new FormattableMarkup('%entity_type: Entity found in the database.', ['%entity_type' => $this->entityType])); $this->assertEqual($entity->{$this->fieldName}->target_id, $referenced_entities[0]->id()); $this->assertEqual($entity->{$this->fieldName}->entity->id(), $referenced_entities[0]->id()); diff --git a/core/modules/field/tests/src/Functional/FieldTestBase.php b/core/modules/field/tests/src/Functional/FieldTestBase.php index b8dff1e55e0..db20aa2fe14 100644 --- a/core/modules/field/tests/src/Functional/FieldTestBase.php +++ b/core/modules/field/tests/src/Functional/FieldTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\field\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Tests\BrowserTestBase; @@ -58,7 +59,7 @@ abstract class FieldTestBase extends BrowserTestBase { $values = $field->getValue(); $this->assertEqual(count($values), count($expected_values), 'Expected number of values were saved.'); foreach ($expected_values as $key => $value) { - $this->assertEqual($values[$key][$column], $value, format_string('Value @value was saved correctly.', ['@value' => $value])); + $this->assertEqual($values[$key][$column], $value, new FormattableMarkup('Value @value was saved correctly.', ['@value' => $value])); } } diff --git a/core/modules/field/tests/src/Functional/String/StringFieldTest.php b/core/modules/field/tests/src/Functional/String/StringFieldTest.php index e3419be3497..21273673913 100644 --- a/core/modules/field/tests/src/Functional/String/StringFieldTest.php +++ b/core/modules/field/tests/src/Functional/String/StringFieldTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\field\Functional\String; +use Drupal\Component\Render\FormattableMarkup; use Drupal\entity_test\Entity\EntityTest; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; @@ -82,7 +83,7 @@ class StringFieldTest extends BrowserTestBase { $this->drupalGet('entity_test/add'); $this->assertFieldByName("{$field_name}[0][value]", '', 'Widget is displayed'); $this->assertNoFieldByName("{$field_name}[0][format]", '1', 'Format selector is not displayed'); - $this->assertRaw(format_string('placeholder="A placeholder on @widget_type"', ['@widget_type' => $widget_type])); + $this->assertRaw(new FormattableMarkup('placeholder="A placeholder on @widget_type"', ['@widget_type' => $widget_type])); // Submit with some value. $value = $this->randomMachineName(); diff --git a/core/modules/field/tests/src/Functional/TranslationWebTest.php b/core/modules/field/tests/src/Functional/TranslationWebTest.php index f8674fb3e31..400044bb56f 100644 --- a/core/modules/field/tests/src/Functional/TranslationWebTest.php +++ b/core/modules/field/tests/src/Functional/TranslationWebTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\field\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldConfig; use Drupal\language\Entity\ConfigurableLanguage; @@ -129,7 +130,7 @@ class TranslationWebTest extends FieldTestBase { ->loadRevision($revision_id); foreach ($available_langcodes as $langcode => $value) { $passed = $entity->getTranslation($langcode)->{$field_name}->value == $value + 1; - $this->assertTrue($passed, format_string('The @language translation for revision @revision was correctly stored', ['@language' => $langcode, '@revision' => $entity->getRevisionId()])); + $this->assertTrue($passed, new FormattableMarkup('The @language translation for revision @revision was correctly stored', ['@language' => $langcode, '@revision' => $entity->getRevisionId()])); } } diff --git a/core/modules/field/tests/src/Kernel/DisplayApiTest.php b/core/modules/field/tests/src/Kernel/DisplayApiTest.php index df81f48d3e2..df133621335 100644 --- a/core/modules/field/tests/src/Kernel/DisplayApiTest.php +++ b/core/modules/field/tests/src/Kernel/DisplayApiTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\field\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Entity\Entity\EntityViewMode; use Drupal\entity_test\Entity\EntityTest; use Drupal\field\Entity\FieldConfig; @@ -135,7 +136,7 @@ class DisplayApiTest extends FieldKernelTestBase { $setting = $settings['test_formatter_setting']; $this->assertText($this->label, 'Label was displayed.'); foreach ($this->values as $delta => $value) { - $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', ['@delta' => $delta])); + $this->assertText($setting . '|' . $value['value'], new FormattableMarkup('Value @delta was displayed with expected setting.', ['@delta' => $delta])); } // Display settings: Check hidden field. @@ -194,7 +195,7 @@ class DisplayApiTest extends FieldKernelTestBase { $this->assertNoText($this->label, 'Label was not displayed.'); $this->assertNoText('field_test_entity_display_build_alter', 'Alter not fired.'); foreach ($this->values as $delta => $value) { - $this->assertText($setting . '|' . $value['value'] . '|' . ($value['value'] + 1), format_string('Value @delta was displayed with expected setting.', ['@delta' => $delta])); + $this->assertText($setting . '|' . $value['value'] . '|' . ($value['value'] + 1), new FormattableMarkup('Value @delta was displayed with expected setting.', ['@delta' => $delta])); } // View mode: check that display settings specified in the display object @@ -204,7 +205,7 @@ class DisplayApiTest extends FieldKernelTestBase { $setting = $this->displayOptions['teaser']['settings']['test_formatter_setting']; $this->assertText($this->label, 'Label was displayed.'); foreach ($this->values as $delta => $value) { - $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', ['@delta' => $delta])); + $this->assertText($setting . '|' . $value['value'], new FormattableMarkup('Value @delta was displayed with expected setting.', ['@delta' => $delta])); } // Unknown view mode: check that display settings for 'default' view mode @@ -214,7 +215,7 @@ class DisplayApiTest extends FieldKernelTestBase { $setting = $this->displayOptions['default']['settings']['test_formatter_setting']; $this->assertText($this->label, 'Label was displayed.'); foreach ($this->values as $delta => $value) { - $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', ['@delta' => $delta])); + $this->assertText($setting . '|' . $value['value'], new FormattableMarkup('Value @delta was displayed with expected setting.', ['@delta' => $delta])); } } @@ -229,7 +230,7 @@ class DisplayApiTest extends FieldKernelTestBase { $item = $this->entity->{$this->fieldName}[$delta]; $build = $item->view(); $this->render($build); - $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', ['@delta' => $delta])); + $this->assertText($setting . '|' . $value['value'], new FormattableMarkup('Value @delta was displayed with expected setting.', ['@delta' => $delta])); } // Check that explicit display settings are used. @@ -244,7 +245,7 @@ class DisplayApiTest extends FieldKernelTestBase { $item = $this->entity->{$this->fieldName}[$delta]; $build = $item->view($display); $this->render($build); - $this->assertText($setting . '|0:' . $value['value'], format_string('Value @delta was displayed with expected setting.', ['@delta' => $delta])); + $this->assertText($setting . '|0:' . $value['value'], new FormattableMarkup('Value @delta was displayed with expected setting.', ['@delta' => $delta])); } // Check that prepare_view steps are invoked. @@ -259,7 +260,7 @@ class DisplayApiTest extends FieldKernelTestBase { $item = $this->entity->{$this->fieldName}[$delta]; $build = $item->view($display); $this->render($build); - $this->assertText($setting . '|' . $value['value'] . '|' . ($value['value'] + 1), format_string('Value @delta was displayed with expected setting.', ['@delta' => $delta])); + $this->assertText($setting . '|' . $value['value'] . '|' . ($value['value'] + 1), new FormattableMarkup('Value @delta was displayed with expected setting.', ['@delta' => $delta])); } // View mode: check that display settings specified in the field are used. @@ -268,7 +269,7 @@ class DisplayApiTest extends FieldKernelTestBase { $item = $this->entity->{$this->fieldName}[$delta]; $build = $item->view('teaser'); $this->render($build); - $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', ['@delta' => $delta])); + $this->assertText($setting . '|' . $value['value'], new FormattableMarkup('Value @delta was displayed with expected setting.', ['@delta' => $delta])); } // Unknown view mode: check that display settings for 'default' view mode @@ -278,7 +279,7 @@ class DisplayApiTest extends FieldKernelTestBase { $item = $this->entity->{$this->fieldName}[$delta]; $build = $item->view('unknown_view_mode'); $this->render($build); - $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', ['@delta' => $delta])); + $this->assertText($setting . '|' . $value['value'], new FormattableMarkup('Value @delta was displayed with expected setting.', ['@delta' => $delta])); } } diff --git a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php index b42d83c13db..04352ea93f0 100644 --- a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php +++ b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\field\Kernel\EntityReference; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Field\FieldStorageDefinitionInterface; @@ -163,7 +164,7 @@ class EntityReferenceFormatterTest extends EntityKernelTestBase { ->view($referencing_entity, 'default'); // Verify the un-accessible item still exists. - $this->assertEqual($referencing_entity->{$field_name}->target_id, $this->referencedEntity->id(), format_string('The un-accessible item still exists after @name formatter was executed.', ['@name' => $name])); + $this->assertEqual($referencing_entity->{$field_name}->target_id, $this->referencedEntity->id(), new FormattableMarkup('The un-accessible item still exists after @name formatter was executed.', ['@name' => $name])); } } @@ -215,7 +216,7 @@ class EntityReferenceFormatterTest extends EntityKernelTestBase { $this->assertEqual($build[0]['#markup'], 'default | ' . $this->referencedEntity->label() . $expected_rendered_name_field_1 . $expected_rendered_body_field_1, sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter)); $expected_cache_tags = Cache::mergeTags(\Drupal::entityTypeManager()->getViewBuilder($this->entityType)->getCacheTags(), $this->referencedEntity->getCacheTags()); $expected_cache_tags = Cache::mergeTags($expected_cache_tags, FilterFormat::load('full_html')->getCacheTags()); - $this->assertEqual($build[0]['#cache']['tags'], $expected_cache_tags, format_string('The @formatter formatter has the expected cache tags.', ['@formatter' => $formatter])); + $this->assertEqual($build[0]['#cache']['tags'], $expected_cache_tags, new FormattableMarkup('The @formatter formatter has the expected cache tags.', ['@formatter' => $formatter])); // Test the second field item. $expected_rendered_name_field_2 = ' diff --git a/core/modules/field/tests/src/Kernel/FieldAttachStorageTest.php b/core/modules/field/tests/src/Kernel/FieldAttachStorageTest.php index cc08edb348b..20f69910500 100644 --- a/core/modules/field/tests/src/Kernel/FieldAttachStorageTest.php +++ b/core/modules/field/tests/src/Kernel/FieldAttachStorageTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\field\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; @@ -54,17 +55,17 @@ class FieldAttachStorageTest extends FieldKernelTestBase { $this->assertEqual(count($entity->{$this->fieldTestData->field_name}), $cardinality, 'Current revision: expected number of values'); for ($delta = 0; $delta < $cardinality; $delta++) { // The field value loaded matches the one inserted or updated. - $this->assertEqual($entity->{$this->fieldTestData->field_name}[$delta]->value, $values[$current_revision][$delta]['value'], format_string('Current revision: expected value %delta was found.', ['%delta' => $delta])); + $this->assertEqual($entity->{$this->fieldTestData->field_name}[$delta]->value, $values[$current_revision][$delta]['value'], new FormattableMarkup('Current revision: expected value %delta was found.', ['%delta' => $delta])); } // Confirm each revision loads the correct data. foreach (array_keys($values) as $revision_id) { $entity = $storage->loadRevision($revision_id); // Number of values per field loaded equals the field cardinality. - $this->assertEqual(count($entity->{$this->fieldTestData->field_name}), $cardinality, format_string('Revision %revision_id: expected number of values.', ['%revision_id' => $revision_id])); + $this->assertEqual(count($entity->{$this->fieldTestData->field_name}), $cardinality, new FormattableMarkup('Revision %revision_id: expected number of values.', ['%revision_id' => $revision_id])); for ($delta = 0; $delta < $cardinality; $delta++) { // The field value loaded matches the one inserted or updated. - $this->assertEqual($entity->{$this->fieldTestData->field_name}[$delta]->value, $values[$revision_id][$delta]['value'], format_string('Revision %revision_id: expected value %delta was found.', ['%revision_id' => $revision_id, '%delta' => $delta])); + $this->assertEqual($entity->{$this->fieldTestData->field_name}[$delta]->value, $values[$revision_id][$delta]['value'], new FormattableMarkup('Revision %revision_id: expected value %delta was found.', ['%revision_id' => $revision_id, '%delta' => $delta])); } } } @@ -136,7 +137,7 @@ class FieldAttachStorageTest extends FieldKernelTestBase { continue; } // The field value loaded matches the one inserted. - $this->assertEqual($entity->{$field_name}->value, $values[$index][$field_name], format_string('Entity %index: expected value was found.', ['%index' => $index])); + $this->assertEqual($entity->{$field_name}->value, $values[$index][$field_name], new FormattableMarkup('Entity %index: expected value was found.', ['%index' => $index])); } } } diff --git a/core/modules/field/tests/src/Kernel/FieldDataCountTest.php b/core/modules/field/tests/src/Kernel/FieldDataCountTest.php index 86cb4150e49..b9ad604c0e4 100644 --- a/core/modules/field/tests/src/Kernel/FieldDataCountTest.php +++ b/core/modules/field/tests/src/Kernel/FieldDataCountTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\field\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Database\Database; use Drupal\Core\Entity\Sql\SqlContentEntityStorage; use Drupal\entity_test\Entity\EntityTest; @@ -138,7 +139,7 @@ class FieldDataCountTest extends FieldKernelTestBase { $storage = $this->container->get('entity_type.manager')->getStorage($entity_type); $entity = $storage->loadRevision($first_revision); - $this->assertEqual(count($entity->{$this->fieldTestData->field_name_2}), $cardinality, format_string('Revision %revision_id: expected number of values.', ['%revision_id' => $first_revision])); + $this->assertEqual(count($entity->{$this->fieldTestData->field_name_2}), $cardinality, new FormattableMarkup('Revision %revision_id: expected number of values.', ['%revision_id' => $first_revision])); } /** diff --git a/core/modules/field/tests/src/Kernel/FieldKernelTestBase.php b/core/modules/field/tests/src/Kernel/FieldKernelTestBase.php index 568f62cda3d..fdc8940fd65 100644 --- a/core/modules/field/tests/src/Kernel/FieldKernelTestBase.php +++ b/core/modules/field/tests/src/Kernel/FieldKernelTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\field\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\field\Entity\FieldConfig; @@ -197,7 +198,7 @@ abstract class FieldKernelTestBase extends KernelTestBase { $values = $field->getValue(); $this->assertEqual(count($values), count($expected_values), 'Expected number of values were saved.'); foreach ($expected_values as $key => $value) { - $this->assertEqual($values[$key][$column], $value, format_string('Value @value was saved correctly.', ['@value' => $value])); + $this->assertEqual($values[$key][$column], $value, new FormattableMarkup('Value @value was saved correctly.', ['@value' => $value])); } } diff --git a/core/modules/field/tests/src/Kernel/FieldTypePluginManagerTest.php b/core/modules/field/tests/src/Kernel/FieldTypePluginManagerTest.php index c40229fe7a9..ec480a8b4f1 100644 --- a/core/modules/field/tests/src/Kernel/FieldTypePluginManagerTest.php +++ b/core/modules/field/tests/src/Kernel/FieldTypePluginManagerTest.php @@ -21,8 +21,8 @@ class FieldTypePluginManagerTest extends FieldKernelTestBase { $field_type_manager = \Drupal::service('plugin.manager.field.field_type'); foreach (['test_field', 'shape', 'hidden_test_field'] as $type) { $definition = $field_type_manager->getDefinition($type); - $this->assertIdentical($field_type_manager->getDefaultStorageSettings($type), $definition['class']::defaultStorageSettings(), format_string("%type storage settings were returned", ['%type' => $type])); - $this->assertIdentical($field_type_manager->getDefaultFieldSettings($type), $definition['class']::defaultFieldSettings(), format_string(" %type field settings were returned", ['%type' => $type])); + $this->assertIdentical($field_type_manager->getDefaultStorageSettings($type), $definition['class']::defaultStorageSettings(), new FormattableMarkup("%type storage settings were returned", ['%type' => $type])); + $this->assertIdentical($field_type_manager->getDefaultFieldSettings($type), $definition['class']::defaultFieldSettings(), new FormattableMarkup(" %type field settings were returned", ['%type' => $type])); } } diff --git a/core/modules/field/tests/src/Kernel/TranslationTest.php b/core/modules/field/tests/src/Kernel/TranslationTest.php index 605c5574b4a..20e729f4dde 100644 --- a/core/modules/field/tests/src/Kernel/TranslationTest.php +++ b/core/modules/field/tests/src/Kernel/TranslationTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\field\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\field\Entity\FieldConfig; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\field\Entity\FieldStorageConfig; @@ -136,7 +137,7 @@ class TranslationTest extends FieldKernelTestBase { foreach ($items as $delta => $item) { $result = $result && $item['value'] == $entity->getTranslation($langcode)->{$this->fieldName}[$delta]->value; } - $this->assertTrue($result, format_string('%language translation correctly handled.', ['%language' => $langcode])); + $this->assertTrue($result, new FormattableMarkup('%language translation correctly handled.', ['%language' => $langcode])); } // Test default values. @@ -173,7 +174,7 @@ class TranslationTest extends FieldKernelTestBase { // @todo Test every translation once the Entity Translation API allows for // multilingual defaults. $langcode = $entity->language()->getId(); - $this->assertEqual($entity->getTranslation($langcode)->{$field_name_default}->getValue(), $field->getDefaultValueLiteral(), format_string('Default value correctly populated for language %language.', ['%language' => $langcode])); + $this->assertEqual($entity->getTranslation($langcode)->{$field_name_default}->getValue(), $field->getDefaultValueLiteral(), new FormattableMarkup('Default value correctly populated for language %language.', ['%language' => $langcode])); $storage = \Drupal::entityTypeManager()->getStorage($entity_type_id); // Check that explicit empty values are not overridden with default values. @@ -189,7 +190,7 @@ class TranslationTest extends FieldKernelTestBase { } foreach ($entity->getTranslationLanguages() as $langcode => $language) { - $this->assertEquals([], $entity->getTranslation($langcode)->{$field_name_default}->getValue(), format_string('Empty value correctly populated for language %language.', ['%language' => $langcode])); + $this->assertEquals([], $entity->getTranslation($langcode)->{$field_name_default}->getValue(), new FormattableMarkup('Empty value correctly populated for language %language.', ['%language' => $langcode])); } } } diff --git a/core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php b/core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php index a8479c00f9d..bf86b7e98fc 100644 --- a/core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php +++ b/core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php @@ -142,7 +142,7 @@ class ManageFieldsFunctionalTest extends BrowserTestBase { ]; foreach ($table_headers as $table_header) { // We check that the label appear in the table headings. - $this->assertRaw($table_header . '</th>', format_string('%table_header table header was found.', ['%table_header' => $table_header])); + $this->assertRaw($table_header . '</th>', new FormattableMarkup('%table_header table header was found.', ['%table_header' => $table_header])); } // Test the "Add field" action link. @@ -399,7 +399,7 @@ class ManageFieldsFunctionalTest extends BrowserTestBase { // Create a valid field. $this->fieldUIAddNewField('admin/structure/types/manage/' . $this->contentType, $this->fieldNameInput, $this->fieldLabel); $this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/node.' . $this->contentType . '.' . $field_prefix . $this->fieldNameInput); - $this->assertText(format_string('@label settings for @type', ['@label' => $this->fieldLabel, '@type' => $this->contentType])); + $this->assertText(new FormattableMarkup('@label settings for @type', ['@label' => $this->fieldLabel, '@type' => $this->contentType])); } /** @@ -603,7 +603,7 @@ class ManageFieldsFunctionalTest extends BrowserTestBase { ->getFormDisplay('node', $this->contentType) ->setComponent($field_name) ->save(); - $this->assertTrue(FieldConfig::load('node.' . $this->contentType . '.' . $field_name), format_string('A field of the field storage %field was created programmatically.', ['%field' => $field_name])); + $this->assertTrue(FieldConfig::load('node.' . $this->contentType . '.' . $field_name), new FormattableMarkup('A field of the field storage %field was created programmatically.', ['%field' => $field_name])); // Check that the newly added field appears on the 'Manage Fields' // screen. diff --git a/core/modules/file/src/Tests/FileFieldTestBase.php b/core/modules/file/src/Tests/FileFieldTestBase.php index 484bf2fa022..1096cbd4092 100644 --- a/core/modules/file/src/Tests/FileFieldTestBase.php +++ b/core/modules/file/src/Tests/FileFieldTestBase.php @@ -4,6 +4,7 @@ namespace Drupal\file\Tests; @trigger_error('The ' . __NAMESPACE__ . '\FileFieldTestBase is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\file\Functional\FileFieldTestBase. See https://www.drupal.org/node/2969361.', E_USER_DEPRECATED); +use Drupal\Component\Render\FormattableMarkup; use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldConfig; use Drupal\file\FileInterface; @@ -269,7 +270,7 @@ abstract class FileFieldTestBase extends WebTestBase { * Asserts that a file exists physically on disk. */ public function assertFileExists($file, $message = NULL) { - $message = isset($message) ? $message : format_string('File %file exists on the disk.', ['%file' => $file->getFileUri()]); + $message = isset($message) ? $message : new FormattableMarkup('File %file exists on the disk.', ['%file' => $file->getFileUri()]); $this->assertTrue(is_file($file->getFileUri()), $message); } @@ -279,7 +280,7 @@ abstract class FileFieldTestBase extends WebTestBase { public function assertFileEntryExists($file, $message = NULL) { $this->container->get('entity_type.manager')->getStorage('file')->resetCache(); $db_file = File::load($file->id()); - $message = isset($message) ? $message : format_string('File %file exists in database at the correct path.', ['%file' => $file->getFileUri()]); + $message = isset($message) ? $message : new FormattableMarkup('File %file exists in database at the correct path.', ['%file' => $file->getFileUri()]); $this->assertEqual($db_file->getFileUri(), $file->getFileUri(), $message); } @@ -287,7 +288,7 @@ abstract class FileFieldTestBase extends WebTestBase { * Asserts that a file does not exist on disk. */ public function assertFileNotExists($file, $message = NULL) { - $message = isset($message) ? $message : format_string('File %file exists on the disk.', ['%file' => $file->getFileUri()]); + $message = isset($message) ? $message : new FormattableMarkup('File %file exists on the disk.', ['%file' => $file->getFileUri()]); $this->assertFalse(is_file($file->getFileUri()), $message); } @@ -296,7 +297,7 @@ abstract class FileFieldTestBase extends WebTestBase { */ public function assertFileEntryNotExists($file, $message) { $this->container->get('entity_type.manager')->getStorage('file')->resetCache(); - $message = isset($message) ? $message : format_string('File %file exists in database at the correct path.', ['%file' => $file->getFileUri()]); + $message = isset($message) ? $message : new FormattableMarkup('File %file exists in database at the correct path.', ['%file' => $file->getFileUri()]); $this->assertFalse(File::load($file->id()), $message); } @@ -304,7 +305,7 @@ abstract class FileFieldTestBase extends WebTestBase { * Asserts that a file's status is set to permanent in the database. */ public function assertFileIsPermanent(FileInterface $file, $message = NULL) { - $message = isset($message) ? $message : format_string('File %file is permanent.', ['%file' => $file->getFileUri()]); + $message = isset($message) ? $message : new FormattableMarkup('File %file is permanent.', ['%file' => $file->getFileUri()]); $this->assertTrue($file->isPermanent(), $message); } diff --git a/core/modules/file/src/Tests/FileManagedTestBase.php b/core/modules/file/src/Tests/FileManagedTestBase.php index 1c52b353123..b66d0f1f236 100644 --- a/core/modules/file/src/Tests/FileManagedTestBase.php +++ b/core/modules/file/src/Tests/FileManagedTestBase.php @@ -4,6 +4,7 @@ namespace Drupal\file\Tests; @trigger_error('The ' . __NAMESPACE__ . '\FileManagedTestBase is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\file\Functional\FileManagedTestBase. See https://www.drupal.org/node/2969361.', E_USER_DEPRECATED); +use Drupal\Component\Render\FormattableMarkup; use Drupal\file\Entity\File; use Drupal\file\FileInterface; use Drupal\simpletest\WebTestBase; @@ -47,16 +48,16 @@ abstract class FileManagedTestBase extends WebTestBase { // Determine if there were any expected that were not called. $uncalled = array_diff($expected, $actual); if (count($uncalled)) { - $this->assertTrue(FALSE, format_string('Expected hooks %expected to be called but %uncalled was not called.', ['%expected' => implode(', ', $expected), '%uncalled' => implode(', ', $uncalled)])); + $this->assertTrue(FALSE, new FormattableMarkup('Expected hooks %expected to be called but %uncalled was not called.', ['%expected' => implode(', ', $expected), '%uncalled' => implode(', ', $uncalled)])); } else { - $this->assertTrue(TRUE, format_string('All the expected hooks were called: %expected', ['%expected' => empty($expected) ? '(none)' : implode(', ', $expected)])); + $this->assertTrue(TRUE, new FormattableMarkup('All the expected hooks were called: %expected', ['%expected' => empty($expected) ? '(none)' : implode(', ', $expected)])); } // Determine if there were any unexpected calls. $unexpected = array_diff($actual, $expected); if (count($unexpected)) { - $this->assertTrue(FALSE, format_string('Unexpected hooks were called: %unexpected.', ['%unexpected' => empty($unexpected) ? '(none)' : implode(', ', $unexpected)])); + $this->assertTrue(FALSE, new FormattableMarkup('Unexpected hooks were called: %unexpected.', ['%unexpected' => empty($unexpected) ? '(none)' : implode(', ', $unexpected)])); } else { $this->assertTrue(TRUE, 'No unexpected hooks were called.'); @@ -78,13 +79,13 @@ abstract class FileManagedTestBase extends WebTestBase { if (!isset($message)) { if ($actual_count == $expected_count) { - $message = format_string('hook_file_@name was called correctly.', ['@name' => $hook]); + $message = new FormattableMarkup('hook_file_@name was called correctly.', ['@name' => $hook]); } elseif ($expected_count == 0) { $message = \Drupal::translation()->formatPlural($actual_count, 'hook_file_@name was not expected to be called but was actually called once.', 'hook_file_@name was not expected to be called but was actually called @count times.', ['@name' => $hook, '@count' => $actual_count]); } else { - $message = format_string('hook_file_@name was expected to be called %expected times but was called %actual times.', ['@name' => $hook, '%expected' => $expected_count, '%actual' => $actual_count]); + $message = new FormattableMarkup('hook_file_@name was expected to be called %expected times but was called %actual times.', ['@name' => $hook, '%expected' => $expected_count, '%actual' => $actual_count]); } } $this->assertEqual($actual_count, $expected_count, $message); diff --git a/core/modules/file/tests/src/Functional/FileFieldDisplayTest.php b/core/modules/file/tests/src/Functional/FileFieldDisplayTest.php index 15130fdae53..2fa7f51e3ea 100644 --- a/core/modules/file/tests/src/Functional/FileFieldDisplayTest.php +++ b/core/modules/file/tests/src/Functional/FileFieldDisplayTest.php @@ -51,7 +51,7 @@ class FileFieldDisplayTest extends FileFieldTestBase { } $this->drupalPostForm("admin/structure/types/manage/$type_name/display", $edit, t('Save')); $this->drupalGet('node/' . $node->id()); - $this->assertNoText($field_name, format_string('Field label is hidden when no file attached for formatter %formatter', ['%formatter' => $formatter])); + $this->assertNoText($field_name, new FormattableMarkup('Field label is hidden when no file attached for formatter %formatter', ['%formatter' => $formatter])); } $this->generateFile('escaped-&-text', 64, 10, 'text'); diff --git a/core/modules/file/tests/src/Functional/FileFieldPathTest.php b/core/modules/file/tests/src/Functional/FileFieldPathTest.php index 1a909f308ff..5acc0d9eb42 100644 --- a/core/modules/file/tests/src/Functional/FileFieldPathTest.php +++ b/core/modules/file/tests/src/Functional/FileFieldPathTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\file\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\file\Entity\File; /** @@ -37,7 +38,7 @@ class FileFieldPathTest extends FileFieldTestBase { $date_formatter->format(REQUEST_TIME, 'custom', 'Y') . '-' . $date_formatter->format(REQUEST_TIME, 'custom', 'm') . '/' . $test_file->getFilename(); - $this->assertPathMatch($expected_filename, $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', ['%file' => $node_file->getFileUri()])); + $this->assertPathMatch($expected_filename, $node_file->getFileUri(), new FormattableMarkup('The file %file was uploaded to the correct path.', ['%file' => $node_file->getFileUri()])); // Change the path to contain multiple subdirectories. $this->updateFileField($field_name, $type_name, ['file_directory' => 'foo/bar/baz']); @@ -49,7 +50,7 @@ class FileFieldPathTest extends FileFieldTestBase { $node_storage->resetCache([$nid]); $node = $node_storage->load($nid); $node_file = File::load($node->{$field_name}->target_id); - $this->assertPathMatch('public://foo/bar/baz/' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', ['%file' => $node_file->getFileUri()])); + $this->assertPathMatch('public://foo/bar/baz/' . $test_file->getFilename(), $node_file->getFileUri(), new FormattableMarkup('The file %file was uploaded to the correct path.', ['%file' => $node_file->getFileUri()])); // Check the path when used with tokens. // Change the path to contain multiple token directories. @@ -66,7 +67,7 @@ class FileFieldPathTest extends FileFieldTestBase { // the user running the test case. $data = ['user' => $this->adminUser]; $subdirectory = \Drupal::token()->replace('[user:uid]/[user:name]', $data); - $this->assertPathMatch('public://' . $subdirectory . '/' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path with token replacements.', ['%file' => $node_file->getFileUri()])); + $this->assertPathMatch('public://' . $subdirectory . '/' . $test_file->getFilename(), $node_file->getFileUri(), new FormattableMarkup('The file %file was uploaded to the correct path with token replacements.', ['%file' => $node_file->getFileUri()])); } /** diff --git a/core/modules/file/tests/src/Functional/FileFieldTestBase.php b/core/modules/file/tests/src/Functional/FileFieldTestBase.php index 76272ac5b18..d738c9ab72a 100644 --- a/core/modules/file/tests/src/Functional/FileFieldTestBase.php +++ b/core/modules/file/tests/src/Functional/FileFieldTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\file\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldConfig; use Drupal\file\FileInterface; @@ -217,7 +218,7 @@ abstract class FileFieldTestBase extends BrowserTestBase { @trigger_error('Passing a File entity as $file argument to FileFieldTestBase::assertFileExists is deprecated in drupal:8.8.0. It will be removed from drupal:9.0.0. Instead, pass the File entity URI via File::getFileUri(). See https://www.drupal.org/node/3057326', E_USER_DEPRECATED); $file = $file->getFileUri(); } - $message = isset($message) ? $message : format_string('File %file exists on the disk.', ['%file' => $file]); + $message = isset($message) ? $message : new FormattableMarkup('File %file exists on the disk.', ['%file' => $file]); parent::assertFileExists($file, $message); } @@ -227,7 +228,7 @@ abstract class FileFieldTestBase extends BrowserTestBase { public function assertFileEntryExists($file, $message = NULL) { $this->container->get('entity_type.manager')->getStorage('file')->resetCache(); $db_file = File::load($file->id()); - $message = isset($message) ? $message : format_string('File %file exists in database at the correct path.', ['%file' => $file->getFileUri()]); + $message = isset($message) ? $message : new FormattableMarkup('File %file exists in database at the correct path.', ['%file' => $file->getFileUri()]); $this->assertEqual($db_file->getFileUri(), $file->getFileUri(), $message); } @@ -249,7 +250,7 @@ abstract class FileFieldTestBase extends BrowserTestBase { @trigger_error('Passing a File entity as $file argument to FileFieldTestBase::assertFileNotExists is deprecated in drupal:8.8.0. It will be removed from drupal:9.0.0. Instead, pass the File entity URI via File::getFileUri(). See https://www.drupal.org/node/3057326', E_USER_DEPRECATED); $file = $file->getFileUri(); } - $message = isset($message) ? $message : format_string('File %file exists on the disk.', ['%file' => $file]); + $message = isset($message) ? $message : new FormattableMarkup('File %file exists on the disk.', ['%file' => $file]); parent::assertFileNotExists($file, $message); } @@ -258,7 +259,7 @@ abstract class FileFieldTestBase extends BrowserTestBase { */ public function assertFileEntryNotExists($file, $message) { $this->container->get('entity_type.manager')->getStorage('file')->resetCache(); - $message = isset($message) ? $message : format_string('File %file exists in database at the correct path.', ['%file' => $file->getFileUri()]); + $message = isset($message) ? $message : new FormattableMarkup('File %file exists in database at the correct path.', ['%file' => $file->getFileUri()]); $this->assertFalse(File::load($file->id()), $message); } @@ -266,7 +267,7 @@ abstract class FileFieldTestBase extends BrowserTestBase { * Asserts that a file's status is set to permanent in the database. */ public function assertFileIsPermanent(FileInterface $file, $message = NULL) { - $message = isset($message) ? $message : format_string('File %file is permanent.', ['%file' => $file->getFileUri()]); + $message = isset($message) ? $message : new FormattableMarkup('File %file is permanent.', ['%file' => $file->getFileUri()]); $this->assertTrue($file->isPermanent(), $message); } diff --git a/core/modules/file/tests/src/Functional/FileFieldValidateTest.php b/core/modules/file/tests/src/Functional/FileFieldValidateTest.php index 56502f458d8..ec7b99d63df 100644 --- a/core/modules/file/tests/src/Functional/FileFieldValidateTest.php +++ b/core/modules/file/tests/src/Functional/FileFieldValidateTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\file\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\field\Entity\FieldConfig; use Drupal\file\Entity\File; @@ -34,7 +35,7 @@ class FileFieldValidateTest extends FileFieldTestBase { // Create a new node with the uploaded file. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); - $this->assertTrue($nid !== FALSE, format_string('uploadNodeFile(@test_file, @field_name, @type_name) succeeded', ['@test_file' => $test_file->getFileUri(), '@field_name' => $field_name, '@type_name' => $type_name])); + $this->assertTrue($nid !== FALSE, new FormattableMarkup('uploadNodeFile(@test_file, @field_name, @type_name) succeeded', ['@test_file' => $test_file->getFileUri(), '@field_name' => $field_name, '@type_name' => $type_name])); $node_storage->resetCache([$nid]); $node = $node_storage->load($nid); @@ -92,13 +93,13 @@ class FileFieldValidateTest extends FileFieldTestBase { $node_storage->resetCache([$nid]); $node = $node_storage->load($nid); $node_file = File::load($node->{$field_name}->target_id); - $this->assertFileExists($node_file->getFileUri(), format_string('File exists after uploading a file (%filesize) under the max limit (%maxsize).', ['%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize])); - $this->assertFileEntryExists($node_file, format_string('File entry exists after uploading a file (%filesize) under the max limit (%maxsize).', ['%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize])); + $this->assertFileExists($node_file->getFileUri(), new FormattableMarkup('File exists after uploading a file (%filesize) under the max limit (%maxsize).', ['%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize])); + $this->assertFileEntryExists($node_file, new FormattableMarkup('File entry exists after uploading a file (%filesize) under the max limit (%maxsize).', ['%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize])); // Check that uploading the large file fails (1M limit). $this->uploadNodeFile($large_file, $field_name, $type_name); $error_message = t('The file is %filesize exceeding the maximum file size of %maxsize.', ['%filesize' => format_size($large_file->getSize()), '%maxsize' => format_size($file_limit)]); - $this->assertRaw($error_message, format_string('Node save failed when file (%filesize) exceeded the max upload size (%maxsize).', ['%filesize' => format_size($large_file->getSize()), '%maxsize' => $max_filesize])); + $this->assertRaw($error_message, new FormattableMarkup('Node save failed when file (%filesize) exceeded the max upload size (%maxsize).', ['%filesize' => format_size($large_file->getSize()), '%maxsize' => $max_filesize])); } // Turn off the max filesize. @@ -109,8 +110,8 @@ class FileFieldValidateTest extends FileFieldTestBase { $node_storage->resetCache([$nid]); $node = $node_storage->load($nid); $node_file = File::load($node->{$field_name}->target_id); - $this->assertFileExists($node_file->getFileUri(), format_string('File exists after uploading a file (%filesize) with no max limit.', ['%filesize' => format_size($large_file->getSize())])); - $this->assertFileEntryExists($node_file, format_string('File entry exists after uploading a file (%filesize) with no max limit.', ['%filesize' => format_size($large_file->getSize())])); + $this->assertFileExists($node_file->getFileUri(), new FormattableMarkup('File exists after uploading a file (%filesize) with no max limit.', ['%filesize' => format_size($large_file->getSize())])); + $this->assertFileEntryExists($node_file, new FormattableMarkup('File entry exists after uploading a file (%filesize) with no max limit.', ['%filesize' => format_size($large_file->getSize())])); } /** diff --git a/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php b/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php index 52d8821f529..781208a91f0 100644 --- a/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php +++ b/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\file\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\comment\Entity\Comment; use Drupal\comment\Tests\CommentTestTrait; use Drupal\Component\Serialization\Json; @@ -160,7 +161,7 @@ class FileFieldWidgetTest extends FileFieldTestBase { // Ensure we have the expected number of Remove buttons, and that they // are numbered sequentially. $buttons = $this->xpath('//input[@type="submit" and @value="Remove"]'); - $this->assertTrue(is_array($buttons) && count($buttons) === $num_expected_remove_buttons, format_string('There are %n "Remove" buttons displayed.', ['%n' => $num_expected_remove_buttons])); + $this->assertTrue(is_array($buttons) && count($buttons) === $num_expected_remove_buttons, new FormattableMarkup('There are %n "Remove" buttons displayed.', ['%n' => $num_expected_remove_buttons])); foreach ($buttons as $i => $button) { $key = $i >= $remaining ? $i - $remaining : $i; $check_field_name = $field_name2; diff --git a/core/modules/file/tests/src/Functional/FileManagedTestBase.php b/core/modules/file/tests/src/Functional/FileManagedTestBase.php index 3d17e927efa..61099ea1c30 100644 --- a/core/modules/file/tests/src/Functional/FileManagedTestBase.php +++ b/core/modules/file/tests/src/Functional/FileManagedTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\file\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\file\Entity\File; use Drupal\file\FileInterface; use Drupal\Tests\BrowserTestBase; @@ -42,16 +43,16 @@ abstract class FileManagedTestBase extends BrowserTestBase { // Determine if there were any expected that were not called. $uncalled = array_diff($expected, $actual); if (count($uncalled)) { - $this->assertTrue(FALSE, format_string('Expected hooks %expected to be called but %uncalled was not called.', ['%expected' => implode(', ', $expected), '%uncalled' => implode(', ', $uncalled)])); + $this->assertTrue(FALSE, new FormattableMarkup('Expected hooks %expected to be called but %uncalled was not called.', ['%expected' => implode(', ', $expected), '%uncalled' => implode(', ', $uncalled)])); } else { - $this->assertTrue(TRUE, format_string('All the expected hooks were called: %expected', ['%expected' => empty($expected) ? '(none)' : implode(', ', $expected)])); + $this->assertTrue(TRUE, new FormattableMarkup('All the expected hooks were called: %expected', ['%expected' => empty($expected) ? '(none)' : implode(', ', $expected)])); } // Determine if there were any unexpected calls. $unexpected = array_diff($actual, $expected); if (count($unexpected)) { - $this->assertTrue(FALSE, format_string('Unexpected hooks were called: %unexpected.', ['%unexpected' => empty($unexpected) ? '(none)' : implode(', ', $unexpected)])); + $this->assertTrue(FALSE, new FormattableMarkup('Unexpected hooks were called: %unexpected.', ['%unexpected' => empty($unexpected) ? '(none)' : implode(', ', $unexpected)])); } else { $this->assertTrue(TRUE, 'No unexpected hooks were called.'); @@ -73,13 +74,13 @@ abstract class FileManagedTestBase extends BrowserTestBase { if (!isset($message)) { if ($actual_count == $expected_count) { - $message = format_string('hook_file_@name was called correctly.', ['@name' => $hook]); + $message = new FormattableMarkup('hook_file_@name was called correctly.', ['@name' => $hook]); } elseif ($expected_count == 0) { $message = \Drupal::translation()->formatPlural($actual_count, 'hook_file_@name was not expected to be called but was actually called once.', 'hook_file_@name was not expected to be called but was actually called @count times.', ['@name' => $hook, '@count' => $actual_count]); } else { - $message = format_string('hook_file_@name was expected to be called %expected times but was called %actual times.', ['@name' => $hook, '%expected' => $expected_count, '%actual' => $actual_count]); + $message = new FormattableMarkup('hook_file_@name was expected to be called %expected times but was called %actual times.', ['@name' => $hook, '%expected' => $expected_count, '%actual' => $actual_count]); } } $this->assertEqual($actual_count, $expected_count, $message); diff --git a/core/modules/file/tests/src/Functional/FileTokenReplaceTest.php b/core/modules/file/tests/src/Functional/FileTokenReplaceTest.php index 3f8ad074271..14759e98569 100644 --- a/core/modules/file/tests/src/Functional/FileTokenReplaceTest.php +++ b/core/modules/file/tests/src/Functional/FileTokenReplaceTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\file\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Html; use Drupal\Core\Render\BubbleableMetadata; use Drupal\file\Entity\File; @@ -81,7 +82,7 @@ class FileTokenReplaceTest extends FileFieldTestBase { foreach ($tests as $input => $expected) { $bubbleable_metadata = new BubbleableMetadata(); $output = $token_service->replace($input, ['file' => $file], ['langcode' => $language_interface->getId()], $bubbleable_metadata); - $this->assertEqual($output, $expected, format_string('Sanitized file token %token replaced.', ['%token' => $input])); + $this->assertEqual($output, $expected, new FormattableMarkup('Sanitized file token %token replaced.', ['%token' => $input])); $this->assertEqual($bubbleable_metadata, $metadata_tests[$input]); } @@ -93,7 +94,7 @@ class FileTokenReplaceTest extends FileFieldTestBase { foreach ($tests as $input => $expected) { $output = $token_service->replace($input, ['file' => $file], ['langcode' => $language_interface->getId(), 'sanitize' => FALSE]); - $this->assertEqual($output, $expected, format_string('Unsanitized file token %token replaced.', ['%token' => $input])); + $this->assertEqual($output, $expected, new FormattableMarkup('Unsanitized file token %token replaced.', ['%token' => $input])); } } diff --git a/core/modules/file/tests/src/FunctionalJavascript/FileFieldWidgetTest.php b/core/modules/file/tests/src/FunctionalJavascript/FileFieldWidgetTest.php index 689ca792cb3..c0d2fc53e04 100644 --- a/core/modules/file/tests/src/FunctionalJavascript/FileFieldWidgetTest.php +++ b/core/modules/file/tests/src/FunctionalJavascript/FileFieldWidgetTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\file\FunctionalJavascript; +use Drupal\Component\Render\FormattableMarkup; use Drupal\file\Entity\File; use Drupal\FunctionalJavascriptTests\WebDriverTestBase; use Drupal\Tests\field_ui\Traits\FieldUiTestTrait; @@ -83,7 +84,7 @@ class FileFieldWidgetTest extends WebDriverTestBase { // Ensure we have the expected number of Remove buttons, and that they // are numbered sequentially. $buttons = $this->xpath('//input[@type="submit" and @value="Remove"]'); - $this->assertTrue(is_array($buttons) && count($buttons) === $num_expected_remove_buttons, format_string('There are %n "Remove" buttons displayed.', ['%n' => $num_expected_remove_buttons])); + $this->assertTrue(is_array($buttons) && count($buttons) === $num_expected_remove_buttons, new FormattableMarkup('There are %n "Remove" buttons displayed.', ['%n' => $num_expected_remove_buttons])); foreach ($buttons as $i => $button) { $key = $i >= $remaining ? $i - $remaining : $i; $check_field_name = $field_name2; diff --git a/core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php b/core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php index 34d501726ff..da8194a8d6f 100644 --- a/core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php +++ b/core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\file\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\file\Entity\File; use Drupal\file\FileInterface; use Drupal\KernelTests\KernelTestBase; @@ -55,16 +56,16 @@ abstract class FileManagedUnitTestBase extends KernelTestBase { // Determine if there were any expected that were not called. $uncalled = array_diff($expected, $actual); if (count($uncalled)) { - $this->assertTrue(FALSE, format_string('Expected hooks %expected to be called but %uncalled was not called.', ['%expected' => implode(', ', $expected), '%uncalled' => implode(', ', $uncalled)])); + $this->assertTrue(FALSE, new FormattableMarkup('Expected hooks %expected to be called but %uncalled was not called.', ['%expected' => implode(', ', $expected), '%uncalled' => implode(', ', $uncalled)])); } else { - $this->assertTrue(TRUE, format_string('All the expected hooks were called: %expected', ['%expected' => empty($expected) ? '(none)' : implode(', ', $expected)])); + $this->assertTrue(TRUE, new FormattableMarkup('All the expected hooks were called: %expected', ['%expected' => empty($expected) ? '(none)' : implode(', ', $expected)])); } // Determine if there were any unexpected calls. $unexpected = array_diff($actual, $expected); if (count($unexpected)) { - $this->assertTrue(FALSE, format_string('Unexpected hooks were called: %unexpected.', ['%unexpected' => empty($unexpected) ? '(none)' : implode(', ', $unexpected)])); + $this->assertTrue(FALSE, new FormattableMarkup('Unexpected hooks were called: %unexpected.', ['%unexpected' => empty($unexpected) ? '(none)' : implode(', ', $unexpected)])); } else { $this->assertTrue(TRUE, 'No unexpected hooks were called.'); @@ -86,13 +87,13 @@ abstract class FileManagedUnitTestBase extends KernelTestBase { if (!isset($message)) { if ($actual_count == $expected_count) { - $message = format_string('hook_file_@name was called correctly.', ['@name' => $hook]); + $message = new FormattableMarkup('hook_file_@name was called correctly.', ['@name' => $hook]); } elseif ($expected_count == 0) { $message = \Drupal::translation()->formatPlural($actual_count, 'hook_file_@name was not expected to be called but was actually called once.', 'hook_file_@name was not expected to be called but was actually called @count times.', ['@name' => $hook, '@count' => $actual_count]); } else { - $message = format_string('hook_file_@name was expected to be called %expected times but was called %actual times.', ['@name' => $hook, '%expected' => $expected_count, '%actual' => $actual_count]); + $message = new FormattableMarkup('hook_file_@name was expected to be called %expected times but was called %actual times.', ['@name' => $hook, '%expected' => $expected_count, '%actual' => $actual_count]); } } $this->assertEqual($actual_count, $expected_count, $message); diff --git a/core/modules/file/tests/src/Kernel/MoveTest.php b/core/modules/file/tests/src/Kernel/MoveTest.php index 72f6801a551..b1fe1f7a42d 100644 --- a/core/modules/file/tests/src/Kernel/MoveTest.php +++ b/core/modules/file/tests/src/Kernel/MoveTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\file\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\file\Entity\File; /** @@ -32,7 +33,7 @@ class MoveTest extends FileManagedUnitTestBase { $this->assertFileHooksCalled(['move', 'load', 'update']); // Make sure we got the same file back. - $this->assertEqual($source->id(), $result->id(), format_string("Source file id's' %fid is unchanged after move.", ['%fid' => $source->id()])); + $this->assertEqual($source->id(), $result->id(), new FormattableMarkup("Source file id's' %fid is unchanged after move.", ['%fid' => $source->id()])); // Reload the file from the database and check that the changes were // actually saved. diff --git a/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestPlaceholders.php b/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestPlaceholders.php index f4745bb5fbf..6e34bd6139f 100644 --- a/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestPlaceholders.php +++ b/core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestPlaceholders.php @@ -2,6 +2,7 @@ namespace Drupal\filter_test\Plugin\Filter; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Security\TrustedCallbackInterface; use Drupal\filter\FilterProcessResult; use Drupal\filter\Plugin\FilterBase; @@ -39,7 +40,7 @@ class FilterTestPlaceholders extends FilterBase implements TrustedCallbackInterf */ public static function renderDynamicThing($thing) { return [ - '#markup' => format_string('This is a dynamic @thing.', ['@thing' => $thing]), + '#markup' => new FormattableMarkup('This is a dynamic @thing.', ['@thing' => $thing]), ]; } diff --git a/core/modules/filter/tests/src/Functional/FilterHtmlImageSecureTest.php b/core/modules/filter/tests/src/Functional/FilterHtmlImageSecureTest.php index 0c14a5cee1d..60ccbc5cc64 100644 --- a/core/modules/filter/tests/src/Functional/FilterHtmlImageSecureTest.php +++ b/core/modules/filter/tests/src/Functional/FilterHtmlImageSecureTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\filter\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\comment\Tests\CommentTestTrait; use Drupal\Core\StreamWrapper\PublicStream; use Drupal\filter\Entity\FilterFormat; @@ -153,7 +154,7 @@ class FilterHtmlImageSecureTest extends BrowserTestBase { $this->assertEqual($element->getAttribute('src'), $converted); } } - $this->assertTrue($found, format_string('@image was found.', ['@image' => $image])); + $this->assertTrue($found, new FormattableMarkup('@image was found.', ['@image' => $image])); } } diff --git a/core/modules/filter/tests/src/Kernel/FilterAPITest.php b/core/modules/filter/tests/src/Kernel/FilterAPITest.php index 3885ec4e5c7..15cc9138fcb 100644 --- a/core/modules/filter/tests/src/Kernel/FilterAPITest.php +++ b/core/modules/filter/tests/src/Kernel/FilterAPITest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\filter\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Session\AnonymousUserSession; use Drupal\Core\TypedData\OptionsProviderInterface; @@ -455,7 +456,7 @@ class FilterAPITest extends EntityKernelTestBase { break; } } - $this->assertTrue($filter_format_violation_found, format_string('Validation violation for invalid value "%invalid_value" found', ['%invalid_value' => $invalid_value])); + $this->assertTrue($filter_format_violation_found, new FormattableMarkup('Validation violation for invalid value "%invalid_value" found', ['%invalid_value' => $invalid_value])); } /** diff --git a/core/modules/filter/tests/src/Kernel/FilterCrudTest.php b/core/modules/filter/tests/src/Kernel/FilterCrudTest.php index b73b180bfe0..f42fff0ccb4 100644 --- a/core/modules/filter/tests/src/Kernel/FilterCrudTest.php +++ b/core/modules/filter/tests/src/Kernel/FilterCrudTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\filter\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\filter\Entity\FilterFormat; use Drupal\KernelTests\KernelTestBase; @@ -94,11 +95,11 @@ class FilterCrudTest extends KernelTestBase { // Verify the loaded filter has all properties. $filter_format = FilterFormat::load($format->id()); - $this->assertEqual($filter_format->id(), $format->id(), format_string('filter_format_load: Proper format id for text format %format.', $t_args)); - $this->assertEqual($filter_format->label(), $format->label(), format_string('filter_format_load: Proper title for text format %format.', $t_args)); - $this->assertEqual($filter_format->get('weight'), $format->get('weight'), format_string('filter_format_load: Proper weight for text format %format.', $t_args)); + $this->assertEqual($filter_format->id(), $format->id(), new FormattableMarkup('filter_format_load: Proper format id for text format %format.', $t_args)); + $this->assertEqual($filter_format->label(), $format->label(), new FormattableMarkup('filter_format_load: Proper title for text format %format.', $t_args)); + $this->assertEqual($filter_format->get('weight'), $format->get('weight'), new FormattableMarkup('filter_format_load: Proper weight for text format %format.', $t_args)); // Check that the filter was created in site default language. - $this->assertEqual($format->language()->getId(), $default_langcode, format_string('filter_format_load: Proper language code for text format %format.', $t_args)); + $this->assertEqual($format->language()->getId(), $default_langcode, new FormattableMarkup('filter_format_load: Proper language code for text format %format.', $t_args)); } } diff --git a/core/modules/filter/tests/src/Kernel/FilterKernelTest.php b/core/modules/filter/tests/src/Kernel/FilterKernelTest.php index b8626aedae4..f9aeeb9523f 100644 --- a/core/modules/filter/tests/src/Kernel/FilterKernelTest.php +++ b/core/modules/filter/tests/src/Kernel/FilterKernelTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\filter\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Html; use Drupal\Core\Language\Language; use Drupal\Core\Render\RenderContext; @@ -876,14 +877,14 @@ www.example.com with a newline in comments --> foreach ($tasks as $value => $is_expected) { // Not using assertIdentical, since combination with strpos() is hard to grok. if ($is_expected) { - $success = $this->assertTrue(strpos($result, $value) !== FALSE, format_string('@source: @value found. Filtered result: @result.', [ + $success = $this->assertTrue(strpos($result, $value) !== FALSE, new FormattableMarkup('@source: @value found. Filtered result: @result.', [ '@source' => var_export($source, TRUE), '@value' => var_export($value, TRUE), '@result' => var_export($result, TRUE), ])); } else { - $success = $this->assertTrue(strpos($result, $value) === FALSE, format_string('@source: @value not found. Filtered result: @result.', [ + $success = $this->assertTrue(strpos($result, $value) === FALSE, new FormattableMarkup('@source: @value not found. Filtered result: @result.', [ '@source' => var_export($source, TRUE), '@value' => var_export($value, TRUE), '@result' => var_export($result, TRUE), @@ -1066,7 +1067,7 @@ body {color:red} /*--><!]]>*/ </style></p>', - format_string('HTML corrector -- Existing cdata section @pattern_name properly escaped', ['@pattern_name' => '/*<![CDATA[*/']) + new FormattableMarkup('HTML corrector -- Existing cdata section @pattern_name properly escaped', ['@pattern_name' => '/*<![CDATA[*/']) ); $filtered_data = Html::normalize('<p><style> @@ -1085,7 +1086,7 @@ body {color:red} /*--><!]]>*/ </style></p>', - format_string('HTML corrector -- Existing cdata section @pattern_name properly escaped', ['@pattern_name' => '<!--/*--><![CDATA[/* ><!--*/']) + new FormattableMarkup('HTML corrector -- Existing cdata section @pattern_name properly escaped', ['@pattern_name' => '<!--/*--><![CDATA[/* ><!--*/']) ); $filtered_data = Html::normalize('<p><script> @@ -1102,7 +1103,7 @@ body {color:red} //--><!]]> </script></p>', - format_string('HTML corrector -- Existing cdata section @pattern_name properly escaped', ['@pattern_name' => '<!--//--><![CDATA[// ><!--']) + new FormattableMarkup('HTML corrector -- Existing cdata section @pattern_name properly escaped', ['@pattern_name' => '<!--//--><![CDATA[// ><!--']) ); $filtered_data = Html::normalize('<p><script> @@ -1119,7 +1120,7 @@ body {color:red} //--><!]]> </script></p>', - format_string('HTML corrector -- Existing cdata section @pattern_name properly escaped', ['@pattern_name' => '// <![CDATA[']) + new FormattableMarkup('HTML corrector -- Existing cdata section @pattern_name properly escaped', ['@pattern_name' => '// <![CDATA[']) ); } diff --git a/core/modules/forum/tests/src/Functional/ForumBlockTest.php b/core/modules/forum/tests/src/Functional/ForumBlockTest.php index b231f6d0eac..5bbe1998ee1 100644 --- a/core/modules/forum/tests/src/Functional/ForumBlockTest.php +++ b/core/modules/forum/tests/src/Functional/ForumBlockTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\forum\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\comment\Entity\Comment; use Drupal\Tests\BrowserTestBase; @@ -57,7 +58,7 @@ class ForumBlockTest extends BrowserTestBase { // We expect all 5 forum topics to appear in the "New forum topics" block. foreach ($topics as $topic) { - $this->assertLink($topic, 0, format_string('Forum topic @topic found in the "New forum topics" block.', ['@topic' => $topic])); + $this->assertLink($topic, 0, new FormattableMarkup('Forum topic @topic found in the "New forum topics" block.', ['@topic' => $topic])); } // Configure the new forum topics block to only show 2 topics. @@ -69,10 +70,10 @@ class ForumBlockTest extends BrowserTestBase { // topics" block. for ($index = 0; $index < 5; $index++) { if (in_array($index, [3, 4])) { - $this->assertLink($topics[$index], 0, format_string('Forum topic @topic found in the "New forum topics" block.', ['@topic' => $topics[$index]])); + $this->assertLink($topics[$index], 0, new FormattableMarkup('Forum topic @topic found in the "New forum topics" block.', ['@topic' => $topics[$index]])); } else { - $this->assertNoText($topics[$index], format_string('Forum topic @topic not found in the "New forum topics" block.', ['@topic' => $topics[$index]])); + $this->assertNoText($topics[$index], new FormattableMarkup('Forum topic @topic not found in the "New forum topics" block.', ['@topic' => $topics[$index]])); } } } @@ -115,10 +116,10 @@ class ForumBlockTest extends BrowserTestBase { $this->drupalGet('<front>'); for ($index = 0; $index < 10; $index++) { if ($index < 5) { - $this->assertLink($topics[$index], 0, format_string('Forum topic @topic found in the "Active forum topics" block.', ['@topic' => $topics[$index]])); + $this->assertLink($topics[$index], 0, new FormattableMarkup('Forum topic @topic found in the "Active forum topics" block.', ['@topic' => $topics[$index]])); } else { - $this->assertNoText($topics[$index], format_string('Forum topic @topic not found in the "Active forum topics" block.', ['@topic' => $topics[$index]])); + $this->assertNoText($topics[$index], new FormattableMarkup('Forum topic @topic not found in the "Active forum topics" block.', ['@topic' => $topics[$index]])); } } diff --git a/core/modules/forum/tests/src/Functional/ForumTest.php b/core/modules/forum/tests/src/Functional/ForumTest.php index 5eeb67cd3b1..d8417ffd042 100644 --- a/core/modules/forum/tests/src/Functional/ForumTest.php +++ b/core/modules/forum/tests/src/Functional/ForumTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\forum\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Core\Entity\EntityInterface; @@ -427,7 +428,7 @@ class ForumTest extends BrowserTestBase { 'Created new @type @term.', ['@term' => $name, '@type' => t($type)] ), - format_string('@type was created', ['@type' => ucfirst($type)]) + new FormattableMarkup('@type was created', ['@type' => ucfirst($type)]) ); // Verify that the creation message contains a link to a term. @@ -578,7 +579,7 @@ class ForumTest extends BrowserTestBase { // Retrieve node object, ensure that the topic was created and in the proper forum. $node = $this->drupalGetNodeByTitle($title); - $this->assertTrue($node != NULL, format_string('Node @title was loaded', ['@title' => $title])); + $this->assertTrue($node != NULL, new FormattableMarkup('Node @title was loaded', ['@title' => $title])); $this->assertEqual($node->taxonomy_forums->target_id, $tid, 'Saved forum topic was in the expected forum'); // View forum topic. diff --git a/core/modules/help/tests/src/Functional/HelpTest.php b/core/modules/help/tests/src/Functional/HelpTest.php index 029db407da0..8d1e538c176 100644 --- a/core/modules/help/tests/src/Functional/HelpTest.php +++ b/core/modules/help/tests/src/Functional/HelpTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\help\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Tests\BrowserTestBase; /** @@ -76,7 +77,7 @@ class HelpTest extends BrowserTestBase { // Make sure links are properly added for modules implementing hook_help(). foreach ($this->getModuleList() as $module => $name) { - $this->assertLink($name, 0, format_string('Link properly added to @name (admin/help/@module)', ['@module' => $module, '@name' => $name])); + $this->assertLink($name, 0, new FormattableMarkup('Link properly added to @name (admin/help/@module)', ['@module' => $module, '@name' => $name])); } // Ensure that module which does not provide an module overview page is @@ -121,7 +122,7 @@ class HelpTest extends BrowserTestBase { $this->drupalGet('admin/help/' . $module); $this->assertResponse($response); if ($response == 200) { - $this->assertTitle($name . ' | Drupal', format_string('%module title was displayed', ['%module' => $module])); + $this->assertTitle($name . ' | Drupal', new FormattableMarkup('%module title was displayed', ['%module' => $module])); $this->assertEquals($name, $this->cssSelect('h1.page-title')[0]->getText(), "$module heading was displayed"); $admin_tasks = system_get_module_admin_tasks($module, system_get_info('module', $module)); if (!empty($admin_tasks)) { diff --git a/core/modules/image/tests/src/Functional/ImageAdminStylesTest.php b/core/modules/image/tests/src/Functional/ImageAdminStylesTest.php index 2a536d64d9f..eacd7886998 100644 --- a/core/modules/image/tests/src/Functional/ImageAdminStylesTest.php +++ b/core/modules/image/tests/src/Functional/ImageAdminStylesTest.php @@ -61,7 +61,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase { $this->drupalPostForm('admin/config/media/image-styles/add', $edit, t('Create new style')); $this->assertRaw(t('Style %name was created.', ['%name' => $style_label])); $options = image_style_options(); - $this->assertTrue(array_key_exists($style_name, $options), format_string('Array key %key exists.', ['%key' => $style_name])); + $this->assertTrue(array_key_exists($style_name, $options), new FormattableMarkup('Array key %key exists.', ['%key' => $style_name])); } /** @@ -159,7 +159,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase { // Assert that every effect was saved. foreach (array_keys($effect_edits) as $effect_name) { - $this->assertTrue(isset($uuids[$effect_name]), format_string( + $this->assertTrue(isset($uuids[$effect_name]), new FormattableMarkup( 'A %effect_name effect was saved with ID %uuid', [ '%effect_name' => $effect_name, @@ -198,7 +198,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase { // Create an image to make sure it gets flushed after saving. $image_path = $this->createSampleImage($style); - $this->assertEqual($this->getImageCount($style), 1, format_string('Image style %style image %file successfully generated.', ['%style' => $style->label(), '%file' => $image_path])); + $this->assertEqual($this->getImageCount($style), 1, new FormattableMarkup('Image style %style image %file successfully generated.', ['%style' => $style->label(), '%file' => $image_path])); $this->drupalPostForm($style_path, $edit, t('Save')); @@ -208,7 +208,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase { // Check that the URL was updated. $this->drupalGet($style_path); $this->assertTitle(t('Edit style @name | Drupal', ['@name' => $style_label])); - $this->assertResponse(200, format_string('Image style %original renamed to %new', ['%original' => $style->id(), '%new' => $style_name])); + $this->assertResponse(200, new FormattableMarkup('Image style %original renamed to %new', ['%original' => $style->id(), '%new' => $style_name])); // Check that the available image effects are properly sorted. $option = $this->xpath('//select[@id=:id]//option', [':id' => 'edit-new--2']); @@ -217,7 +217,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase { // Check that the image was flushed after updating the style. // This is especially important when renaming the style. Make sure that // the old image directory has been deleted. - $this->assertEqual($this->getImageCount($style), 0, format_string('Image style %style was flushed after renaming the style and updating the order of effects.', ['%style' => $style->label()])); + $this->assertEqual($this->getImageCount($style), 0, new FormattableMarkup('Image style %style was flushed after renaming the style and updating the order of effects.', ['%style' => $style->label()])); // Load the style by the new name with the new weights. $style = ImageStyle::load($style_name); @@ -238,7 +238,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase { // Create an image to make sure it gets flushed after deleting an effect. $image_path = $this->createSampleImage($style); - $this->assertEqual($this->getImageCount($style), 1, format_string('Image style %style image %file successfully generated.', ['%style' => $style->label(), '%file' => $image_path])); + $this->assertEqual($this->getImageCount($style), 1, new FormattableMarkup('Image style %style image %file successfully generated.', ['%style' => $style->label(), '%file' => $image_path])); // Delete the 'image_crop' effect from the style. $this->drupalPostForm($style_path . '/effects/' . $uuids['image_crop'] . '/delete', [], t('Delete')); @@ -252,7 +252,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase { // actually deleted. $entity_type_manager = $this->container->get('entity_type.manager'); $style = $entity_type_manager->getStorage('image_style')->loadUnchanged($style->id()); - $this->assertFalse($style->getEffects()->has($uuids['image_crop']), format_string( + $this->assertFalse($style->getEffects()->has($uuids['image_crop']), new FormattableMarkup( 'Effect with ID %uuid no longer found on image style %style', [ '%uuid' => $uuids['image_crop'], @@ -278,9 +278,9 @@ class ImageAdminStylesTest extends ImageFieldTestBase { // Confirm the style directory has been removed. $directory = 'public://styles/' . $style_name; - $this->assertFalse(is_dir($directory), format_string('Image style %style directory removed on style deletion.', ['%style' => $style->label()])); + $this->assertFalse(is_dir($directory), new FormattableMarkup('Image style %style directory removed on style deletion.', ['%style' => $style->label()])); - $this->assertFalse(ImageStyle::load($style_name), format_string('Image style %style successfully deleted.', ['%style' => $style->label()])); + $this->assertFalse(ImageStyle::load($style_name), new FormattableMarkup('Image style %style successfully deleted.', ['%style' => $style->label()])); // Test empty text when there are no image styles. @@ -330,7 +330,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase { // Test that image is displayed using newly created style. $this->drupalGet('node/' . $nid); - $this->assertRaw(file_url_transform_relative($style->buildUrl($original_uri)), format_string('Image displayed using style @style.', ['@style' => $style_name])); + $this->assertRaw(file_url_transform_relative($style->buildUrl($original_uri)), new FormattableMarkup('Image displayed using style @style.', ['@style' => $style_name])); // Rename the style and make sure the image field is updated. $new_style_name = strtolower($this->randomMachineName(10)); @@ -340,7 +340,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase { 'label' => $new_style_label, ]; $this->drupalPostForm($style_path . $style_name, $edit, t('Save')); - $this->assertText(t('Changes to the style have been saved.'), format_string('Style %name was renamed to %new_name.', ['%name' => $style_name, '%new_name' => $new_style_name])); + $this->assertText(t('Changes to the style have been saved.'), new FormattableMarkup('Style %name was renamed to %new_name.', ['%name' => $style_name, '%new_name' => $new_style_name])); $this->drupalGet('node/' . $nid); // Reload the image style using the new name. @@ -476,7 +476,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase { // Test that image is displayed using newly created style. $this->drupalGet('node/' . $nid); - $this->assertRaw(file_url_transform_relative($style->buildUrl($original_uri)), format_string('Image displayed using style @style.', ['@style' => $style_name])); + $this->assertRaw(file_url_transform_relative($style->buildUrl($original_uri)), new FormattableMarkup('Image displayed using style @style.', ['@style' => $style_name])); // Copy config to sync, and delete the image style. $sync = $this->container->get('config.storage.sync'); diff --git a/core/modules/image/tests/src/Functional/ImageFieldDefaultImagesTest.php b/core/modules/image/tests/src/Functional/ImageFieldDefaultImagesTest.php index 7be3c6fc680..46281918c87 100644 --- a/core/modules/image/tests/src/Functional/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/tests/src/Functional/ImageFieldDefaultImagesTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\image\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\field\Entity\FieldConfig; use Drupal\file\Entity\File; @@ -125,7 +126,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase { $this->assertFieldByXpath( '//input[@name="settings[default_image][uuid][fids]"]', $default_images['field_storage']->id(), - format_string( + new FormattableMarkup( 'Article image field storage default equals expected file ID of @fid.', ['@fid' => $default_images['field_storage']->id()] ) @@ -135,7 +136,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase { $this->assertFieldByXpath( '//input[@name="settings[default_image][uuid][fids]"]', $default_images['field']->id(), - format_string( + new FormattableMarkup( 'Article image field default equals expected file ID of @fid.', ['@fid' => $default_images['field']->id()] ) @@ -146,7 +147,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase { $this->assertFieldByXpath( '//input[@name="settings[default_image][uuid][fids]"]', $default_images['field_storage']->id(), - format_string( + new FormattableMarkup( 'Page image field storage default equals expected file ID of @fid.', ['@fid' => $default_images['field_storage']->id()] ) @@ -157,7 +158,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase { $this->assertFieldByXpath( '//input[@name="settings[default_image][uuid][fids]"]', $default_images['field2']->id(), - format_string( + new FormattableMarkup( 'Page image field default equals expected file ID of @fid.', ['@fid' => $default_images['field2']->id()] ) @@ -169,7 +170,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase { $this->assertEqual( $article_built[$field_name][0]['#item']->target_id, $default_images['field']->id(), - format_string( + new FormattableMarkup( 'A new article node without an image has the expected default image file ID of @fid.', ['@fid' => $default_images['field']->id()] ) @@ -188,7 +189,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase { $this->assertEqual( $page_built[$field_name][0]['#item']->target_id, $default_images['field2']->id(), - format_string( + new FormattableMarkup( 'A new page node without an image has the expected default image file ID of @fid.', ['@fid' => $default_images['field2']->id()] ) @@ -206,7 +207,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase { $this->assertFieldByXpath( '//input[@name="settings[default_image][uuid][fids]"]', $default_images['field_storage_new']->id(), - format_string( + new FormattableMarkup( 'Updated image field storage default equals expected file ID of @fid.', ['@fid' => $default_images['field_storage_new']->id()] ) @@ -219,7 +220,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase { $this->assertEqual( $article_built[$field_name][0]['#item']->target_id, $default_images['field']->id(), - format_string( + new FormattableMarkup( 'An existing article node without an image has the expected default image file ID of @fid.', ['@fid' => $default_images['field']->id()] ) @@ -227,7 +228,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase { $this->assertEqual( $page_built[$field_name][0]['#item']->target_id, $default_images['field2']->id(), - format_string( + new FormattableMarkup( 'An existing page node without an image has the expected default image file ID of @fid.', ['@fid' => $default_images['field2']->id()] ) @@ -244,7 +245,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase { $this->assertFieldByXpath( '//input[@name="settings[default_image][uuid][fids]"]', $default_images['field_new']->id(), - format_string( + new FormattableMarkup( 'Updated article image field default equals expected file ID of @fid.', ['@fid' => $default_images['field_new']->id()] ) @@ -259,7 +260,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase { $this->assertEqual( $article_built[$field_name][0]['#item']->target_id, $default_images['field_new']->id(), - format_string( + new FormattableMarkup( 'An existing article node without an image has the expected default image file ID of @fid.', ['@fid' => $default_images['field_new']->id()] ) @@ -268,7 +269,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase { $this->assertEqual( $page_built[$field_name][0]['#item']->target_id, $default_images['field2']->id(), - format_string( + new FormattableMarkup( 'An existing page node without an image has the expected default image file ID of @fid.', ['@fid' => $default_images['field2']->id()] ) @@ -301,7 +302,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase { $this->assertEqual( $article_built[$field_name][0]['#item']->target_id, $default_images['field_storage_new']->id(), - format_string( + new FormattableMarkup( 'An existing article node without an image has the expected default image file ID of @fid.', ['@fid' => $default_images['field_storage_new']->id()] ) @@ -310,7 +311,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase { $this->assertEqual( $page_built[$field_name][0]['#item']->target_id, $default_images['field2']->id(), - format_string( + new FormattableMarkup( 'An existing page node without an image has the expected default image file ID of @fid.', ['@fid' => $default_images['field2']->id()] ) @@ -340,7 +341,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase { $this->assertFieldByXpath( '//input[@name="settings[default_image][uuid][fids]"]', $default_images['field_storage_private']->id(), - format_string( + new FormattableMarkup( 'Updated image field storage default equals expected file ID of @fid.', ['@fid' => $default_images['field_storage_private']->id()] ) @@ -359,7 +360,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase { $this->assertFieldByXpath( '//input[@name="settings[default_image][uuid][fids]"]', $default_images['field_private']->id(), - format_string( + new FormattableMarkup( 'Updated article image field default equals expected file ID of @fid.', ['@fid' => $default_images['field_private']->id()] ) diff --git a/core/modules/image/tests/src/Functional/ImageFieldDisplayTest.php b/core/modules/image/tests/src/Functional/ImageFieldDisplayTest.php index c716b21ba65..c7f5d8c6358 100644 --- a/core/modules/image/tests/src/Functional/ImageFieldDisplayTest.php +++ b/core/modules/image/tests/src/Functional/ImageFieldDisplayTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\image\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\StreamWrapper\StreamWrapperManager; use Drupal\Core\Url; @@ -331,7 +332,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase { $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save')); // Add the required alt text. $this->drupalPostForm(NULL, [$field_name . '[1][alt]' => $alt], t('Save')); - $this->assertText(format_string('Article @title has been updated.', ['@title' => $node->getTitle()])); + $this->assertText(new FormattableMarkup('Article @title has been updated.', ['@title' => $node->getTitle()])); // Assert ImageWidget::process() calls FieldWidget::process(). $this->drupalGet('node/' . $node->id() . '/edit'); diff --git a/core/modules/image/tests/src/Functional/ImageStyleFlushTest.php b/core/modules/image/tests/src/Functional/ImageStyleFlushTest.php index 00b9615db7a..7410fdc6b37 100644 --- a/core/modules/image/tests/src/Functional/ImageStyleFlushTest.php +++ b/core/modules/image/tests/src/Functional/ImageStyleFlushTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\image\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\image\Entity\ImageStyle; use Drupal\Tests\TestFileCreationTrait; @@ -88,11 +89,11 @@ class ImageStyleFlushTest extends ImageFieldTestBase { $image_path = $this->createSampleImage($style, 'public'); // Expecting to find 2 images, one is the sample.png image shown in // image style preview. - $this->assertEqual($this->getImageCount($style, 'public'), 2, format_string('Image style %style image %file successfully generated.', ['%style' => $style->label(), '%file' => $image_path])); + $this->assertEqual($this->getImageCount($style, 'public'), 2, new FormattableMarkup('Image style %style image %file successfully generated.', ['%style' => $style->label(), '%file' => $image_path])); // Create an image for the 'private' wrapper. $image_path = $this->createSampleImage($style, 'private'); - $this->assertEqual($this->getImageCount($style, 'private'), 1, format_string('Image style %style image %file successfully generated.', ['%style' => $style->label(), '%file' => $image_path])); + $this->assertEqual($this->getImageCount($style, 'private'), 1, new FormattableMarkup('Image style %style image %file successfully generated.', ['%style' => $style->label(), '%file' => $image_path])); // Remove the 'image_scale' effect and updates the style, which in turn // forces an image style flush. @@ -107,10 +108,10 @@ class ImageStyleFlushTest extends ImageFieldTestBase { $this->assertResponse(200); // Post flush, expected 1 image in the 'public' wrapper (sample.png). - $this->assertEqual($this->getImageCount($style, 'public'), 1, format_string('Image style %style flushed correctly for %wrapper wrapper.', ['%style' => $style->label(), '%wrapper' => 'public'])); + $this->assertEqual($this->getImageCount($style, 'public'), 1, new FormattableMarkup('Image style %style flushed correctly for %wrapper wrapper.', ['%style' => $style->label(), '%wrapper' => 'public'])); // Post flush, expected no image in the 'private' wrapper. - $this->assertEqual($this->getImageCount($style, 'private'), 0, format_string('Image style %style flushed correctly for %wrapper wrapper.', ['%style' => $style->label(), '%wrapper' => 'private'])); + $this->assertEqual($this->getImageCount($style, 'private'), 0, new FormattableMarkup('Image style %style flushed correctly for %wrapper wrapper.', ['%style' => $style->label(), '%wrapper' => 'private'])); } } diff --git a/core/modules/language/tests/src/Functional/LanguageConfigurationTest.php b/core/modules/language/tests/src/Functional/LanguageConfigurationTest.php index 639b4d95825..777ff110e82 100644 --- a/core/modules/language/tests/src/Functional/LanguageConfigurationTest.php +++ b/core/modules/language/tests/src/Functional/LanguageConfigurationTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\language\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Url; use Drupal\Core\Language\LanguageInterface; use Drupal\language\Entity\ConfigurableLanguage; @@ -189,7 +190,7 @@ class LanguageConfigurationTest extends BrowserTestBase { $replacements = ['@event' => $state]; foreach (\Drupal::languageManager()->getLanguages(LanguageInterface::STATE_LOCKED) as $locked_language) { $replacements['%language'] = $locked_language->getName(); - $this->assertTrue($locked_language->getWeight() > $max_configurable_language_weight, format_string('System language %language has higher weight than configurable languages @event', $replacements)); + $this->assertTrue($locked_language->getWeight() > $max_configurable_language_weight, new FormattableMarkup('System language %language has higher weight than configurable languages @event', $replacements)); } } diff --git a/core/modules/language/tests/src/Functional/LanguageNegotiationInfoTest.php b/core/modules/language/tests/src/Functional/LanguageNegotiationInfoTest.php index c5e3c2c7b1e..374f748e1e3 100644 --- a/core/modules/language/tests/src/Functional/LanguageNegotiationInfoTest.php +++ b/core/modules/language/tests/src/Functional/LanguageNegotiationInfoTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\language\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Language\LanguageInterface; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI; use Drupal\Tests\BrowserTestBase; @@ -112,10 +113,10 @@ class LanguageNegotiationInfoTest extends BrowserTestBase { foreach ($this->languageManager()->getLanguageTypes() as $type) { $form_field = $type . '[enabled][test_language_negotiation_method_ts]'; if ($type == $test_type) { - $this->assertFieldByName($form_field, NULL, format_string('Type-specific test language negotiation method available for %type.', ['%type' => $type])); + $this->assertFieldByName($form_field, NULL, new FormattableMarkup('Type-specific test language negotiation method available for %type.', ['%type' => $type])); } else { - $this->assertNoFieldByName($form_field, NULL, format_string('Type-specific test language negotiation method unavailable for %type.', ['%type' => $type])); + $this->assertNoFieldByName($form_field, NULL, new FormattableMarkup('Type-specific test language negotiation method unavailable for %type.', ['%type' => $type])); } } @@ -125,7 +126,7 @@ class LanguageNegotiationInfoTest extends BrowserTestBase { foreach ($this->languageManager()->getDefinedLanguageTypes() as $type) { $langcode = $last[$type]; $value = $type == LanguageInterface::TYPE_CONTENT || strpos($type, 'test') !== FALSE ? 'it' : 'en'; - $this->assertEqual($langcode, $value, format_string('The negotiated language for %type is %language', ['%type' => $type, '%language' => $value])); + $this->assertEqual($langcode, $value, new FormattableMarkup('The negotiated language for %type is %language', ['%type' => $type, '%language' => $value])); } // Uninstall language_test and check that everything is set back to the @@ -135,7 +136,7 @@ class LanguageNegotiationInfoTest extends BrowserTestBase { // Check that only the core language types are available. foreach ($this->languageManager()->getDefinedLanguageTypes() as $type) { - $this->assertTrue(strpos($type, 'test') === FALSE, format_string('The %type language is still available', ['%type' => $type])); + $this->assertTrue(strpos($type, 'test') === FALSE, new FormattableMarkup('The %type language is still available', ['%type' => $type])); } // Check that fixed language types are properly configured, even those @@ -161,7 +162,7 @@ class LanguageNegotiationInfoTest extends BrowserTestBase { if (!in_array($type, $configurable) && isset($info['fixed'])) { $negotiation = $this->config('language.types')->get('negotiation.' . $type . '.enabled'); $equal = array_keys($negotiation) === array_values($info['fixed']); - $this->assertTrue($equal, format_string('language negotiation for %type is properly set up', ['%type' => $type])); + $this->assertTrue($equal, new FormattableMarkup('language negotiation for %type is properly set up', ['%type' => $type])); } } } diff --git a/core/modules/language/tests/src/Functional/LanguageUILanguageNegotiationTest.php b/core/modules/language/tests/src/Functional/LanguageUILanguageNegotiationTest.php index 23f2ec5c205..57a6ab66ba2 100644 --- a/core/modules/language/tests/src/Functional/LanguageUILanguageNegotiationTest.php +++ b/core/modules/language/tests/src/Functional/LanguageUILanguageNegotiationTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\language\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Cache\Cache; use Drupal\Core\Url; use Drupal\file\Entity\File; @@ -513,19 +514,19 @@ class LanguageUILanguageNegotiationTest extends BrowserTestBase { $italian_url = Url::fromRoute('system.admin', [], ['language' => $languages['it']])->toString(); $url_scheme = \Drupal::request()->isSecure() ? 'https://' : 'http://'; $correct_link = $url_scheme . $link; - $this->assertEqual($italian_url, $correct_link, format_string('The right URL (@url) in accordance with the chosen language', ['@url' => $italian_url])); + $this->assertEqual($italian_url, $correct_link, new FormattableMarkup('The right URL (@url) in accordance with the chosen language', ['@url' => $italian_url])); // Test HTTPS via options. $italian_url = Url::fromRoute('system.admin', [], ['https' => TRUE, 'language' => $languages['it']])->toString(); $correct_link = 'https://' . $link; - $this->assertTrue($italian_url == $correct_link, format_string('The right HTTPS URL (via options) (@url) in accordance with the chosen language', ['@url' => $italian_url])); + $this->assertTrue($italian_url == $correct_link, new FormattableMarkup('The right HTTPS URL (via options) (@url) in accordance with the chosen language', ['@url' => $italian_url])); // Test HTTPS via current URL scheme. $request = Request::create('', 'GET', [], [], [], ['HTTPS' => 'on']); $this->container->get('request_stack')->push($request); $italian_url = Url::fromRoute('system.admin', [], ['language' => $languages['it']])->toString(); $correct_link = 'https://' . $link; - $this->assertTrue($italian_url == $correct_link, format_string('The right URL (via current URL scheme) (@url) in accordance with the chosen language', ['@url' => $italian_url])); + $this->assertTrue($italian_url == $correct_link, new FormattableMarkup('The right URL (via current URL scheme) (@url) in accordance with the chosen language', ['@url' => $italian_url])); } /** diff --git a/core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php b/core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php index 8328c746e11..6db85764962 100644 --- a/core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php +++ b/core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\locale\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Url; use Drupal\Core\Database\Database; use Drupal\Tests\BrowserTestBase; @@ -326,7 +327,7 @@ class LocaleImportFunctionalTest extends BrowserTestBase { 'translation' => 'all', ]; $this->drupalPostForm('admin/config/regional/translate', $search, t('Filter')); - $this->assertText($config_string[1], format_string('Translation of @string found.', ['@string' => $config_string[0]])); + $this->assertText($config_string[1], new FormattableMarkup('Translation of @string found.', ['@string' => $config_string[0]])); } // Test that translations got recorded in the config system. diff --git a/core/modules/locale/tests/src/Functional/LocaleUpdateBase.php b/core/modules/locale/tests/src/Functional/LocaleUpdateBase.php index dc22c9be8a8..ab3df49ca56 100644 --- a/core/modules/locale/tests/src/Functional/LocaleUpdateBase.php +++ b/core/modules/locale/tests/src/Functional/LocaleUpdateBase.php @@ -303,7 +303,7 @@ EOF; protected function assertTranslation($source, $translation, $langcode, $message = '') { $db_translation = Database::getConnection()->query('SELECT translation FROM {locales_target} lt INNER JOIN {locales_source} ls ON ls.lid = lt.lid WHERE ls.source = :source AND lt.language = :langcode', [':source' => $source, ':langcode' => $langcode])->fetchField(); $db_translation = $db_translation == FALSE ? '' : $db_translation; - $this->assertEqual($translation, $db_translation, $message ? $message : format_string('Correct translation of %source (%language)', ['%source' => $source, '%language' => $langcode])); + $this->assertEqual($translation, $db_translation, $message ? $message : new FormattableMarkup('Correct translation of %source (%language)', ['%source' => $source, '%language' => $langcode])); } } diff --git a/core/modules/node/src/Tests/NodeTestBase.php b/core/modules/node/src/Tests/NodeTestBase.php index 08e33e6f22d..df879ae67e6 100644 --- a/core/modules/node/src/Tests/NodeTestBase.php +++ b/core/modules/node/src/Tests/NodeTestBase.php @@ -4,6 +4,7 @@ namespace Drupal\node\Tests; @trigger_error(__NAMESPACE__ . '\NodeTestBase is deprecated for removal before Drupal 9.0.0. Use Drupal\Tests\node\Functional\NodeTestBase instead. See https://www.drupal.org/node/2999939', E_USER_DEPRECATED); +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Session\AccountInterface; use Drupal\node\NodeInterface; use Drupal\simpletest\WebTestBase; @@ -104,7 +105,7 @@ abstract class NodeTestBase extends WebTestBase { * about the node access permission test that was performed. */ public function nodeAccessAssertMessage($operation, $result, $langcode = NULL) { - return format_string( + return new FormattableMarkup( 'Node access returns @result with operation %op, language code %langcode.', [ '@result' => $result ? 'true' : 'false', diff --git a/core/modules/node/tests/src/Functional/NodeLoadMultipleTest.php b/core/modules/node/tests/src/Functional/NodeLoadMultipleTest.php index 2da5d1bbeb5..f19d7054488 100644 --- a/core/modules/node/tests/src/Functional/NodeLoadMultipleTest.php +++ b/core/modules/node/tests/src/Functional/NodeLoadMultipleTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\node\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\node\Entity\Node; /** @@ -45,12 +46,12 @@ class NodeLoadMultipleTest extends NodeTestBase { $this->assertEqual($node3->label(), $nodes[$node3->id()]->label(), 'Node was loaded.'); $this->assertEqual($node4->label(), $nodes[$node4->id()]->label(), 'Node was loaded.'); $count = count($nodes); - $this->assertTrue($count == 2, format_string('@count nodes loaded.', ['@count' => $count])); + $this->assertTrue($count == 2, new FormattableMarkup('@count nodes loaded.', ['@count' => $count])); // Load nodes by nid. Nodes 1, 2 and 4 will be loaded. $nodes = Node::loadMultiple([1, 2, 4]); $count = count($nodes); - $this->assertTrue(count($nodes) == 3, format_string('@count nodes loaded', ['@count' => $count])); + $this->assertTrue(count($nodes) == 3, new FormattableMarkup('@count nodes loaded', ['@count' => $count])); $this->assertTrue(isset($nodes[$node1->id()]), 'Node is correctly keyed in the array'); $this->assertTrue(isset($nodes[$node2->id()]), 'Node is correctly keyed in the array'); $this->assertTrue(isset($nodes[$node4->id()]), 'Node is correctly keyed in the array'); diff --git a/core/modules/node/tests/src/Functional/NodeTestBase.php b/core/modules/node/tests/src/Functional/NodeTestBase.php index 264ac31535e..a05552cccd2 100644 --- a/core/modules/node/tests/src/Functional/NodeTestBase.php +++ b/core/modules/node/tests/src/Functional/NodeTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\node\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Session\AccountInterface; use Drupal\node\NodeInterface; use Drupal\Tests\BrowserTestBase; @@ -97,7 +98,7 @@ abstract class NodeTestBase extends BrowserTestBase { * about the node access permission test that was performed. */ public function nodeAccessAssertMessage($operation, $result, $langcode = NULL) { - return format_string( + return new FormattableMarkup( 'Node access returns @result with operation %op, language code %langcode.', [ '@result' => $result ? 'true' : 'false', diff --git a/core/modules/node/tests/src/Functional/NodeTranslationUITest.php b/core/modules/node/tests/src/Functional/NodeTranslationUITest.php index cf81e50113f..9bff2bce2ed 100644 --- a/core/modules/node/tests/src/Functional/NodeTranslationUITest.php +++ b/core/modules/node/tests/src/Functional/NodeTranslationUITest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\node\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Database\Database; use Drupal\Core\Entity\EntityInterface; use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase; @@ -372,7 +373,7 @@ class NodeTranslationUITest extends ContentTranslationUITestBase { $languages = $this->container->get('language_manager')->getLanguages(); foreach ($this->langcodes as $langcode) { $this->drupalGet($path, ['language' => $languages[$langcode]]); - $this->assertText($values[$langcode]['title'][0]['value'], format_string('The %langcode node translation is correctly displayed.', ['%langcode' => $langcode])); + $this->assertText($values[$langcode]['title'][0]['value'], new FormattableMarkup('The %langcode node translation is correctly displayed.', ['%langcode' => $langcode])); } } @@ -396,7 +397,7 @@ class NodeTranslationUITest extends ContentTranslationUITestBase { // Retrieve desired link elements from the HTML head. $links = $this->xpath('head/link[@rel = "alternate" and @href = :href and @hreflang = :hreflang]', [':href' => $language_url->toString(), ':hreflang' => $alternate_langcode]); - $this->assert(isset($links[0]), format_string('The %langcode node translation has the correct alternate hreflang link for %alternate_langcode: %link.', ['%langcode' => $langcode, '%alternate_langcode' => $alternate_langcode, '%link' => $url->toString()])); + $this->assert(isset($links[0]), new FormattableMarkup('The %langcode node translation has the correct alternate hreflang link for %alternate_langcode: %link.', ['%langcode' => $langcode, '%alternate_langcode' => $alternate_langcode, '%link' => $url->toString()])); } } } diff --git a/core/modules/node/tests/src/Functional/Views/FrontPageTest.php b/core/modules/node/tests/src/Functional/Views/FrontPageTest.php index 29fd702d963..062bbe010fd 100644 --- a/core/modules/node/tests/src/Functional/Views/FrontPageTest.php +++ b/core/modules/node/tests/src/Functional/Views/FrontPageTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\node\Functional\Views; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Cache\Cache; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Url; @@ -77,7 +78,7 @@ class FrontPageTest extends ViewTestBase { $this->executeView($view); $view->preview(); - $this->assertEqual($view->getTitle(), format_string('Welcome to @site_name', ['@site_name' => $site_name]), 'The welcome title is used for the empty view.'); + $this->assertEqual($view->getTitle(), new FormattableMarkup('Welcome to @site_name', ['@site_name' => $site_name]), 'The welcome title is used for the empty view.'); $view->destroy(); // Create some nodes on the frontpage view. Add more than 10 nodes in order diff --git a/core/modules/node/tests/src/Kernel/NodeAccessRecordsTest.php b/core/modules/node/tests/src/Kernel/NodeAccessRecordsTest.php index 6daf5a91a88..78f46710e44 100644 --- a/core/modules/node/tests/src/Kernel/NodeAccessRecordsTest.php +++ b/core/modules/node/tests/src/Kernel/NodeAccessRecordsTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\node\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Database\Database; use Drupal\node\Entity\Node; @@ -73,7 +74,7 @@ class NodeAccessRecordsTest extends NodeAccessTestBase { $grants = node_test_node_grants($web_user, $op); $altered_grants = $grants; \Drupal::moduleHandler()->alter('node_grants', $altered_grants, $web_user, $op); - $this->assertNotEqual($grants, $altered_grants, format_string('Altered the %op grant for a user.', ['%op' => $op])); + $this->assertNotEqual($grants, $altered_grants, new FormattableMarkup('Altered the %op grant for a user.', ['%op' => $op])); } // Check that core does not grant access to an unpublished node when an diff --git a/core/modules/node/tests/src/Kernel/NodeTokenReplaceTest.php b/core/modules/node/tests/src/Kernel/NodeTokenReplaceTest.php index 016807897d7..aaf5da7152b 100644 --- a/core/modules/node/tests/src/Kernel/NodeTokenReplaceTest.php +++ b/core/modules/node/tests/src/Kernel/NodeTokenReplaceTest.php @@ -104,7 +104,7 @@ class NodeTokenReplaceTest extends TokenReplaceKernelTestBase { foreach ($tests as $input => $expected) { $bubbleable_metadata = new BubbleableMetadata(); $output = $this->tokenService->replace($input, ['node' => $node], ['langcode' => $this->interfaceLanguage->getId()], $bubbleable_metadata); - $this->assertEqual($output, $expected, format_string('Node token %token replaced.', ['%token' => $input])); + $this->assertEqual($output, $expected, new FormattableMarkup('Node token %token replaced.', ['%token' => $input])); $this->assertEqual($bubbleable_metadata, $metadata_tests[$input]); } diff --git a/core/modules/options/tests/src/Functional/OptionsFieldUITest.php b/core/modules/options/tests/src/Functional/OptionsFieldUITest.php index 36f46cd9c8e..7f42998767a 100644 --- a/core/modules/options/tests/src/Functional/OptionsFieldUITest.php +++ b/core/modules/options/tests/src/Functional/OptionsFieldUITest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\options\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\Tests\field\Functional\FieldTestBase; @@ -325,7 +326,7 @@ class OptionsFieldUITest extends FieldTestBase { ]; $this->drupalPostForm($this->adminPath, $edit, t('Save field settings')); - $this->assertText(format_string('Updated field @field_name field settings.', ['@field_name' => $this->fieldName]), "The 'On' and 'Off' form fields work for boolean fields."); + $this->assertText(new FormattableMarkup('Updated field @field_name field settings.', ['@field_name' => $this->fieldName]), "The 'On' and 'Off' form fields work for boolean fields."); // Select a default value. $edit = [ diff --git a/core/modules/search/src/Tests/SearchTestBase.php b/core/modules/search/src/Tests/SearchTestBase.php index 61a5a91e330..62bf708c64e 100644 --- a/core/modules/search/src/Tests/SearchTestBase.php +++ b/core/modules/search/src/Tests/SearchTestBase.php @@ -91,8 +91,8 @@ abstract class SearchTestBase extends WebTestBase { foreach ($edit as $name => $value) { $this->fail(new FormattableMarkup('Failed to set field @name to @value', ['@name' => $name, '@value' => $value])); } - $this->assertTrue($submit_matches, format_string('Found the @submit button', ['@submit' => $submit])); - $this->fail(format_string('Found the requested form fields at @path', ['@path' => $path])); + $this->assertTrue($submit_matches, new FormattableMarkup('Found the @submit button', ['@submit' => $submit])); + $this->fail(new FormattableMarkup('Found the requested form fields at @path', ['@path' => $path])); } } diff --git a/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php b/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php index 40aa3e9994f..5255402e3c7 100644 --- a/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php +++ b/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\search\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Url; use Drupal\search\Entity\SearchPage; use Drupal\Tests\BrowserTestBase; @@ -207,7 +208,7 @@ class SearchConfigSettingsFormTest extends BrowserTestBase { $this->drupalGet($item['path'], $item['options']); foreach ($plugins as $entity_id) { $label = $entities[$entity_id]->label(); - $this->assertText($label, format_string('%label search tab is shown', ['%label' => $label])); + $this->assertText($label, new FormattableMarkup('%label search tab is shown', ['%label' => $label])); } } } diff --git a/core/modules/search/tests/src/Functional/SearchNumberMatchingTest.php b/core/modules/search/tests/src/Functional/SearchNumberMatchingTest.php index adc2c436a3a..94eec22daa7 100644 --- a/core/modules/search/tests/src/Functional/SearchNumberMatchingTest.php +++ b/core/modules/search/tests/src/Functional/SearchNumberMatchingTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\search\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Language\LanguageInterface; use Drupal\Tests\BrowserTestBase; use Drupal\Tests\Traits\Core\CronRunTrait; @@ -89,7 +90,7 @@ class SearchNumberMatchingTest extends BrowserTestBase { $this->drupalPostForm('search/node', ['keys' => 'foo'], t('Search')); - $this->assertNoText($node->label(), format_string('%number: node title not shown in dummy search', ['%number' => $i])); + $this->assertNoText($node->label(), new FormattableMarkup('%number: node title not shown in dummy search', ['%number' => $i])); // Now verify that we can find node i by searching for any of the // numbers. @@ -102,7 +103,7 @@ class SearchNumberMatchingTest extends BrowserTestBase { $this->drupalPostForm('search/node', ['keys' => $number], t('Search')); - $this->assertText($node->label(), format_string('%i: node title shown (search found the node) in search for number %number', ['%i' => $i, '%number' => $number])); + $this->assertText($node->label(), new FormattableMarkup('%i: node title shown (search found the node) in search for number %number', ['%i' => $i, '%number' => $number])); } } diff --git a/core/modules/search/tests/src/Functional/SearchNumbersTest.php b/core/modules/search/tests/src/Functional/SearchNumbersTest.php index 0901a270e5f..60c67394563 100644 --- a/core/modules/search/tests/src/Functional/SearchNumbersTest.php +++ b/core/modules/search/tests/src/Functional/SearchNumbersTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\search\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Language\LanguageInterface; use Drupal\Tests\BrowserTestBase; use Drupal\Tests\Traits\Core\CronRunTrait; @@ -109,7 +110,7 @@ class SearchNumbersTest extends BrowserTestBase { $this->drupalPostForm('search/node', ['keys' => $number], t('Search')); - $this->assertText($node->label(), format_string('%type: node title shown (search found the node) in search for number %number.', ['%type' => $type, '%number' => $number])); + $this->assertText($node->label(), new FormattableMarkup('%type: node title shown (search found the node) in search for number %number.', ['%type' => $type, '%number' => $number])); } } diff --git a/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php b/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php index 093aa5689a0..10a7b815984 100644 --- a/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php +++ b/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php @@ -411,7 +411,7 @@ class ShortcutLinksTest extends ShortcutTestBase { foreach ($edit_paths as $path) { $this->drupalGet($path); - $message = format_string('Access is denied on %s', ['%s' => $path]); + $message = new FormattableMarkup('Access is denied on %s', ['%s' => $path]); $this->assertResponse(403, $message); } } @@ -450,7 +450,7 @@ class ShortcutLinksTest extends ShortcutTestBase { * Link position counting from zero. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use format_string() to embed variables in the message text, not + * messages: use new FormattableMarkup() to embed variables in the message text, not * t(). If left blank, a default message will be displayed. * @param string $group * (optional) The group this message is in, which is displayed in a column diff --git a/core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php b/core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php index 6701ee933ec..e3308bd874d 100644 --- a/core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php +++ b/core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\shortcut\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase; use Drupal\Core\Entity\EntityChangedInterface; use Drupal\Core\Language\Language; @@ -78,7 +79,7 @@ class ShortcutTranslationUITest extends ContentTranslationUITestBase { $expected_path = \Drupal::urlGenerator()->generateFromRoute('user.page', [], ['language' => $language]); $label = $entity->getTranslation($langcode)->label(); $elements = $this->xpath('//nav[contains(@class, "toolbar-lining")]/ul[@class="toolbar-menu"]/li/a[contains(@href, :href) and normalize-space(text())=:label]', [':href' => $expected_path, ':label' => $label]); - $this->assertTrue(!empty($elements), format_string('Translated @language shortcut link @label found.', ['@label' => $label, '@language' => $language->getName()])); + $this->assertTrue(!empty($elements), new FormattableMarkup('Translated @language shortcut link @label found.', ['@label' => $label, '@language' => $language->getName()])); } } } @@ -120,7 +121,7 @@ class ShortcutTranslationUITest extends ContentTranslationUITestBase { $this->assertFalse( $entity instanceof EntityChangedInterface, - format_string('%entity is not implementing EntityChangedInterface.', ['%entity' => $this->entityTypeId]) + new FormattableMarkup('%entity is not implementing EntityChangedInterface.', ['%entity' => $this->entityTypeId]) ); } diff --git a/core/modules/simpletest/src/KernelTestBase.php b/core/modules/simpletest/src/KernelTestBase.php index 94ce0816da0..03d4784ad60 100644 --- a/core/modules/simpletest/src/KernelTestBase.php +++ b/core/modules/simpletest/src/KernelTestBase.php @@ -434,7 +434,7 @@ EOD; } \Drupal::service('config.installer')->installDefaultConfig('module', $module); } - $this->pass(format_string('Installed default config: %modules.', [ + $this->pass(new FormattableMarkup('Installed default config: %modules.', [ '%modules' => implode(', ', $modules), ])); } @@ -476,7 +476,7 @@ EOD; } $this->container->get('database')->schema()->createTable($table, $schema); } - $this->pass(format_string('Installed %module tables: %tables.', [ + $this->pass(new FormattableMarkup('Installed %module tables: %tables.', [ '%tables' => '{' . implode('}, {', $tables) . '}', '%module' => $module, ])); @@ -566,7 +566,7 @@ EOD; // Note that the kernel has rebuilt the container; this $module_handler is // no longer the $module_handler instance from above. $this->container->get('module_handler')->reload(); - $this->pass(format_string('Enabled modules: %modules.', [ + $this->pass(new FormattableMarkup('Enabled modules: %modules.', [ '%modules' => implode(', ', $modules), ])); } @@ -601,7 +601,7 @@ EOD; // no longer the $module_handler instance from above. $module_handler = $this->container->get('module_handler'); $module_handler->reload(); - $this->pass(format_string('Disabled modules: %modules.', [ + $this->pass(new FormattableMarkup('Disabled modules: %modules.', [ '%modules' => implode(', ', $modules), ])); } diff --git a/core/modules/simpletest/src/Tests/SimpleTestErrorCollectorTest.php b/core/modules/simpletest/src/Tests/SimpleTestErrorCollectorTest.php index 0c9fc2d41bd..59456fa1b0d 100644 --- a/core/modules/simpletest/src/Tests/SimpleTestErrorCollectorTest.php +++ b/core/modules/simpletest/src/Tests/SimpleTestErrorCollectorTest.php @@ -2,6 +2,7 @@ namespace Drupal\simpletest\Tests; +use Drupal\Component\Render\FormattableMarkup; use Drupal\simpletest\WebTestBase; /** @@ -83,11 +84,11 @@ class SimpleTestErrorCollectorTest extends WebTestBase { * Asserts that a collected error matches what we are expecting. */ public function assertError($error, $group, $function, $file, $message = NULL) { - $this->assertEqual($error['group'], $group, format_string("Group was %group", ['%group' => $group])); - $this->assertEqual($error['caller']['function'], $function, format_string("Function was %function", ['%function' => $function])); - $this->assertEqual(\Drupal::service('file_system')->basename($error['caller']['file']), $file, format_string("File was %file", ['%file' => $file])); + $this->assertEqual($error['group'], $group, new FormattableMarkup("Group was %group", ['%group' => $group])); + $this->assertEqual($error['caller']['function'], $function, new FormattableMarkup("Function was %function", ['%function' => $function])); + $this->assertEqual(\Drupal::service('file_system')->basename($error['caller']['file']), $file, new FormattableMarkup("File was %file", ['%file' => $file])); if (isset($message)) { - $this->assertEqual($error['message'], $message, format_string("Message was %message", ['%message' => $message])); + $this->assertEqual($error['message'], $message, new FormattableMarkup("Message was %message", ['%message' => $message])); } } diff --git a/core/modules/simpletest/src/Tests/SimpleTestTest.php b/core/modules/simpletest/src/Tests/SimpleTestTest.php index 392bbb921dd..c26fbdcbfee 100644 --- a/core/modules/simpletest/src/Tests/SimpleTestTest.php +++ b/core/modules/simpletest/src/Tests/SimpleTestTest.php @@ -2,6 +2,7 @@ namespace Drupal\simpletest\Tests; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Crypt; use Drupal\Core\Test\TestDatabase; use Drupal\simpletest\WebTestBase; @@ -313,7 +314,7 @@ EOD; break; } } - return $this->assertTrue($found, format_string('Found assertion {"@message", "@type", "@status", "@file", "@function"}.', ['@message' => $message, '@type' => $type, '@status' => $status, "@file" => $file, "@function" => $function])); + return $this->assertTrue($found, new FormattableMarkup('Found assertion {"@message", "@type", "@status", "@file", "@function"}.', ['@message' => $message, '@type' => $type, '@status' => $status, "@file" => $file, "@function" => $function])); } /** diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index ca823217d5c..e40b7bde191 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -229,7 +229,7 @@ abstract class WebTestBase extends TestBase { */ protected function assertBlockAppears(Block $block) { $result = $this->findBlockInstance($block); - $this->assertTrue(!empty($result), format_string('Ensure the block @id appears on the page', ['@id' => $block->id()])); + $this->assertTrue(!empty($result), new FormattableMarkup('Ensure the block @id appears on the page', ['@id' => $block->id()])); } /** @@ -240,7 +240,7 @@ abstract class WebTestBase extends TestBase { */ protected function assertNoBlockAppears(Block $block) { $result = $this->findBlockInstance($block); - $this->assertFalse(!empty($result), format_string('Ensure the block @id does not appear on the page', ['@id' => $block->id()])); + $this->assertFalse(!empty($result), new FormattableMarkup('Ensure the block @id does not appear on the page', ['@id' => $block->id()])); } /** @@ -298,7 +298,7 @@ abstract class WebTestBase extends TestBase { if (isset($this->sessionId)) { $account->session_id = $this->sessionId; } - $pass = $this->assert($this->drupalUserIsLoggedIn($account), format_string('User %name successfully logged in.', ['%name' => $account->getAccountName()]), 'User login'); + $pass = $this->assert($this->drupalUserIsLoggedIn($account), new FormattableMarkup('User %name successfully logged in.', ['%name' => $account->getAccountName()]), 'User login'); if ($pass) { $this->loggedInUser = $account; $this->container->get('current_user')->setAccount($account); @@ -1061,9 +1061,9 @@ abstract class WebTestBase extends TestBase { $this->fail(new FormattableMarkup('Failed to set field @name to @value', ['@name' => $name, '@value' => $value])); } if (!$ajax && isset($submit)) { - $this->assertTrue($submit_matches, format_string('Found the @submit button', ['@submit' => $submit])); + $this->assertTrue($submit_matches, new FormattableMarkup('Found the @submit button', ['@submit' => $submit])); } - $this->fail(format_string('Found the requested form fields at @path', ['@path' => ($path instanceof Url) ? $path->toString() : $path])); + $this->fail(new FormattableMarkup('Found the requested form fields at @path', ['@path' => ($path instanceof Url) ? $path->toString() : $path])); } } diff --git a/core/modules/statistics/tests/src/Functional/StatisticsTokenReplaceTest.php b/core/modules/statistics/tests/src/Functional/StatisticsTokenReplaceTest.php index 70f2f4298d2..cdffd84a16f 100644 --- a/core/modules/statistics/tests/src/Functional/StatisticsTokenReplaceTest.php +++ b/core/modules/statistics/tests/src/Functional/StatisticsTokenReplaceTest.php @@ -2,6 +2,8 @@ namespace Drupal\Tests\statistics\Functional; +use Drupal\Component\Render\FormattableMarkup; + /** * Generates text using placeholders for dummy content to check statistics token * replacement. @@ -47,7 +49,7 @@ class StatisticsTokenReplaceTest extends StatisticsTestBase { foreach ($tests as $input => $expected) { $output = \Drupal::token()->replace($input, ['node' => $node], ['langcode' => $language_interface->getId()]); - $this->assertEqual($output, $expected, format_string('Statistics token %token replaced.', ['%token' => $input])); + $this->assertEqual($output, $expected, new FormattableMarkup('Statistics token %token replaced.', ['%token' => $input])); } } diff --git a/core/modules/system/src/Tests/Menu/AssertBreadcrumbTrait.php b/core/modules/system/src/Tests/Menu/AssertBreadcrumbTrait.php index 41634b115ed..03bc9b594d3 100644 --- a/core/modules/system/src/Tests/Menu/AssertBreadcrumbTrait.php +++ b/core/modules/system/src/Tests/Menu/AssertBreadcrumbTrait.php @@ -4,6 +4,7 @@ namespace Drupal\system\Tests\Menu; @trigger_error(__NAMESPACE__ . '\AssertBreadcrumbTrait is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\system\Functional\Menu\AssertBreadcrumbTrait', E_USER_DEPRECATED); +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Html; use Drupal\Core\Url; @@ -89,7 +90,7 @@ trait AssertBreadcrumbTrait { // No parts must be left, or an expected "Home" will always pass. $pass = ($pass && empty($parts)); - $this->assertTrue($pass, format_string('Breadcrumb %parts found on @path.', [ + $this->assertTrue($pass, new FormattableMarkup('Breadcrumb %parts found on @path.', [ '%parts' => implode(' » ', $trail), '@path' => $this->getUrl(), ])); diff --git a/core/modules/system/src/Tests/Menu/AssertMenuActiveTrailTrait.php b/core/modules/system/src/Tests/Menu/AssertMenuActiveTrailTrait.php index e64177a8c21..d80752f2922 100644 --- a/core/modules/system/src/Tests/Menu/AssertMenuActiveTrailTrait.php +++ b/core/modules/system/src/Tests/Menu/AssertMenuActiveTrailTrait.php @@ -4,6 +4,7 @@ namespace Drupal\system\Tests\Menu; @trigger_error(__NAMESPACE__ . '\AssertMenuActiveTrailTrait is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\system\Functional\Menu\AssertMenuActiveTrailTrait', E_USER_DEPRECATED); +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Url; /** @@ -61,7 +62,7 @@ trait AssertMenuActiveTrailTrait { ':title' => $active_link_title, ]; $elements = $this->xpath($xpath, $args); - $this->assertTrue(!empty($elements), format_string('Active link %title was found in menu tree, including active trail links %tree.', [ + $this->assertTrue(!empty($elements), new FormattableMarkup('Active link %title was found in menu tree, including active trail links %tree.', [ '%title' => $active_link_title, '%tree' => implode(' » ', $tree), ])); diff --git a/core/modules/system/src/Tests/Module/ModuleTestBase.php b/core/modules/system/src/Tests/Module/ModuleTestBase.php index e733dfa4c85..64f673b68d1 100644 --- a/core/modules/system/src/Tests/Module/ModuleTestBase.php +++ b/core/modules/system/src/Tests/Module/ModuleTestBase.php @@ -4,6 +4,7 @@ namespace Drupal\system\Tests\Module; @trigger_error(__NAMESPACE__ . '\ModuleTestBase is deprecated for removal before Drupal 9.0.0. Use \Drupal\Tests\system\Functional\Module\ModuleTestBase instead. See https://www.drupal.org/node/2999939', E_USER_DEPRECATED); +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Config\InstallStorage; use Drupal\Core\Database\Database; use Drupal\Core\Config\FileStorage; @@ -50,9 +51,9 @@ abstract class ModuleTestBase extends WebTestBase { $tables = $connection->schema()->findTables($connection->prefixTables('{' . $base_table . '}') . '%'); if ($count) { - return $this->assertTrue($tables, format_string('Tables matching "@base_table" found.', ['@base_table' => $base_table])); + return $this->assertTrue($tables, new FormattableMarkup('Tables matching "@base_table" found.', ['@base_table' => $base_table])); } - return $this->assertFalse($tables, format_string('Tables matching "@base_table" not found.', ['@base_table' => $base_table])); + return $this->assertFalse($tables, new FormattableMarkup('Tables matching "@base_table" not found.', ['@base_table' => $base_table])); } /** @@ -70,7 +71,7 @@ abstract class ModuleTestBase extends WebTestBase { $tables_exist = FALSE; } } - return $this->assertTrue($tables_exist, format_string('All database tables defined by the @module module exist.', ['@module' => $module])); + return $this->assertTrue($tables_exist, new FormattableMarkup('All database tables defined by the @module module exist.', ['@module' => $module])); } /** @@ -88,7 +89,7 @@ abstract class ModuleTestBase extends WebTestBase { $tables_exist = TRUE; } } - return $this->assertFalse($tables_exist, format_string('None of the database tables defined by the @module module exist.', ['@module' => $module])); + return $this->assertFalse($tables_exist, new FormattableMarkup('None of the database tables defined by the @module module exist.', ['@module' => $module])); } /** @@ -132,7 +133,7 @@ abstract class ModuleTestBase extends WebTestBase { } // Verify that all configuration has been installed (which means that $names // is empty). - return $this->assertFalse($names, format_string('All default configuration of @module module found.', ['@module' => $module])); + return $this->assertFalse($names, new FormattableMarkup('All default configuration of @module module found.', ['@module' => $module])); } /** @@ -146,7 +147,7 @@ abstract class ModuleTestBase extends WebTestBase { */ public function assertNoModuleConfig($module) { $names = \Drupal::configFactory()->listAll($module . '.'); - return $this->assertFalse($names, format_string('No configuration found for @module module.', ['@module' => $module])); + return $this->assertFalse($names, new FormattableMarkup('No configuration found for @module module.', ['@module' => $module])); } /** @@ -166,7 +167,7 @@ abstract class ModuleTestBase extends WebTestBase { else { $message = 'Module "@module" is not enabled.'; } - $this->assertEqual($this->container->get('module_handler')->moduleExists($module), $enabled, format_string($message, ['@module' => $module])); + $this->assertEqual($this->container->get('module_handler')->moduleExists($module), $enabled, new FormattableMarkup($message, ['@module' => $module])); } } @@ -200,7 +201,7 @@ abstract class ModuleTestBase extends WebTestBase { ->countQuery() ->execute() ->fetchField(); - $this->assertTrue($count > 0, format_string('watchdog table contains @count rows for @message', ['@count' => $count, '@message' => format_string($message, $variables)])); + $this->assertTrue($count > 0, new FormattableMarkup('watchdog table contains @count rows for @message', ['@count' => $count, '@message' => new FormattableMarkup($message, $variables)])); } } diff --git a/core/modules/system/src/Tests/System/SystemConfigFormTestBase.php b/core/modules/system/src/Tests/System/SystemConfigFormTestBase.php index 0abbfd3f19b..e7d8b5d09b3 100644 --- a/core/modules/system/src/Tests/System/SystemConfigFormTestBase.php +++ b/core/modules/system/src/Tests/System/SystemConfigFormTestBase.php @@ -4,6 +4,7 @@ namespace Drupal\system\Tests\System; @trigger_error('\Drupal\system\Tests\System\SystemConfigFormTestBase is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use \Drupal\KernelTests\ConfigFormTestBase instead.', E_USER_DEPRECATED); +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Form\FormState; use Drupal\simpletest\WebTestBase; @@ -64,7 +65,7 @@ abstract class SystemConfigFormTestBase extends WebTestBase { '%values' => print_r($values, TRUE), '%errors' => $valid_form ? t('None') : implode(' ', $errors), ]; - $this->assertTrue($valid_form, format_string('Input values: %values<br/>Validation handler errors: %errors', $args)); + $this->assertTrue($valid_form, new FormattableMarkup('Input values: %values<br/>Validation handler errors: %errors', $args)); foreach ($this->values as $data) { $this->assertEqual($data['#value'], $this->config($data['#config_name'])->get($data['#config_key'])); diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index 9a080bfa3b6..4f680ba82c7 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -5,6 +5,7 @@ * Test module for the entity API providing several entity types for testing. */ +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Access\AccessResult; use Drupal\Core\Database\Query\AlterableInterface; use Drupal\Core\Entity\ContentEntityInterface; @@ -574,7 +575,7 @@ function entity_test_entity_operation_alter(array &$operations, EntityInterface if (in_array($entity->getEntityTypeId(), $valid_entity_type_ids)) { if (\Drupal::service('router.route_provider')->getRouteByName("entity.{$entity->getEntityTypeId()}.test_operation")) { $operations['test_operation'] = [ - 'title' => format_string('Test Operation: @label', ['@label' => $entity->label()]), + 'title' => new FormattableMarkup('Test Operation: @label', ['@label' => $entity->label()]), 'url' => Url::fromRoute("entity.{$entity->getEntityTypeId()}.test_operation", [$entity->getEntityTypeId() => $entity->id()]), 'weight' => 50, ]; diff --git a/core/modules/system/tests/src/Functional/Cache/ClearTest.php b/core/modules/system/tests/src/Functional/Cache/ClearTest.php index bec6d502fc7..905f010759e 100644 --- a/core/modules/system/tests/src/Functional/Cache/ClearTest.php +++ b/core/modules/system/tests/src/Functional/Cache/ClearTest.php @@ -7,6 +7,7 @@ namespace Drupal\Tests\system\Functional\Cache; * * @group Cache */ +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Cache\Cache; class ClearTest extends CacheTestBase { @@ -35,7 +36,7 @@ class ClearTest extends CacheTestBase { foreach ($bins as $bin => $cache_backend) { $cid = 'test_cid_clear' . $bin; - $this->assertFalse($this->checkCacheExists($cid, $this->defaultValue, $bin), format_string('All cache entries removed from @bin.', ['@bin' => $bin])); + $this->assertFalse($this->checkCacheExists($cid, $this->defaultValue, $bin), new FormattableMarkup('All cache entries removed from @bin.', ['@bin' => $bin])); } } diff --git a/core/modules/system/tests/src/Functional/Common/UrlTest.php b/core/modules/system/tests/src/Functional/Common/UrlTest.php index 362868c3178..47008beb65a 100644 --- a/core/modules/system/tests/src/Functional/Common/UrlTest.php +++ b/core/modules/system/tests/src/Functional/Common/UrlTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Functional\Common; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Cache\Cache; use Drupal\Core\Language\Language; @@ -32,11 +33,11 @@ class UrlTest extends BrowserTestBase { $encoded_path = "3CSCRIPT%3Ealert%28%27XSS%27%29%3C/SCRIPT%3E"; $link = \Drupal::l($text, Url::fromUserInput('/' . $path)); - $this->assertTrue(strpos($link, $encoded_path) !== FALSE && strpos($link, $path) === FALSE, format_string('XSS attack @path was filtered by \Drupal\Core\Utility\LinkGeneratorInterface::generate().', ['@path' => $path])); + $this->assertTrue(strpos($link, $encoded_path) !== FALSE && strpos($link, $path) === FALSE, new FormattableMarkup('XSS attack @path was filtered by \Drupal\Core\Utility\LinkGeneratorInterface::generate().', ['@path' => $path])); // Test \Drupal\Core\Url. $link = Url::fromUri('base:' . $path)->toString(); - $this->assertTrue(strpos($link, $encoded_path) !== FALSE && strpos($link, $path) === FALSE, format_string('XSS attack @path was filtered by #theme', ['@path' => $path])); + $this->assertTrue(strpos($link, $encoded_path) !== FALSE && strpos($link, $path) === FALSE, new FormattableMarkup('XSS attack @path was filtered by #theme', ['@path' => $path])); } /** @@ -93,10 +94,10 @@ class UrlTest extends BrowserTestBase { $hreflang_override_link['#options']['attributes']['hreflang'] = 'foo'; $rendered = $renderer->renderRoot($hreflang_link); - $this->assertTrue($this->hasAttribute('hreflang', $rendered, $langcode), format_string('hreflang attribute with value @langcode is present on a rendered link when langcode is provided in the render array.', ['@langcode' => $langcode])); + $this->assertTrue($this->hasAttribute('hreflang', $rendered, $langcode), new FormattableMarkup('hreflang attribute with value @langcode is present on a rendered link when langcode is provided in the render array.', ['@langcode' => $langcode])); $rendered = $renderer->renderRoot($hreflang_override_link); - $this->assertTrue($this->hasAttribute('hreflang', $rendered, 'foo'), format_string('hreflang attribute with value @hreflang is present on a rendered link when @hreflang is provided in the render array.', ['@hreflang' => 'foo'])); + $this->assertTrue($this->hasAttribute('hreflang', $rendered, 'foo'), new FormattableMarkup('hreflang attribute with value @hreflang is present on a rendered link when @hreflang is provided in the render array.', ['@hreflang' => 'foo'])); // Test the active class in links produced by // \Drupal\Core\Utility\LinkGeneratorInterface::generate() and #type 'link'. @@ -139,7 +140,7 @@ class UrlTest extends BrowserTestBase { // Test the link generator. $class_l = $this->randomMachineName(); $link_l = \Drupal::l($this->randomMachineName(), new Url('<current>', [], ['attributes' => ['class' => [$class_l]]])); - $this->assertTrue($this->hasAttribute('class', $link_l, $class_l), format_string('Custom class @class is present on link when requested by l()', ['@class' => $class_l])); + $this->assertTrue($this->hasAttribute('class', $link_l, $class_l), new FormattableMarkup('Custom class @class is present on link when requested by l()', ['@class' => $class_l])); // Test #type. $class_theme = $this->randomMachineName(); @@ -154,7 +155,7 @@ class UrlTest extends BrowserTestBase { ], ]; $link_theme = $renderer->renderRoot($type_link); - $this->assertTrue($this->hasAttribute('class', $link_theme, $class_theme), format_string('Custom class @class is present on link when requested by #type', ['@class' => $class_theme])); + $this->assertTrue($this->hasAttribute('class', $link_theme, $class_theme), new FormattableMarkup('Custom class @class is present on link when requested by #type', ['@class' => $class_theme])); } /** diff --git a/core/modules/system/tests/src/Functional/Database/SelectPagerDefaultTest.php b/core/modules/system/tests/src/Functional/Database/SelectPagerDefaultTest.php index 0c436ef419b..e4e83d2d9fe 100644 --- a/core/modules/system/tests/src/Functional/Database/SelectPagerDefaultTest.php +++ b/core/modules/system/tests/src/Functional/Database/SelectPagerDefaultTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Functional\Database; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Database\Database; use Symfony\Component\HttpFoundation\Request; @@ -42,7 +43,7 @@ class SelectPagerDefaultTest extends DatabaseTestBase { $correct_number = $count - ($limit * $page); } - $this->assertCount($correct_number, $data->names, format_string('Correct number of records returned by pager: @number', ['@number' => $correct_number])); + $this->assertCount($correct_number, $data->names, new FormattableMarkup('Correct number of records returned by pager: @number', ['@number' => $correct_number])); } } @@ -76,7 +77,7 @@ class SelectPagerDefaultTest extends DatabaseTestBase { $correct_number = $count - ($limit * $page); } - $this->assertCount($correct_number, $data->names, format_string('Correct number of records returned by pager: @number', ['@number' => $correct_number])); + $this->assertCount($correct_number, $data->names, new FormattableMarkup('Correct number of records returned by pager: @number', ['@number' => $correct_number])); } } diff --git a/core/modules/system/tests/src/Functional/Database/SelectTableSortDefaultTest.php b/core/modules/system/tests/src/Functional/Database/SelectTableSortDefaultTest.php index 2904d31fa65..ee69dec9458 100644 --- a/core/modules/system/tests/src/Functional/Database/SelectTableSortDefaultTest.php +++ b/core/modules/system/tests/src/Functional/Database/SelectTableSortDefaultTest.php @@ -2,6 +2,8 @@ namespace Drupal\Tests\system\Functional\Database; +use Drupal\Component\Render\FormattableMarkup; + /** * Tests the tablesort query extender. * @@ -60,8 +62,8 @@ class SelectTableSortDefaultTest extends DatabaseTestBase { $first = array_shift($data->tasks); $last = array_pop($data->tasks); - $this->assertEqual($first->task, $sort['first'], format_string('Items appear in the correct order sorting by @field @sort.', ['@field' => $sort['field'], '@sort' => $sort['sort']])); - $this->assertEqual($last->task, $sort['last'], format_string('Items appear in the correct order sorting by @field @sort.', ['@field' => $sort['field'], '@sort' => $sort['sort']])); + $this->assertEqual($first->task, $sort['first'], new FormattableMarkup('Items appear in the correct order sorting by @field @sort.', ['@field' => $sort['field'], '@sort' => $sort['sort']])); + $this->assertEqual($last->task, $sort['last'], new FormattableMarkup('Items appear in the correct order sorting by @field @sort.', ['@field' => $sort['field'], '@sort' => $sort['sort']])); } } diff --git a/core/modules/system/tests/src/Functional/Entity/EntityFormTest.php b/core/modules/system/tests/src/Functional/Entity/EntityFormTest.php index a82bb3e8593..7b497bf417f 100644 --- a/core/modules/system/tests/src/Functional/Entity/EntityFormTest.php +++ b/core/modules/system/tests/src/Functional/Entity/EntityFormTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Functional\Entity; +use Drupal\Component\Render\FormattableMarkup; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\Tests\BrowserTestBase; @@ -76,21 +77,21 @@ class EntityFormTest extends BrowserTestBase { $this->drupalPostForm($entity_type . '/add', $edit, t('Save')); $entity = $this->loadEntityByName($entity_type, $name1); - $this->assertTrue($entity, format_string('%entity_type: Entity found in the database.', ['%entity_type' => $entity_type])); + $this->assertTrue($entity, new FormattableMarkup('%entity_type: Entity found in the database.', ['%entity_type' => $entity_type])); $edit['name[0][value]'] = $name2; $this->drupalPostForm($entity_type . '/manage/' . $entity->id() . '/edit', $edit, t('Save')); $entity = $this->loadEntityByName($entity_type, $name1); - $this->assertFalse($entity, format_string('%entity_type: The entity has been modified.', ['%entity_type' => $entity_type])); + $this->assertFalse($entity, new FormattableMarkup('%entity_type: The entity has been modified.', ['%entity_type' => $entity_type])); $entity = $this->loadEntityByName($entity_type, $name2); - $this->assertTrue($entity, format_string('%entity_type: Modified entity found in the database.', ['%entity_type' => $entity_type])); - $this->assertNotEqual($entity->name->value, $name1, format_string('%entity_type: The entity name has been modified.', ['%entity_type' => $entity_type])); + $this->assertTrue($entity, new FormattableMarkup('%entity_type: Modified entity found in the database.', ['%entity_type' => $entity_type])); + $this->assertNotEqual($entity->name->value, $name1, new FormattableMarkup('%entity_type: The entity name has been modified.', ['%entity_type' => $entity_type])); $this->drupalGet($entity_type . '/manage/' . $entity->id() . '/edit'); $this->clickLink(t('Delete')); $this->drupalPostForm(NULL, [], t('Delete')); $entity = $this->loadEntityByName($entity_type, $name2); - $this->assertFalse($entity, format_string('%entity_type: Entity not found in the database.', ['%entity_type' => $entity_type])); + $this->assertFalse($entity, new FormattableMarkup('%entity_type: Entity not found in the database.', ['%entity_type' => $entity_type])); } /** @@ -111,26 +112,26 @@ class EntityFormTest extends BrowserTestBase { $this->drupalPostForm($entity_type_id . '/add', $edit, t('Save')); $entity = $this->loadEntityByName($entity_type_id, $name1); - $this->assertTrue($entity, format_string('%entity_type: Entity found in the database.', ['%entity_type' => $entity_type_id])); + $this->assertTrue($entity, new FormattableMarkup('%entity_type: Entity found in the database.', ['%entity_type' => $entity_type_id])); // Add a translation to the newly created entity without using the Content // translation module. $entity->addTranslation('ro', ['name' => $name1_ro])->save(); $translated_entity = $this->loadEntityByName($entity_type_id, $name1)->getTranslation('ro'); - $this->assertEqual($translated_entity->name->value, $name1_ro, format_string('%entity_type: The translation has been added.', ['%entity_type' => $entity_type_id])); + $this->assertEqual($translated_entity->name->value, $name1_ro, new FormattableMarkup('%entity_type: The translation has been added.', ['%entity_type' => $entity_type_id])); $edit['name[0][value]'] = $name2_ro; $this->drupalPostForm('ro/' . $entity_type_id . '/manage/' . $entity->id() . '/edit', $edit, t('Save')); $translated_entity = $this->loadEntityByName($entity_type_id, $name1)->getTranslation('ro'); - $this->assertTrue($translated_entity, format_string('%entity_type: Modified translation found in the database.', ['%entity_type' => $entity_type_id])); - $this->assertEqual($translated_entity->name->value, $name2_ro, format_string('%entity_type: The name of the translation has been modified.', ['%entity_type' => $entity_type_id])); + $this->assertTrue($translated_entity, new FormattableMarkup('%entity_type: Modified translation found in the database.', ['%entity_type' => $entity_type_id])); + $this->assertEqual($translated_entity->name->value, $name2_ro, new FormattableMarkup('%entity_type: The name of the translation has been modified.', ['%entity_type' => $entity_type_id])); $this->drupalGet('ro/' . $entity_type_id . '/manage/' . $entity->id() . '/edit'); $this->clickLink(t('Delete')); $this->drupalPostForm(NULL, [], t('Delete Romanian translation')); $entity = $this->loadEntityByName($entity_type_id, $name1); - $this->assertNotNull($entity, format_string('%entity_type: The original entity still exists.', ['%entity_type' => $entity_type_id])); - $this->assertFalse($entity->hasTranslation('ro'), format_string('%entity_type: Entity translation does not exist anymore.', ['%entity_type' => $entity_type_id])); + $this->assertNotNull($entity, new FormattableMarkup('%entity_type: The original entity still exists.', ['%entity_type' => $entity_type_id])); + $this->assertFalse($entity->hasTranslation('ro'), new FormattableMarkup('%entity_type: Entity translation does not exist anymore.', ['%entity_type' => $entity_type_id])); } /** diff --git a/core/modules/system/tests/src/Functional/Entity/EntityOperationsTest.php b/core/modules/system/tests/src/Functional/Entity/EntityOperationsTest.php index bcb385bf163..f881a94bb5b 100644 --- a/core/modules/system/tests/src/Functional/Entity/EntityOperationsTest.php +++ b/core/modules/system/tests/src/Functional/Entity/EntityOperationsTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Functional\Entity; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Tests\BrowserTestBase; /** @@ -36,7 +37,7 @@ class EntityOperationsTest extends BrowserTestBase { $roles = user_roles(); foreach ($roles as $role) { $this->assertLinkByHref($role->toUrl()->toString() . '/test_operation'); - $this->assertLink(format_string('Test Operation: @label', ['@label' => $role->label()])); + $this->assertLink(new FormattableMarkup('Test Operation: @label', ['@label' => $role->label()])); } } diff --git a/core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php b/core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php index aefaec23aa3..07468af5c56 100644 --- a/core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php +++ b/core/modules/system/tests/src/Functional/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Functional\Entity\EntityReferenceSelection; +use Drupal\Component\Render\FormattableMarkup; use Drupal\comment\Tests\CommentTestTrait; use Drupal\Component\Utility\Html; use Drupal\Core\Language\LanguageInterface; @@ -86,7 +87,7 @@ class EntityReferenceSelectionAccessTest extends KernelTestBase { foreach ($tests as $test) { foreach ($test['arguments'] as $arguments) { $result = call_user_func_array([$handler, 'getReferenceableEntities'], $arguments); - $this->assertEqual($result, $test['result'], format_string('Valid result set returned by @handler.', ['@handler' => $handler_name])); + $this->assertEqual($result, $test['result'], new FormattableMarkup('Valid result set returned by @handler.', ['@handler' => $handler_name])); $result = call_user_func_array([$handler, 'countReferenceableEntities'], $arguments); if (!empty($test['result'])) { @@ -97,7 +98,7 @@ class EntityReferenceSelectionAccessTest extends KernelTestBase { $count = 0; } - $this->assertEqual($result, $count, format_string('Valid count returned by @handler.', ['@handler' => $handler_name])); + $this->assertEqual($result, $count, new FormattableMarkup('Valid count returned by @handler.', ['@handler' => $handler_name])); } } } diff --git a/core/modules/system/tests/src/Functional/Entity/EntityRevisionsTest.php b/core/modules/system/tests/src/Functional/Entity/EntityRevisionsTest.php index a413b730766..efc5a82386b 100644 --- a/core/modules/system/tests/src/Functional/Entity/EntityRevisionsTest.php +++ b/core/modules/system/tests/src/Functional/Entity/EntityRevisionsTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Functional\Entity; +use Drupal\Component\Render\FormattableMarkup; use Drupal\entity_test\Entity\EntityTestMulRev; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; @@ -139,9 +140,9 @@ class EntityRevisionsTest extends BrowserTestBase { } // Check that the fields and properties contain new content. - $this->assertTrue($entity->revision_id->value > $legacy_revision_id, format_string('%entity_type: Revision ID changed.', ['%entity_type' => $entity_type])); - $this->assertNotEqual($entity->name->value, $legacy_name, format_string('%entity_type: Name changed.', ['%entity_type' => $entity_type])); - $this->assertNotEqual($entity->translatable_test_field->value, $legacy_text, format_string('%entity_type: Text changed.', ['%entity_type' => $entity_type])); + $this->assertTrue($entity->revision_id->value > $legacy_revision_id, new FormattableMarkup('%entity_type: Revision ID changed.', ['%entity_type' => $entity_type])); + $this->assertNotEqual($entity->name->value, $legacy_name, new FormattableMarkup('%entity_type: Name changed.', ['%entity_type' => $entity_type])); + $this->assertNotEqual($entity->translatable_test_field->value, $legacy_text, new FormattableMarkup('%entity_type: Text changed.', ['%entity_type' => $entity_type])); } $revisions = $storage->loadMultipleRevisions($revision_ids); @@ -150,29 +151,29 @@ class EntityRevisionsTest extends BrowserTestBase { $entity_revision = $revisions[$revision_ids[$i]]; // Check if properties and fields contain the revision specific content. - $this->assertEqual($entity_revision->revision_id->value, $revision_ids[$i], format_string('%entity_type: Revision ID matches.', ['%entity_type' => $entity_type])); - $this->assertEqual($entity_revision->name->value, $values['en'][$i]['name'], format_string('%entity_type: Name matches.', ['%entity_type' => $entity_type])); - $this->assertEqual($entity_revision->translatable_test_field[0]->value, $values['en'][$i]['translatable_test_field'][0], format_string('%entity_type: Text matches.', ['%entity_type' => $entity_type])); - $this->assertEqual($entity_revision->translatable_test_field[1]->value, $values['en'][$i]['translatable_test_field'][1], format_string('%entity_type: Text matches.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity_revision->revision_id->value, $revision_ids[$i], new FormattableMarkup('%entity_type: Revision ID matches.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity_revision->name->value, $values['en'][$i]['name'], new FormattableMarkup('%entity_type: Name matches.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity_revision->translatable_test_field[0]->value, $values['en'][$i]['translatable_test_field'][0], new FormattableMarkup('%entity_type: Text matches.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity_revision->translatable_test_field[1]->value, $values['en'][$i]['translatable_test_field'][1], new FormattableMarkup('%entity_type: Text matches.', ['%entity_type' => $entity_type])); // Check the translated values. if ($entity->getEntityType()->isTranslatable()) { $revision_translation = $entity_revision->getTranslation('de'); - $this->assertEqual($revision_translation->name->value, $values['de'][$i]['name'], format_string('%entity_type: Name matches.', ['%entity_type' => $entity_type])); - $this->assertEqual($revision_translation->translatable_test_field[0]->value, $values['de'][$i]['translatable_test_field'][0], format_string('%entity_type: Text matches.', ['%entity_type' => $entity_type])); - $this->assertEqual($revision_translation->translatable_test_field[1]->value, $values['de'][$i]['translatable_test_field'][1], format_string('%entity_type: Text matches.', ['%entity_type' => $entity_type])); + $this->assertEqual($revision_translation->name->value, $values['de'][$i]['name'], new FormattableMarkup('%entity_type: Name matches.', ['%entity_type' => $entity_type])); + $this->assertEqual($revision_translation->translatable_test_field[0]->value, $values['de'][$i]['translatable_test_field'][0], new FormattableMarkup('%entity_type: Text matches.', ['%entity_type' => $entity_type])); + $this->assertEqual($revision_translation->translatable_test_field[1]->value, $values['de'][$i]['translatable_test_field'][1], new FormattableMarkup('%entity_type: Text matches.', ['%entity_type' => $entity_type])); } // Check non-revisioned values are loaded. - $this->assertTrue(isset($entity_revision->created->value), format_string('%entity_type: Non-revisioned field is loaded.', ['%entity_type' => $entity_type])); - $this->assertEqual($entity_revision->created->value, $values['en'][2]['created'], format_string('%entity_type: Non-revisioned field value is the same between revisions.', ['%entity_type' => $entity_type])); + $this->assertTrue(isset($entity_revision->created->value), new FormattableMarkup('%entity_type: Non-revisioned field is loaded.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity_revision->created->value, $values['en'][2]['created'], new FormattableMarkup('%entity_type: Non-revisioned field value is the same between revisions.', ['%entity_type' => $entity_type])); } // Confirm the correct revision text appears in the edit form. $entity = $storage->load($entity->id->value); $this->drupalGet($entity_type . '/manage/' . $entity->id->value . '/edit'); - $this->assertFieldById('edit-name-0-value', $entity->name->value, format_string('%entity_type: Name matches in UI.', ['%entity_type' => $entity_type])); - $this->assertFieldById('edit-translatable-test-field-0-value', $entity->translatable_test_field->value, format_string('%entity_type: Text matches in UI.', ['%entity_type' => $entity_type])); + $this->assertFieldById('edit-name-0-value', $entity->name->value, new FormattableMarkup('%entity_type: Name matches in UI.', ['%entity_type' => $entity_type])); + $this->assertFieldById('edit-translatable-test-field-0-value', $entity->translatable_test_field->value, new FormattableMarkup('%entity_type: Text matches in UI.', ['%entity_type' => $entity_type])); } /** diff --git a/core/modules/system/tests/src/Functional/Form/CheckboxTest.php b/core/modules/system/tests/src/Functional/Form/CheckboxTest.php index 60fad6a2e81..a4d9c0904a7 100644 --- a/core/modules/system/tests/src/Functional/Form/CheckboxTest.php +++ b/core/modules/system/tests/src/Functional/Form/CheckboxTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Functional\Form; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Tests\BrowserTestBase; /** @@ -48,7 +49,7 @@ class CheckboxTest extends BrowserTestBase { $checked = ($default_value === '1foobar'); } $checked_in_html = strpos($form, 'checked') !== FALSE; - $message = format_string('#default_value is %default_value #return_value is %return_value.', ['%default_value' => var_export($default_value, TRUE), '%return_value' => var_export($return_value, TRUE)]); + $message = new FormattableMarkup('#default_value is %default_value #return_value is %return_value.', ['%default_value' => var_export($default_value, TRUE), '%return_value' => var_export($return_value, TRUE)]); $this->assertIdentical($checked, $checked_in_html, $message); } } @@ -78,7 +79,7 @@ class CheckboxTest extends BrowserTestBase { foreach ($checkboxes as $checkbox) { $checked = $checkbox->isChecked(); $name = $checkbox->getAttribute('name'); - $this->assertIdentical($checked, $name == 'checkbox_zero_default[0]' || $name == 'checkbox_string_zero_default[0]', format_string('Checkbox %name correctly checked', ['%name' => $name])); + $this->assertIdentical($checked, $name == 'checkbox_zero_default[0]' || $name == 'checkbox_string_zero_default[0]', new FormattableMarkup('Checkbox %name correctly checked', ['%name' => $name])); } // Due to Mink driver differences, we cannot submit an empty checkbox value // to drupalPostForm(), even if that empty value is the 'true' value for @@ -92,7 +93,7 @@ class CheckboxTest extends BrowserTestBase { foreach ($checkboxes as $checkbox) { $checked = $checkbox->isChecked(); $name = (string) $checkbox->getAttribute('name'); - $this->assertIdentical($checked, $name == 'checkbox_off[0]' || $name == 'checkbox_zero_default[0]' || $name == 'checkbox_string_zero_default[0]', format_string('Checkbox %name correctly checked', ['%name' => $name])); + $this->assertIdentical($checked, $name == 'checkbox_off[0]' || $name == 'checkbox_zero_default[0]' || $name == 'checkbox_string_zero_default[0]', new FormattableMarkup('Checkbox %name correctly checked', ['%name' => $name])); } } diff --git a/core/modules/system/tests/src/Functional/Form/ElementTest.php b/core/modules/system/tests/src/Functional/Form/ElementTest.php index 6eefa484bdd..eb167d428f7 100644 --- a/core/modules/system/tests/src/Functional/Form/ElementTest.php +++ b/core/modules/system/tests/src/Functional/Form/ElementTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Functional\Form; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Tests\BrowserTestBase; /** @@ -30,7 +31,7 @@ class ElementTest extends BrowserTestBase { ':id' => 'edit-' . $type, ':expected' => $expected, ]); - $this->assertTrue(!empty($element), format_string('Placeholder text placed in @type.', ['@type' => $type])); + $this->assertTrue(!empty($element), new FormattableMarkup('Placeholder text placed in @type.', ['@type' => $type])); } // Test to make sure textarea has the proper placeholder text. @@ -82,7 +83,7 @@ class ElementTest extends BrowserTestBase { ':id' => 'edit-' . $type . '-foo', ':class' => 'description', ]); - $this->assertTrue(count($elements), format_string('Custom %type option description found.', [ + $this->assertTrue(count($elements), new FormattableMarkup('Custom %type option description found.', [ '%type' => $type, ])); } @@ -138,8 +139,8 @@ class ElementTest extends BrowserTestBase { foreach (['checkboxes', 'radios'] as $type) { $element_ids = $this->xpath('//div[@id=:id]', [':id' => 'edit-' . $type]); $wrapper_ids = $this->xpath('//fieldset[@id=:id]', [':id' => 'edit-' . $type . '--wrapper']); - $this->assertTrue(count($element_ids) == 1, format_string('A single element id found for type %type', ['%type' => $type])); - $this->assertTrue(count($wrapper_ids) == 1, format_string('A single wrapper id found for type %type', ['%type' => $type])); + $this->assertTrue(count($element_ids) == 1, new FormattableMarkup('A single element id found for type %type', ['%type' => $type])); + $this->assertTrue(count($wrapper_ids) == 1, new FormattableMarkup('A single wrapper id found for type %type', ['%type' => $type])); } } diff --git a/core/modules/system/tests/src/Functional/Form/FormTest.php b/core/modules/system/tests/src/Functional/Form/FormTest.php index 849944b0f54..bd45bbcf788 100644 --- a/core/modules/system/tests/src/Functional/Form/FormTest.php +++ b/core/modules/system/tests/src/Functional/Form/FormTest.php @@ -191,7 +191,7 @@ class FormTest extends BrowserTestBase { $expected_key = array_search($error->getText(), $expected); // If the error message is not one of the expected messages, fail. if ($expected_key === FALSE) { - $this->fail(format_string("Unexpected error message: @error", ['@error' => $error[0]])); + $this->fail(new FormattableMarkup("Unexpected error message: @error", ['@error' => $error[0]])); } // Remove the expected message from the list once it is found. else { @@ -201,7 +201,7 @@ class FormTest extends BrowserTestBase { // Fail if any expected messages were not found. foreach ($expected as $not_found) { - $this->fail(format_string("Found error message: @error", ['@error' => $not_found])); + $this->fail(new FormattableMarkup("Found error message: @error", ['@error' => $not_found])); } // Verify that input elements are still empty. @@ -369,7 +369,7 @@ class FormTest extends BrowserTestBase { 'zero_checkbox_off' => 0, ]; foreach ($expected_values as $widget => $expected_value) { - $this->assertSame($values[$widget], $expected_value, format_string('Checkbox %widget returns expected value (expected: %expected, got: %value)', [ + $this->assertSame($values[$widget], $expected_value, new FormattableMarkup('Checkbox %widget returns expected value (expected: %expected, got: %value)', [ '%widget' => var_export($widget, TRUE), '%expected' => var_export($expected_value, TRUE), '%value' => var_export($values[$widget], TRUE), @@ -446,7 +446,7 @@ class FormTest extends BrowserTestBase { 'multiple_no_default_required' => ['three' => 'three'], ]; foreach ($expected as $key => $value) { - $this->assertIdentical($values[$key], $value, format_string('@name: @actual is equal to @expected.', [ + $this->assertIdentical($values[$key], $value, new FormattableMarkup('@name: @actual is equal to @expected.', [ '@name' => $key, '@actual' => var_export($values[$key], TRUE), '@expected' => var_export($value, TRUE), @@ -517,10 +517,10 @@ class FormTest extends BrowserTestBase { // Check if the error exists on the page, if the current message ID is // expected. Otherwise ensure that the error message is not present. if ($id === $error) { - $this->assertRaw(format_string($message, $placeholders)); + $this->assertRaw(new FormattableMarkup($message, $placeholders)); } else { - $this->assertNoRaw(format_string($message, $placeholders)); + $this->assertNoRaw(new FormattableMarkup($message, $placeholders)); } } } @@ -660,7 +660,7 @@ class FormTest extends BrowserTestBase { // Checkboxes values are not filtered out. $values[$key] = array_filter($values[$key]); } - $this->assertIdentical($expected_value, $values[$key], format_string('Default value for %type: expected %expected, returned %returned.', ['%type' => $key, '%expected' => var_export($expected_value, TRUE), '%returned' => var_export($values[$key], TRUE)])); + $this->assertIdentical($expected_value, $values[$key], new FormattableMarkup('Default value for %type: expected %expected, returned %returned.', ['%type' => $key, '%expected' => var_export($expected_value, TRUE), '%returned' => var_export($values[$key], TRUE)])); } // Recurse children. @@ -717,7 +717,7 @@ class FormTest extends BrowserTestBase { ':div-class' => $class, ':value' => isset($item['#value']) ? $item['#value'] : '', ]); - $this->assertTrue(isset($element[0]), format_string('Disabled form element class found for #type %type.', ['%type' => $item['#type']])); + $this->assertTrue(isset($element[0]), new FormattableMarkup('Disabled form element class found for #type %type.', ['%type' => $item['#type']])); } // Verify special element #type text-format. @@ -725,12 +725,12 @@ class FormTest extends BrowserTestBase { ':name' => 'text_format[value]', ':div-class' => 'form-disabled', ]); - $this->assertTrue(isset($element[0]), format_string('Disabled form element class found for #type %type.', ['%type' => 'text_format[value]'])); + $this->assertTrue(isset($element[0]), new FormattableMarkup('Disabled form element class found for #type %type.', ['%type' => 'text_format[value]'])); $element = $this->xpath('//div[contains(@class, :div-class)]/descendant::select[@name=:name]', [ ':name' => 'text_format[format]', ':div-class' => 'form-disabled', ]); - $this->assertTrue(isset($element[0]), format_string('Disabled form element class found for #type %type.', ['%type' => 'text_format[format]'])); + $this->assertTrue(isset($element[0]), new FormattableMarkup('Disabled form element class found for #type %type.', ['%type' => 'text_format[format]'])); } /** @@ -759,7 +759,7 @@ class FormTest extends BrowserTestBase { ':id' => 'edit-' . $type, ':expected' => $expected, ]); - $this->assertTrue(!empty($element), format_string('The @type has the proper required attribute.', ['@type' => $type])); + $this->assertTrue(!empty($element), new FormattableMarkup('The @type has the proper required attribute.', ['@type' => $type])); } // Test to make sure textarea has the proper required attribute. diff --git a/core/modules/system/tests/src/Functional/Form/LanguageSelectElementTest.php b/core/modules/system/tests/src/Functional/Form/LanguageSelectElementTest.php index 0bd9bb8e6d5..1e77250b60e 100644 --- a/core/modules/system/tests/src/Functional/Form/LanguageSelectElementTest.php +++ b/core/modules/system/tests/src/Functional/Form/LanguageSelectElementTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Functional\Form; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Serialization\Json; use Drupal\Core\Language\LanguageInterface; use Drupal\language\Entity\ConfigurableLanguage; @@ -48,7 +49,7 @@ class LanguageSelectElementTest extends BrowserTestBase { 'edit-languages-config-and-locked' => LanguageInterface::STATE_CONFIGURABLE | LanguageInterface::STATE_LOCKED, ]; foreach ($ids as $id => $flags) { - $this->assertField($id, format_string('The @id field was found on the page.', ['@id' => $id])); + $this->assertField($id, new FormattableMarkup('The @id field was found on the page.', ['@id' => $id])); $options = []; /* @var $language_manager \Drupal\Core\Language\LanguageManagerInterface */ $language_manager = $this->container->get('language_manager'); @@ -59,7 +60,7 @@ class LanguageSelectElementTest extends BrowserTestBase { } // Test that the #options were not altered by #languages. - $this->assertField('edit-language-custom-options', format_string('The @id field was found on the page.', ['@id' => 'edit-language-custom-options'])); + $this->assertField('edit-language-custom-options', new FormattableMarkup('The @id field was found on the page.', ['@id' => 'edit-language-custom-options'])); $this->_testLanguageSelectElementOptions('edit-language-custom-options', ['opt1' => 'First option', 'opt2' => 'Second option', 'opt3' => 'Third option']); } @@ -76,7 +77,7 @@ class LanguageSelectElementTest extends BrowserTestBase { // Check that the language fields were rendered on the page. $ids = ['edit-languages-all', 'edit-languages-configurable', 'edit-languages-locked', 'edit-languages-config-and-locked']; foreach ($ids as $id) { - $this->assertNoField($id, format_string('The @id field was not found on the page.', ['@id' => $id])); + $this->assertNoField($id, new FormattableMarkup('The @id field was not found on the page.', ['@id' => $id])); } // Check that the submitted values were the default values of the language @@ -112,7 +113,7 @@ class LanguageSelectElementTest extends BrowserTestBase { $this->assertEqual($option->getText(), $option_title); next($options); } - $this->assertEqual($count, count($options), format_string('The number of languages and the number of options shown by the language element are the same: @languages languages, @number options', ['@languages' => count($options), '@number' => $count])); + $this->assertEqual($count, count($options), new FormattableMarkup('The number of languages and the number of options shown by the language element are the same: @languages languages, @number options', ['@languages' => count($options), '@number' => $count])); } } diff --git a/core/modules/system/tests/src/Functional/Form/StateValuesCleanTest.php b/core/modules/system/tests/src/Functional/Form/StateValuesCleanTest.php index cae0835b5f8..a77b11fd753 100644 --- a/core/modules/system/tests/src/Functional/Form/StateValuesCleanTest.php +++ b/core/modules/system/tests/src/Functional/Form/StateValuesCleanTest.php @@ -35,16 +35,16 @@ class StateValuesCleanTest extends BrowserTestBase { ]; // Verify that all internal Form API elements were removed. - $this->assertFalse(isset($values['form_id']), format_string('%element was removed.', ['%element' => 'form_id'])); - $this->assertFalse(isset($values['form_token']), format_string('%element was removed.', ['%element' => 'form_token'])); - $this->assertFalse(isset($values['form_build_id']), format_string('%element was removed.', ['%element' => 'form_build_id'])); - $this->assertFalse(isset($values['op']), format_string('%element was removed.', ['%element' => 'op'])); + $this->assertFalse(isset($values['form_id']), new FormattableMarkup('%element was removed.', ['%element' => 'form_id'])); + $this->assertFalse(isset($values['form_token']), new FormattableMarkup('%element was removed.', ['%element' => 'form_token'])); + $this->assertFalse(isset($values['form_build_id']), new FormattableMarkup('%element was removed.', ['%element' => 'form_build_id'])); + $this->assertFalse(isset($values['op']), new FormattableMarkup('%element was removed.', ['%element' => 'op'])); // Verify that all buttons were removed. - $this->assertFalse(isset($values['foo']), format_string('%element was removed.', ['%element' => 'foo'])); - $this->assertFalse(isset($values['bar']), format_string('%element was removed.', ['%element' => 'bar'])); - $this->assertFalse(isset($values['baz']['foo']), format_string('%element was removed.', ['%element' => 'foo'])); - $this->assertFalse(isset($values['baz']['baz']), format_string('%element was removed.', ['%element' => 'baz'])); + $this->assertFalse(isset($values['foo']), new FormattableMarkup('%element was removed.', ['%element' => 'foo'])); + $this->assertFalse(isset($values['bar']), new FormattableMarkup('%element was removed.', ['%element' => 'bar'])); + $this->assertFalse(isset($values['baz']['foo']), new FormattableMarkup('%element was removed.', ['%element' => 'foo'])); + $this->assertFalse(isset($values['baz']['baz']), new FormattableMarkup('%element was removed.', ['%element' => 'baz'])); // Verify values manually added for cleaning were removed. $this->assertFalse(isset($values['wine']), new FormattableMarkup('%element was removed.', ['%element' => 'wine'])); diff --git a/core/modules/system/tests/src/Functional/Form/ValidationTest.php b/core/modules/system/tests/src/Functional/Form/ValidationTest.php index 094a0af73c7..ccb15ade16d 100644 --- a/core/modules/system/tests/src/Functional/Form/ValidationTest.php +++ b/core/modules/system/tests/src/Functional/Form/ValidationTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Functional\Form; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Render\Element; use Drupal\Tests\BrowserTestBase; @@ -100,7 +101,7 @@ class ValidationTest extends BrowserTestBase { ':id' => 'edit-' . $type, ':expected' => $expected, ]); - $this->assertTrue(!empty($element), format_string('The @type button has the proper formnovalidate attribute.', ['@type' => $type])); + $this->assertTrue(!empty($element), new FormattableMarkup('The @type button has the proper formnovalidate attribute.', ['@type' => $type])); } // The button with full server-side validation should not have the // 'formnovalidate' attribute. diff --git a/core/modules/system/tests/src/Functional/Menu/AssertBreadcrumbTrait.php b/core/modules/system/tests/src/Functional/Menu/AssertBreadcrumbTrait.php index 32793e3501e..e38dfbcb181 100644 --- a/core/modules/system/tests/src/Functional/Menu/AssertBreadcrumbTrait.php +++ b/core/modules/system/tests/src/Functional/Menu/AssertBreadcrumbTrait.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Functional\Menu; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Html; use Drupal\Core\Url; @@ -88,7 +89,7 @@ trait AssertBreadcrumbTrait { // No parts must be left, or an expected "Home" will always pass. $pass = ($pass && empty($parts)); - $this->assertTrue($pass, format_string('Breadcrumb %parts found on @path.', [ + $this->assertTrue($pass, new FormattableMarkup('Breadcrumb %parts found on @path.', [ '%parts' => implode(' » ', $trail), '@path' => $this->getUrl(), ])); diff --git a/core/modules/system/tests/src/Functional/Menu/AssertMenuActiveTrailTrait.php b/core/modules/system/tests/src/Functional/Menu/AssertMenuActiveTrailTrait.php index c5d60e54275..7eb8394e946 100644 --- a/core/modules/system/tests/src/Functional/Menu/AssertMenuActiveTrailTrait.php +++ b/core/modules/system/tests/src/Functional/Menu/AssertMenuActiveTrailTrait.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Functional\Menu; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Url; /** @@ -56,7 +57,7 @@ trait AssertMenuActiveTrailTrait { ':title' => $active_link_title, ]; $elements = $this->xpath($xpath, $args); - $this->assertTrue(!empty($elements), format_string('Active link %title was found in menu tree, including active trail links %tree.', [ + $this->assertTrue(!empty($elements), new FormattableMarkup('Active link %title was found in menu tree, including active trail links %tree.', [ '%title' => $active_link_title, '%tree' => implode(' » ', $tree), ])); diff --git a/core/modules/system/tests/src/Functional/Menu/LocalTasksTest.php b/core/modules/system/tests/src/Functional/Menu/LocalTasksTest.php index fc6e8c1ac09..0afc7116242 100644 --- a/core/modules/system/tests/src/Functional/Menu/LocalTasksTest.php +++ b/core/modules/system/tests/src/Functional/Menu/LocalTasksTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Functional\Menu; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Html; use Drupal\Core\Url; use Drupal\Tests\BrowserTestBase; @@ -56,7 +57,7 @@ class LocalTasksTest extends BrowserTestBase { list($route_name, $route_parameters) = $route_info; $expected = Url::fromRoute($route_name, $route_parameters)->toString(); $method = ($elements[$index]->getAttribute('href') == $expected ? 'pass' : 'fail'); - $this->{$method}(format_string('Task @number href @value equals @expected.', [ + $this->{$method}(new FormattableMarkup('Task @number href @value equals @expected.', [ '@number' => $index + 1, '@value' => $elements[$index]->getAttribute('href'), '@expected' => $expected, diff --git a/core/modules/system/tests/src/Functional/Module/InstallTest.php b/core/modules/system/tests/src/Functional/Module/InstallTest.php index 360441271c9..43b66782f3a 100644 --- a/core/modules/system/tests/src/Functional/Module/InstallTest.php +++ b/core/modules/system/tests/src/Functional/Module/InstallTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Functional\Module; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Database\Database; use Drupal\Core\Extension\ExtensionNameLengthException; use Drupal\Tests\BrowserTestBase; @@ -71,7 +72,7 @@ class InstallTest extends BrowserTestBase { */ public function testModuleNameLength() { $module_name = 'invalid_module_name_over_the_maximum_allowed_character_length'; - $message = format_string('Exception thrown when enabling module %name with a name length over the allowed maximum', ['%name' => $module_name]); + $message = new FormattableMarkup('Exception thrown when enabling module %name with a name length over the allowed maximum', ['%name' => $module_name]); try { $this->container->get('module_installer')->install([$module_name]); $this->fail($message); @@ -81,7 +82,7 @@ class InstallTest extends BrowserTestBase { } // Since for the UI, the submit callback uses FALSE, test that too. - $message = format_string('Exception thrown when enabling as if via the UI the module %name with a name length over the allowed maximum', ['%name' => $module_name]); + $message = new FormattableMarkup('Exception thrown when enabling as if via the UI the module %name with a name length over the allowed maximum', ['%name' => $module_name]); try { $this->container->get('module_installer')->install([$module_name], FALSE); $this->fail($message); diff --git a/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php b/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php index 40ef29fcc9a..88007a05b8c 100644 --- a/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php +++ b/core/modules/system/tests/src/Functional/Module/ModuleTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Functional\Module; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Config\InstallStorage; use Drupal\Core\Database\Database; use Drupal\Core\Config\FileStorage; @@ -43,9 +44,9 @@ abstract class ModuleTestBase extends BrowserTestBase { $tables = $connection->schema()->findTables($connection->prefixTables('{' . $base_table . '}') . '%'); if ($count) { - return $this->assertTrue($tables, format_string('Tables matching "@base_table" found.', ['@base_table' => $base_table])); + return $this->assertTrue($tables, new FormattableMarkup('Tables matching "@base_table" found.', ['@base_table' => $base_table])); } - return $this->assertFalse($tables, format_string('Tables matching "@base_table" not found.', ['@base_table' => $base_table])); + return $this->assertFalse($tables, new FormattableMarkup('Tables matching "@base_table" not found.', ['@base_table' => $base_table])); } /** @@ -63,7 +64,7 @@ abstract class ModuleTestBase extends BrowserTestBase { $tables_exist = FALSE; } } - return $this->assertTrue($tables_exist, format_string('All database tables defined by the @module module exist.', ['@module' => $module])); + return $this->assertTrue($tables_exist, new FormattableMarkup('All database tables defined by the @module module exist.', ['@module' => $module])); } /** @@ -81,7 +82,7 @@ abstract class ModuleTestBase extends BrowserTestBase { $tables_exist = TRUE; } } - return $this->assertFalse($tables_exist, format_string('None of the database tables defined by the @module module exist.', ['@module' => $module])); + return $this->assertFalse($tables_exist, new FormattableMarkup('None of the database tables defined by the @module module exist.', ['@module' => $module])); } /** @@ -127,7 +128,7 @@ abstract class ModuleTestBase extends BrowserTestBase { } // Verify that all configuration has been installed (which means that $names // is empty). - return $this->assertFalse($names, format_string('All default configuration of @module module found.', ['@module' => $module])); + return $this->assertFalse($names, new FormattableMarkup('All default configuration of @module module found.', ['@module' => $module])); } /** @@ -141,7 +142,7 @@ abstract class ModuleTestBase extends BrowserTestBase { */ public function assertNoModuleConfig($module) { $names = \Drupal::configFactory()->listAll($module . '.'); - return $this->assertFalse($names, format_string('No configuration found for @module module.', ['@module' => $module])); + return $this->assertFalse($names, new FormattableMarkup('No configuration found for @module module.', ['@module' => $module])); } /** @@ -161,7 +162,7 @@ abstract class ModuleTestBase extends BrowserTestBase { else { $message = 'Module "@module" is not enabled.'; } - $this->assertEqual($this->container->get('module_handler')->moduleExists($module), $enabled, format_string($message, ['@module' => $module])); + $this->assertEqual($this->container->get('module_handler')->moduleExists($module), $enabled, new FormattableMarkup($message, ['@module' => $module])); } } @@ -195,7 +196,7 @@ abstract class ModuleTestBase extends BrowserTestBase { ->countQuery() ->execute() ->fetchField(); - $this->assertTrue($count > 0, format_string('watchdog table contains @count rows for @message', ['@count' => $count, '@message' => format_string($message, $variables)])); + $this->assertTrue($count > 0, new FormattableMarkup('watchdog table contains @count rows for @message', ['@count' => $count, '@message' => new FormattableMarkup($message, $variables)])); } } diff --git a/core/modules/system/tests/src/Functional/Path/UrlAlterFunctionalTest.php b/core/modules/system/tests/src/Functional/Path/UrlAlterFunctionalTest.php index afd697a5826..764d3892bc2 100644 --- a/core/modules/system/tests/src/Functional/Path/UrlAlterFunctionalTest.php +++ b/core/modules/system/tests/src/Functional/Path/UrlAlterFunctionalTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Functional\Path; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Database\Database; use Drupal\Core\Url; use Drupal\Tests\BrowserTestBase; @@ -95,7 +96,7 @@ class UrlAlterFunctionalTest extends BrowserTestBase { protected function assertUrlOutboundAlter($original, $final) { // Test outbound altering. $result = $this->container->get('path_processor_manager')->processOutbound($original); - return $this->assertIdentical($result, $final, format_string('Altered outbound URL %original, expected %final, and got %result.', ['%original' => $original, '%final' => $final, '%result' => $result])); + return $this->assertIdentical($result, $final, new FormattableMarkup('Altered outbound URL %original, expected %final, and got %result.', ['%original' => $original, '%final' => $final, '%result' => $result])); } /** @@ -112,7 +113,7 @@ class UrlAlterFunctionalTest extends BrowserTestBase { protected function assertUrlInboundAlter($original, $final) { // Test inbound altering. $result = $this->container->get('path.alias_manager')->getPathByAlias($original); - return $this->assertIdentical($result, $final, format_string('Altered inbound URL %original, expected %final, and got %result.', ['%original' => $original, '%final' => $final, '%result' => $result])); + return $this->assertIdentical($result, $final, new FormattableMarkup('Altered inbound URL %original, expected %final, and got %result.', ['%original' => $original, '%final' => $final, '%result' => $result])); } } diff --git a/core/modules/system/tests/src/Functional/Session/SessionTest.php b/core/modules/system/tests/src/Functional/Session/SessionTest.php index fc95ac2be6f..0822fe435c4 100644 --- a/core/modules/system/tests/src/Functional/Session/SessionTest.php +++ b/core/modules/system/tests/src/Functional/Session/SessionTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Functional\Session; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Database\Database; use Drupal\Tests\BrowserTestBase; @@ -65,7 +66,7 @@ class SessionTest extends BrowserTestBase { ]; $this->drupalPostForm('user/login', $edit, t('Log in')); $this->drupalGet('user'); - $pass = $this->assertText($user->getAccountName(), format_string('Found name: %name', ['%name' => $user->getAccountName()]), 'User login'); + $pass = $this->assertText($user->getAccountName(), new FormattableMarkup('Found name: %name', ['%name' => $user->getAccountName()]), 'User login'); $this->_logged_in = $pass; $this->drupalGet('session-test/id'); diff --git a/core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php b/core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php index 3ab502e8644..72905374414 100644 --- a/core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php +++ b/core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php @@ -121,10 +121,10 @@ class ErrorHandlerTest extends BrowserTestBase { $this->assertSession()->statusCodeEquals(500); // We cannot use assertErrorMessage() since the exact error reported // varies from database to database. Check that the SQL string is displayed. - $this->assertText($error_pdo_exception['%type'], format_string('Found %type in error page.', $error_pdo_exception)); - $this->assertText($error_pdo_exception['@message'], format_string('Found @message in error page.', $error_pdo_exception)); - $error_details = format_string('in %function (line ', $error_pdo_exception); - $this->assertRaw($error_details, format_string("Found '@message' in error page.", ['@message' => $error_details])); + $this->assertText($error_pdo_exception['%type'], new FormattableMarkup('Found %type in error page.', $error_pdo_exception)); + $this->assertText($error_pdo_exception['@message'], new FormattableMarkup('Found @message in error page.', $error_pdo_exception)); + $error_details = new FormattableMarkup('in %function (line ', $error_pdo_exception); + $this->assertRaw($error_details, new FormattableMarkup("Found '@message' in error page.", ['@message' => $error_details])); $this->drupalGet('error-test/trigger-renderer-exception'); $this->assertSession()->statusCodeEquals(500); @@ -147,7 +147,7 @@ class ErrorHandlerTest extends BrowserTestBase { */ public function assertErrorMessage(array $error) { $message = new FormattableMarkup('%type: @message in %function (line ', $error); - $this->assertRaw($message, format_string('Found error message: @message.', ['@message' => $message])); + $this->assertRaw($message, new FormattableMarkup('Found error message: @message.', ['@message' => $message])); } /** @@ -155,7 +155,7 @@ class ErrorHandlerTest extends BrowserTestBase { */ public function assertNoErrorMessage(array $error) { $message = new FormattableMarkup('%type: @message in %function (line ', $error); - $this->assertNoRaw($message, format_string('Did not find error message: @message.', ['@message' => $message])); + $this->assertNoRaw($message, new FormattableMarkup('Did not find error message: @message.', ['@message' => $message])); } /** diff --git a/core/modules/system/tests/src/FunctionalJavascript/FrameworkTest.php b/core/modules/system/tests/src/FunctionalJavascript/FrameworkTest.php index 60f10b35f93..4d8fd5fb911 100644 --- a/core/modules/system/tests/src/FunctionalJavascript/FrameworkTest.php +++ b/core/modules/system/tests/src/FunctionalJavascript/FrameworkTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\FunctionalJavascript; +use Drupal\Component\Render\FormattableMarkup; use Drupal\FunctionalJavascriptTests\WebDriverTestBase; /** @@ -37,9 +38,9 @@ class FrameworkTest extends WebDriverTestBase { // Verify that the base page doesn't have the settings and files that are to // be lazy loaded as part of the next requests. - $this->assertTrue(!isset($original_settings[$expected['setting_name']]), format_string('Page originally lacks the %setting, as expected.', ['%setting' => $expected['setting_name']])); - $this->assertTrue(!in_array($expected['library_1'], $original_libraries), format_string('Page originally lacks the %library library, as expected.', ['%library' => $expected['library_1']])); - $this->assertTrue(!in_array($expected['library_2'], $original_libraries), format_string('Page originally lacks the %library library, as expected.', ['%library' => $expected['library_2']])); + $this->assertTrue(!isset($original_settings[$expected['setting_name']]), new FormattableMarkup('Page originally lacks the %setting, as expected.', ['%setting' => $expected['setting_name']])); + $this->assertTrue(!in_array($expected['library_1'], $original_libraries), new FormattableMarkup('Page originally lacks the %library library, as expected.', ['%library' => $expected['library_1']])); + $this->assertTrue(!in_array($expected['library_2'], $original_libraries), new FormattableMarkup('Page originally lacks the %library library, as expected.', ['%library' => $expected['library_2']])); // Submit the AJAX request without triggering files getting added. $page->pressButton('Submit'); @@ -48,9 +49,9 @@ class FrameworkTest extends WebDriverTestBase { $new_libraries = explode(',', $new_settings['ajaxPageState']['libraries']); // Verify the setting was not added when not expected. - $this->assertTrue(!isset($new_settings[$expected['setting_name']]), format_string('Page still lacks the %setting, as expected.', ['%setting' => $expected['setting_name']])); - $this->assertTrue(!in_array($expected['library_1'], $new_libraries), format_string('Page still lacks the %library library, as expected.', ['%library' => $expected['library_1']])); - $this->assertTrue(!in_array($expected['library_2'], $new_libraries), format_string('Page still lacks the %library library, as expected.', ['%library' => $expected['library_2']])); + $this->assertTrue(!isset($new_settings[$expected['setting_name']]), new FormattableMarkup('Page still lacks the %setting, as expected.', ['%setting' => $expected['setting_name']])); + $this->assertTrue(!in_array($expected['library_1'], $new_libraries), new FormattableMarkup('Page still lacks the %library library, as expected.', ['%library' => $expected['library_1']])); + $this->assertTrue(!in_array($expected['library_2'], $new_libraries), new FormattableMarkup('Page still lacks the %library library, as expected.', ['%library' => $expected['library_2']])); // Submit the AJAX request and trigger adding files. $page->checkField('add_files'); @@ -61,11 +62,11 @@ class FrameworkTest extends WebDriverTestBase { // Verify the expected setting was added, both to drupalSettings, and as // the first AJAX command. - $this->assertIdentical($new_settings[$expected['setting_name']], $expected['setting_value'], format_string('Page now has the %setting.', ['%setting' => $expected['setting_name']])); + $this->assertIdentical($new_settings[$expected['setting_name']], $expected['setting_value'], new FormattableMarkup('Page now has the %setting.', ['%setting' => $expected['setting_name']])); // Verify the expected CSS file was added, both to drupalSettings, and as // the second AJAX command for inclusion into the HTML. - $this->assertTrue(in_array($expected['library_1'], $new_libraries), format_string('Page state now has the %library library.', ['%library' => $expected['library_1']])); + $this->assertTrue(in_array($expected['library_1'], $new_libraries), new FormattableMarkup('Page state now has the %library library.', ['%library' => $expected['library_1']])); // Verify the expected JS file was added, both to drupalSettings, and as // the third AJAX command for inclusion into the HTML. By testing for an @@ -73,7 +74,7 @@ class FrameworkTest extends WebDriverTestBase { // unexpected JavaScript code, such as a jQuery.extend() that would // potentially clobber rather than properly merge settings, didn't // accidentally get added. - $this->assertTrue(in_array($expected['library_2'], $new_libraries), format_string('Page state now has the %library library.', ['%library' => $expected['library_2']])); + $this->assertTrue(in_array($expected['library_2'], $new_libraries), new FormattableMarkup('Page state now has the %library library.', ['%library' => $expected['library_2']])); } /** diff --git a/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php b/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php index 8915815e2dc..8d0ef50df27 100644 --- a/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php +++ b/core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Kernel\Block; +use Drupal\Component\Render\FormattableMarkup; use Drupal\KernelTests\KernelTestBase; use Drupal\system\Entity\Menu; use Drupal\block\Entity\Block; @@ -227,7 +228,7 @@ class SystemMenuBlockTest extends KernelTestBase { foreach ($blocks as $id => $block) { $block_build = $block->build(); $items = isset($block_build['#items']) ? $block_build['#items'] : []; - $this->assertIdentical($no_active_trail_expectations[$id], $this->convertBuiltMenuToIdTree($items), format_string('Menu block %id with no active trail renders the expected tree.', ['%id' => $id])); + $this->assertIdentical($no_active_trail_expectations[$id], $this->convertBuiltMenuToIdTree($items), new FormattableMarkup('Menu block %id with no active trail renders the expected tree.', ['%id' => $id])); } // Scenario 2: test all block instances when there's an active trail. @@ -279,7 +280,7 @@ class SystemMenuBlockTest extends KernelTestBase { foreach ($blocks as $id => $block) { $block_build = $block->build(); $items = isset($block_build['#items']) ? $block_build['#items'] : []; - $this->assertIdentical($active_trail_expectations[$id], $this->convertBuiltMenuToIdTree($items), format_string('Menu block %id with an active trail renders the expected tree.', ['%id' => $id])); + $this->assertIdentical($active_trail_expectations[$id], $this->convertBuiltMenuToIdTree($items), new FormattableMarkup('Menu block %id with an active trail renders the expected tree.', ['%id' => $id])); } } diff --git a/core/modules/system/tests/src/Kernel/Common/AddFeedTest.php b/core/modules/system/tests/src/Kernel/Common/AddFeedTest.php index 1060b30e4a9..b7d34222fcb 100644 --- a/core/modules/system/tests/src/Kernel/Common/AddFeedTest.php +++ b/core/modules/system/tests/src/Kernel/Common/AddFeedTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Kernel\Common; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Url; use Drupal\KernelTests\KernelTestBase; @@ -68,7 +69,7 @@ class AddFeedTest extends KernelTestBase { $this->setRawContent($response->getContent()); // Assert that the content contains the RSS links we specified. foreach ($urls as $description => $feed_info) { - $this->assertPattern($this->urlToRSSLinkPattern($feed_info['url'], $feed_info['title']), format_string('Found correct feed header for %description', ['%description' => $description])); + $this->assertPattern($this->urlToRSSLinkPattern($feed_info['url'], $feed_info['title']), new FormattableMarkup('Found correct feed header for %description', ['%description' => $description])); } } diff --git a/core/modules/system/tests/src/Kernel/Common/FormElementsRenderTest.php b/core/modules/system/tests/src/Kernel/Common/FormElementsRenderTest.php index 9568470573b..9874efa9ae6 100644 --- a/core/modules/system/tests/src/Kernel/Common/FormElementsRenderTest.php +++ b/core/modules/system/tests/src/Kernel/Common/FormElementsRenderTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Kernel\Common; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Url; use Drupal\KernelTests\KernelTestBase; @@ -145,7 +146,7 @@ class FormElementsRenderTest extends KernelTestBase { // @see \Drupal\simpletest\WebTestBase::xpath() $xpath = $this->buildXPathQuery($xpath, $xpath_args); $element += ['#value' => NULL]; - $this->assertFieldByXPath($xpath, $element['#value'], format_string('#type @type was properly rendered.', [ + $this->assertFieldByXPath($xpath, $element['#value'], new FormattableMarkup('#type @type was properly rendered.', [ '@type' => var_export($element['#type'], TRUE), ])); } diff --git a/core/modules/system/tests/src/Kernel/Common/SystemListingTest.php b/core/modules/system/tests/src/Kernel/Common/SystemListingTest.php index 1a3f373f34a..1ff6a845508 100644 --- a/core/modules/system/tests/src/Kernel/Common/SystemListingTest.php +++ b/core/modules/system/tests/src/Kernel/Common/SystemListingTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Kernel\Common; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Extension\ExtensionDiscovery; use Drupal\KernelTests\KernelTestBase; @@ -33,7 +34,7 @@ class SystemListingTest extends KernelTestBase { foreach ($expected_directories as $module => $directories) { foreach ($directories as $directory) { $filename = "$directory/$module/$module.info.yml"; - $this->assertTrue(file_exists($this->root . '/' . $filename), format_string('@filename exists.', ['@filename' => $filename])); + $this->assertTrue(file_exists($this->root . '/' . $filename), new FormattableMarkup('@filename exists.', ['@filename' => $filename])); } } @@ -45,7 +46,7 @@ class SystemListingTest extends KernelTestBase { foreach ($expected_directories as $module => $directories) { $expected_directory = array_shift($directories); $expected_uri = "$expected_directory/$module/$module.info.yml"; - $this->assertEqual($files[$module]->getPathname(), $expected_uri, format_string('Module @actual was found at @expected.', [ + $this->assertEqual($files[$module]->getPathname(), $expected_uri, new FormattableMarkup('Module @actual was found at @expected.', [ '@actual' => $files[$module]->getPathname(), '@expected' => $expected_uri, ])); diff --git a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php index ffaf56bdb33..698de170a65 100644 --- a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php +++ b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Kernel\Extension; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Extension\MissingDependencyException; use Drupal\Core\Extension\ModuleUninstallValidatorException; use Drupal\entity_test\Entity\EntityTest; @@ -61,7 +62,7 @@ class ModuleHandlerTest extends KernelTestBase { protected function assertModuleList(array $expected_values, $condition) { $expected_values = array_values(array_unique($expected_values)); $enabled_modules = array_keys($this->container->get('module_handler')->getModuleList()); - $this->assertEqual($expected_values, $enabled_modules, format_string('@condition: extension handler returns correct results', ['@condition' => $condition])); + $this->assertEqual($expected_values, $enabled_modules, new FormattableMarkup('@condition: extension handler returns correct results', ['@condition' => $condition])); } /** diff --git a/core/modules/system/tests/src/Kernel/Form/ProgrammaticTest.php b/core/modules/system/tests/src/Kernel/Form/ProgrammaticTest.php index 28d056cecd9..456b506e72f 100644 --- a/core/modules/system/tests/src/Kernel/Form/ProgrammaticTest.php +++ b/core/modules/system/tests/src/Kernel/Form/ProgrammaticTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Kernel\Form; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Form\FormState; use Drupal\KernelTests\KernelTestBase; @@ -77,14 +78,14 @@ class ProgrammaticTest extends KernelTestBase { '%values' => print_r($values, TRUE), '%errors' => $valid_form ? t('None') : implode(' ', $errors), ]; - $this->assertTrue($valid_input == $valid_form, format_string('Input values: %values<br />Validation handler errors: %errors', $args)); + $this->assertTrue($valid_input == $valid_form, new FormattableMarkup('Input values: %values<br />Validation handler errors: %errors', $args)); // We check submitted values only if we have a valid input. if ($valid_input) { // Fetching the values that were set in the submission handler. $stored_values = $form_state->get('programmatic_form_submit'); foreach ($values as $key => $value) { - $this->assertEqual($stored_values[$key], $value, format_string('Submission handler correctly executed: %stored_key is %stored_value', ['%stored_key' => $key, '%stored_value' => print_r($value, TRUE)])); + $this->assertEqual($stored_values[$key], $value, new FormattableMarkup('Submission handler correctly executed: %stored_key is %stored_value', ['%stored_key' => $key, '%stored_value' => print_r($value, TRUE)])); } } } diff --git a/core/modules/system/tests/src/Kernel/Theme/ThemeTest.php b/core/modules/system/tests/src/Kernel/Theme/ThemeTest.php index fb54cd71e9b..b8ecab48475 100644 --- a/core/modules/system/tests/src/Kernel/Theme/ThemeTest.php +++ b/core/modules/system/tests/src/Kernel/Theme/ThemeTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\system\Kernel\Theme; +use Drupal\Component\Render\FormattableMarkup; use Drupal\KernelTests\KernelTestBase; use Drupal\Component\Render\MarkupInterface; @@ -57,7 +58,7 @@ class ThemeTest extends KernelTestBase { $foos = ['null' => NULL, 'false' => FALSE, 'integer' => 1, 'string' => 'foo', 'empty_string' => '']; foreach ($foos as $type => $example) { $output = \Drupal::theme()->render('theme_test_foo', ['foo' => $example]); - $this->assertTrue($output instanceof MarkupInterface || is_string($output), format_string('\Drupal::theme() returns an object that implements MarkupInterface or a string for data type @type.', ['@type' => $type])); + $this->assertTrue($output instanceof MarkupInterface || is_string($output), new FormattableMarkup('\Drupal::theme() returns an object that implements MarkupInterface or a string for data type @type.', ['@type' => $type])); if ($output instanceof MarkupInterface) { $this->assertIdentical((string) $example, $output->__toString()); } diff --git a/core/modules/system/tests/src/Kernel/Token/TokenReplaceKernelTest.php b/core/modules/system/tests/src/Kernel/Token/TokenReplaceKernelTest.php index 8f71253c9e9..1f86dd386ab 100644 --- a/core/modules/system/tests/src/Kernel/Token/TokenReplaceKernelTest.php +++ b/core/modules/system/tests/src/Kernel/Token/TokenReplaceKernelTest.php @@ -48,7 +48,7 @@ class TokenReplaceKernelTest extends TokenReplaceKernelTestBase { $input = $test['prefix'] . '[site:name]' . $test['suffix']; $expected = $test['prefix'] . 'Drupal' . $test['suffix']; $output = $this->tokenService->replace($input, [], ['langcode' => $this->interfaceLanguage->getId()]); - $this->assertTrue($output == $expected, format_string('Token recognized in string %string', ['%string' => $input])); + $this->assertTrue($output == $expected, new FormattableMarkup('Token recognized in string %string', ['%string' => $input])); } // Test token replacement when the string contains no tokens. @@ -150,7 +150,7 @@ class TokenReplaceKernelTest extends TokenReplaceKernelTestBase { foreach ($tests as $input => $expected) { $output = $this->tokenService->replace($input, ['date' => $date], ['langcode' => $this->interfaceLanguage->getId()]); - $this->assertEqual($output, $expected, format_string('Date token %token replaced.', ['%token' => $input])); + $this->assertEqual($output, $expected, new FormattableMarkup('Date token %token replaced.', ['%token' => $input])); } } diff --git a/core/modules/taxonomy/tests/src/Functional/LoadMultipleTest.php b/core/modules/taxonomy/tests/src/Functional/LoadMultipleTest.php index 292e7b17160..14ce5548c67 100644 --- a/core/modules/taxonomy/tests/src/Functional/LoadMultipleTest.php +++ b/core/modules/taxonomy/tests/src/Functional/LoadMultipleTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\taxonomy\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\taxonomy\Entity\Term; /** @@ -34,7 +35,7 @@ class LoadMultipleTest extends TaxonomyTestBase { $term_storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term'); $terms = $term_storage->loadByProperties(['vid' => $vocabulary->id()]); $count = count($terms); - $this->assertEqual($count, 5, format_string('Correct number of terms were loaded. @count terms.', ['@count' => $count])); + $this->assertEqual($count, 5, new FormattableMarkup('Correct number of terms were loaded. @count terms.', ['@count' => $count])); // Load the same terms again by tid. $terms2 = Term::loadMultiple(array_keys($terms)); diff --git a/core/modules/taxonomy/tests/src/Functional/TermTest.php b/core/modules/taxonomy/tests/src/Functional/TermTest.php index ca283b33f63..d0f5b306778 100644 --- a/core/modules/taxonomy/tests/src/Functional/TermTest.php +++ b/core/modules/taxonomy/tests/src/Functional/TermTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\taxonomy\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Tags; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\field\Entity\FieldConfig; @@ -304,10 +305,10 @@ class TermTest extends TaxonomyTestBase { $this->drupalGet('node/' . $node->id()); foreach ($term_names as $term_name) { - $this->assertText($term_name, format_string('The term %name appears on the node page after two terms, %deleted1 and %deleted2, were deleted.', ['%name' => $term_name, '%deleted1' => $term_objects['term1']->getName(), '%deleted2' => $term_objects['term2']->getName()])); + $this->assertText($term_name, new FormattableMarkup('The term %name appears on the node page after two terms, %deleted1 and %deleted2, were deleted.', ['%name' => $term_name, '%deleted1' => $term_objects['term1']->getName(), '%deleted2' => $term_objects['term2']->getName()])); } - $this->assertNoText($term_objects['term1']->getName(), format_string('The deleted term %name does not appear on the node page.', ['%name' => $term_objects['term1']->getName()])); - $this->assertNoText($term_objects['term2']->getName(), format_string('The deleted term %name does not appear on the node page.', ['%name' => $term_objects['term2']->getName()])); + $this->assertNoText($term_objects['term1']->getName(), new FormattableMarkup('The deleted term %name does not appear on the node page.', ['%name' => $term_objects['term1']->getName()])); + $this->assertNoText($term_objects['term2']->getName(), new FormattableMarkup('The deleted term %name does not appear on the node page.', ['%name' => $term_objects['term2']->getName()])); } /** diff --git a/core/modules/taxonomy/tests/src/Functional/TokenReplaceTest.php b/core/modules/taxonomy/tests/src/Functional/TokenReplaceTest.php index 3806820d2c6..5bd236b6428 100644 --- a/core/modules/taxonomy/tests/src/Functional/TokenReplaceTest.php +++ b/core/modules/taxonomy/tests/src/Functional/TokenReplaceTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\taxonomy\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Render\BubbleableMetadata; @@ -105,7 +106,7 @@ class TokenReplaceTest extends TaxonomyTestBase { foreach ($tests as $input => $expected) { $bubbleable_metadata = new BubbleableMetadata(); $output = $token_service->replace($input, ['term' => $term1], ['langcode' => $language_interface->getId()], $bubbleable_metadata); - $this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', ['%token' => $input])); + $this->assertEqual($output, $expected, new FormattableMarkup('Sanitized taxonomy term token %token replaced.', ['%token' => $input])); $this->assertEqual($bubbleable_metadata, $metadata_tests[$input]); } @@ -126,7 +127,7 @@ class TokenReplaceTest extends TaxonomyTestBase { foreach ($tests as $input => $expected) { $output = $token_service->replace($input, ['term' => $term2], ['langcode' => $language_interface->getId()]); - $this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', ['%token' => $input])); + $this->assertEqual($output, $expected, new FormattableMarkup('Sanitized taxonomy term token %token replaced.', ['%token' => $input])); } // Generate and test sanitized tokens. @@ -142,7 +143,7 @@ class TokenReplaceTest extends TaxonomyTestBase { foreach ($tests as $input => $expected) { $output = $token_service->replace($input, ['vocabulary' => $this->vocabulary], ['langcode' => $language_interface->getId()]); - $this->assertEqual($output, $expected, format_string('Sanitized taxonomy vocabulary token %token replaced.', ['%token' => $input])); + $this->assertEqual($output, $expected, new FormattableMarkup('Sanitized taxonomy vocabulary token %token replaced.', ['%token' => $input])); } } diff --git a/core/modules/taxonomy/tests/src/Kernel/TermValidationTest.php b/core/modules/taxonomy/tests/src/Kernel/TermValidationTest.php index 268c3a6a6fb..8c0662ba42c 100644 --- a/core/modules/taxonomy/tests/src/Kernel/TermValidationTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/TermValidationTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\taxonomy\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; /** @@ -58,7 +59,7 @@ class TermValidationTest extends EntityKernelTestBase { $term->set('parent', 9999); $violations = $term->validate(); $this->assertEqual(count($violations), 1, 'Violation found when term parent is invalid.'); - $this->assertEqual($violations[0]->getMessage(), format_string('The referenced entity (%type: %id) does not exist.', ['%type' => 'taxonomy_term', '%id' => 9999])); + $this->assertEqual($violations[0]->getMessage(), new FormattableMarkup('The referenced entity (%type: %id) does not exist.', ['%type' => 'taxonomy_term', '%id' => 9999])); $term->set('parent', 0); $violations = $term->validate(); diff --git a/core/modules/text/tests/src/Kernel/TextFormatterTest.php b/core/modules/text/tests/src/Kernel/TextFormatterTest.php index c75ac34bc43..20cf598eb3a 100644 --- a/core/modules/text/tests/src/Kernel/TextFormatterTest.php +++ b/core/modules/text/tests/src/Kernel/TextFormatterTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\text\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\field\Entity\FieldConfig; use Drupal\filter\Entity\FilterFormat; use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; @@ -91,7 +92,7 @@ class TextFormatterTest extends EntityKernelTestBase { $build = $entity->get('formatted_text')->view(['type' => $formatter]); \Drupal::service('renderer')->renderRoot($build[0]); $this->assertEqual($build[0]['#markup'], "<p>Hello, world!</p>\n"); - $this->assertEqual($build[0]['#cache']['tags'], FilterFormat::load('my_text_format')->getCacheTags(), format_string('The @formatter formatter has the expected cache tags when formatting a formatted text field.', ['@formatter' => $formatter])); + $this->assertEqual($build[0]['#cache']['tags'], FilterFormat::load('my_text_format')->getCacheTags(), new FormattableMarkup('The @formatter formatter has the expected cache tags when formatting a formatted text field.', ['@formatter' => $formatter])); } } diff --git a/core/modules/text/tests/src/Kernel/TextSummaryTest.php b/core/modules/text/tests/src/Kernel/TextSummaryTest.php index 015f734698f..bcd0cf33805 100644 --- a/core/modules/text/tests/src/Kernel/TextSummaryTest.php +++ b/core/modules/text/tests/src/Kernel/TextSummaryTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\text\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\entity_test\Entity\EntityTest; use Drupal\field\Entity\FieldConfig; @@ -235,7 +236,7 @@ class TextSummaryTest extends KernelTestBase { */ public function assertTextSummary($text, $expected, $format = NULL, $size = NULL) { $summary = text_summary($text, $format, $size); - $this->assertIdentical($summary, $expected, format_string('<pre style="white-space: pre-wrap">@actual</pre> is identical to <pre style="white-space: pre-wrap">@expected</pre>', [ + $this->assertIdentical($summary, $expected, new FormattableMarkup('<pre style="white-space: pre-wrap">@actual</pre> is identical to <pre style="white-space: pre-wrap">@expected</pre>', [ '@actual' => $summary, '@expected' => $expected, ])); diff --git a/core/modules/tour/src/Tests/TourTestBase.php b/core/modules/tour/src/Tests/TourTestBase.php index eca2ef8a157..ae35dfd6be5 100644 --- a/core/modules/tour/src/Tests/TourTestBase.php +++ b/core/modules/tour/src/Tests/TourTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\tour\Tests; +use Drupal\Component\Render\FormattableMarkup; use Drupal\simpletest\WebTestBase; @trigger_error('\Drupal\tour\Tests\TourTestBase is deprecated in 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\tour\Functional\TourTestBase.', E_USER_DEPRECATED); @@ -56,11 +57,11 @@ abstract class TourTestBase extends WebTestBase { foreach ($tips as $tip) { if (!empty($tip['data-id'])) { $elements = $this->xpath('//*[@id="' . $tip['data-id'] . '"]'); - $this->assertTrue(!empty($elements) && count($elements) === 1, format_string('Found corresponding page element for tour tip with id #%data-id', ['%data-id' => $tip['data-id']])); + $this->assertTrue(!empty($elements) && count($elements) === 1, new FormattableMarkup('Found corresponding page element for tour tip with id #%data-id', ['%data-id' => $tip['data-id']])); } elseif (!empty($tip['data-class'])) { $elements = $this->xpath('//*[contain(@class, "' . $tip['data-id'] . '")]'); - $this->assertFalse(empty($elements), format_string('Found corresponding page element for tour tip with class .%data-class', ['%data-class' => $tip['data-class']])); + $this->assertFalse(empty($elements), new FormattableMarkup('Found corresponding page element for tour tip with class .%data-class', ['%data-class' => $tip['data-class']])); } else { // It's a modal. @@ -68,7 +69,7 @@ abstract class TourTestBase extends WebTestBase { } $total++; } - $this->pass(format_string('Total %total Tips tested of which %modals modal(s).', ['%total' => $total, '%modals' => $modals])); + $this->pass(new FormattableMarkup('Total %total Tips tested of which %modals modal(s).', ['%total' => $total, '%modals' => $modals])); } } diff --git a/core/modules/tour/tests/src/Functional/TourTestBase.php b/core/modules/tour/tests/src/Functional/TourTestBase.php index a8487def61e..6274a8b941e 100644 --- a/core/modules/tour/tests/src/Functional/TourTestBase.php +++ b/core/modules/tour/tests/src/Functional/TourTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\tour\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Tests\BrowserTestBase; /** @@ -53,11 +54,11 @@ abstract class TourTestBase extends BrowserTestBase { foreach ($tips as $tip) { if (!empty($tip['data-id'])) { $elements = $this->getSession()->getPage()->findAll('css', '#' . $tip['data-id']); - $this->assertTrue(!empty($elements) && count($elements) === 1, format_string('Found corresponding page element for tour tip with id #%data-id', ['%data-id' => $tip['data-id']])); + $this->assertTrue(!empty($elements) && count($elements) === 1, new FormattableMarkup('Found corresponding page element for tour tip with id #%data-id', ['%data-id' => $tip['data-id']])); } elseif (!empty($tip['data-class'])) { $elements = $this->getSession()->getPage()->findAll('css', '.' . $tip['data-class']); - $this->assertFalse(empty($elements), format_string('Found corresponding page element for tour tip with class .%data-class', ['%data-class' => $tip['data-class']])); + $this->assertFalse(empty($elements), new FormattableMarkup('Found corresponding page element for tour tip with class .%data-class', ['%data-class' => $tip['data-class']])); } else { // It's a modal. @@ -65,7 +66,7 @@ abstract class TourTestBase extends BrowserTestBase { } $total++; } - $this->pass(format_string('Total %total Tips tested of which %modals modal(s).', ['%total' => $total, '%modals' => $modals])); + $this->pass(new FormattableMarkup('Total %total Tips tested of which %modals modal(s).', ['%total' => $total, '%modals' => $modals])); } } diff --git a/core/modules/tracker/tests/src/Functional/TrackerTest.php b/core/modules/tracker/tests/src/Functional/TrackerTest.php index bd13151c779..63d1cb2f426 100644 --- a/core/modules/tracker/tests/src/Functional/TrackerTest.php +++ b/core/modules/tracker/tests/src/Functional/TrackerTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\tracker\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\comment\CommentInterface; use Drupal\comment\Tests\CommentTestTrait; use Drupal\Core\Cache\Cache; @@ -388,7 +389,7 @@ class TrackerTest extends BrowserTestBase { // Assert that all node titles are displayed. foreach ($nodes as $i => $node) { - $this->assertText($node->label(), format_string('Node @i is displayed on the tracker listing pages.', ['@i' => $i])); + $this->assertText($node->label(), new FormattableMarkup('Node @i is displayed on the tracker listing pages.', ['@i' => $i])); } // Fetch the site-wide tracker. @@ -396,7 +397,7 @@ class TrackerTest extends BrowserTestBase { // Assert that all node titles are displayed. foreach ($nodes as $i => $node) { - $this->assertText($node->label(), format_string('Node @i is displayed on the tracker listing pages.', ['@i' => $i])); + $this->assertText($node->label(), new FormattableMarkup('Node @i is displayed on the tracker listing pages.', ['@i' => $i])); } } diff --git a/core/modules/user/tests/src/Functional/UserTokenReplaceTest.php b/core/modules/user/tests/src/Functional/UserTokenReplaceTest.php index 3b163ab5227..7ff6b31b8ea 100644 --- a/core/modules/user/tests/src/Functional/UserTokenReplaceTest.php +++ b/core/modules/user/tests/src/Functional/UserTokenReplaceTest.php @@ -126,7 +126,7 @@ class UserTokenReplaceTest extends BrowserTestBase { foreach ($tests as $input => $expected) { $bubbleable_metadata = new BubbleableMetadata(); $output = $token_service->replace($input, ['user' => $anonymous_user], ['langcode' => $language_interface->getId()], $bubbleable_metadata); - $this->assertEqual($output, $expected, format_string('Sanitized user token %token replaced.', ['%token' => $input])); + $this->assertEqual($output, $expected, new FormattableMarkup('Sanitized user token %token replaced.', ['%token' => $input])); $this->assertEqual($bubbleable_metadata, $metadata_tests[$input]); } diff --git a/core/modules/views/src/Tests/ViewResultAssertionTrait.php b/core/modules/views/src/Tests/ViewResultAssertionTrait.php index f0387eadb28..8f2bafbae70 100644 --- a/core/modules/views/src/Tests/ViewResultAssertionTrait.php +++ b/core/modules/views/src/Tests/ViewResultAssertionTrait.php @@ -2,6 +2,7 @@ namespace Drupal\views\Tests; +use Drupal\Component\Render\FormattableMarkup; use Drupal\views\Plugin\views\field\EntityField; /** @@ -138,7 +139,7 @@ trait ViewResultAssertionTrait { // Do the actual comparison. if (!isset($message)) { $not = (strpos($assert_method, 'Not') ? 'not' : ''); - $message = format_string("Actual result <pre>\n@actual\n</pre> is $not identical to expected <pre>\n@expected\n</pre>", [ + $message = new FormattableMarkup("Actual result <pre>\n@actual\n</pre> is $not identical to expected <pre>\n@expected\n</pre>", [ '@actual' => var_export($result, TRUE), '@expected' => var_export($expected_result, TRUE), ]); diff --git a/core/modules/views/tests/src/Functional/BulkFormTest.php b/core/modules/views/tests/src/Functional/BulkFormTest.php index 86b0d941f85..73862992be2 100644 --- a/core/modules/views/tests/src/Functional/BulkFormTest.php +++ b/core/modules/views/tests/src/Functional/BulkFormTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Tests\BrowserTestBase; use Drupal\views\Views; @@ -54,7 +55,7 @@ class BulkFormTest extends BrowserTestBase { // Make sure a checkbox appears on all rows. $edit = []; for ($i = 0; $i < 10; $i++) { - $this->assertFieldById('edit-node-bulk-form-' . $i, NULL, format_string('The checkbox on row @row appears.', ['@row' => $i])); + $this->assertFieldById('edit-node-bulk-form-' . $i, NULL, new FormattableMarkup('The checkbox on row @row appears.', ['@row' => $i])); $edit["node_bulk_form[$i]"] = TRUE; } @@ -72,7 +73,7 @@ class BulkFormTest extends BrowserTestBase { foreach ($nodes as $node) { $changed_node = $node_storage->load($node->id()); - $this->assertTrue($changed_node->isSticky(), format_string('Node @nid got marked as sticky.', ['@nid' => $node->id()])); + $this->assertTrue($changed_node->isSticky(), new FormattableMarkup('Node @nid got marked as sticky.', ['@nid' => $node->id()])); } $this->assertText('Make content sticky was applied to 10 items.'); diff --git a/core/modules/views/tests/src/Functional/DefaultViewsTest.php b/core/modules/views/tests/src/Functional/DefaultViewsTest.php index 76bcc80fd20..7f5a4f30aac 100644 --- a/core/modules/views/tests/src/Functional/DefaultViewsTest.php +++ b/core/modules/views/tests/src/Functional/DefaultViewsTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\comment\CommentInterface; use Drupal\comment\Tests\CommentTestTrait; use Drupal\Core\Field\FieldStorageDefinitionInterface; @@ -135,14 +136,14 @@ class DefaultViewsTest extends ViewTestBase { $view->preExecute($this->viewArgMap[$name]); } - $this->assert(TRUE, format_string('View @view will be executed.', ['@view' => $view->storage->id()])); + $this->assert(TRUE, new FormattableMarkup('View @view will be executed.', ['@view' => $view->storage->id()])); $view->execute(); $tokens = ['@name' => $name, '@display_id' => $display_id]; - $this->assertTrue($view->executed, format_string('@name:@display_id has been executed.', $tokens)); + $this->assertTrue($view->executed, new FormattableMarkup('@name:@display_id has been executed.', $tokens)); $count = count($view->result); - $this->assertTrue($count > 0, format_string('@count results returned', ['@count' => $count])); + $this->assertTrue($count > 0, new FormattableMarkup('@count results returned', ['@count' => $count])); $view->destroy(); } } diff --git a/core/modules/views/tests/src/Functional/Handler/FieldWebTest.php b/core/modules/views/tests/src/Functional/Handler/FieldWebTest.php index f320876d973..c4715ab61c6 100644 --- a/core/modules/views/tests/src/Functional/Handler/FieldWebTest.php +++ b/core/modules/views/tests/src/Functional/Handler/FieldWebTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views\Functional\Handler; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Render\RenderContext; @@ -560,14 +561,14 @@ class FieldWebTest extends ViewTestBase { $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) { return $name_field->advancedRender($row); }); - $this->assertSubString($output, $trimmed_name, format_string('Make sure the trimmed output (@trimmed) appears in the rendered output (@output).', ['@trimmed' => $trimmed_name, '@output' => $output])); - $this->assertNotSubString($output, $row->views_test_data_name, format_string("Make sure the untrimmed value (@untrimmed) shouldn't appear in the rendered output (@output).", ['@untrimmed' => $row->views_test_data_name, '@output' => $output])); + $this->assertSubString($output, $trimmed_name, new FormattableMarkup('Make sure the trimmed output (@trimmed) appears in the rendered output (@output).', ['@trimmed' => $trimmed_name, '@output' => $output])); + $this->assertNotSubString($output, $row->views_test_data_name, new FormattableMarkup("Make sure the untrimmed value (@untrimmed) shouldn't appear in the rendered output (@output).", ['@untrimmed' => $row->views_test_data_name, '@output' => $output])); $name_field->options['alter']['max_length'] = 9; $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) { return $name_field->advancedRender($row); }); - $this->assertSubString($output, $trimmed_name, format_string('Make sure the untrimmed (@untrimmed) output appears in the rendered output (@output).', ['@trimmed' => $trimmed_name, '@output' => $output])); + $this->assertSubString($output, $trimmed_name, new FormattableMarkup('Make sure the untrimmed (@untrimmed) output appears in the rendered output (@output).', ['@trimmed' => $trimmed_name, '@output' => $output])); // Take word_boundary into account for the tests. $name_field->options['alter']['max_length'] = 5; @@ -611,10 +612,10 @@ class FieldWebTest extends ViewTestBase { }); if ($tuple['trimmed']) { - $this->assertNotSubString($output, $tuple['value'], format_string('The untrimmed value (@untrimmed) should not appear in the trimmed output (@output).', ['@untrimmed' => $tuple['value'], '@output' => $output])); + $this->assertNotSubString($output, $tuple['value'], new FormattableMarkup('The untrimmed value (@untrimmed) should not appear in the trimmed output (@output).', ['@untrimmed' => $tuple['value'], '@output' => $output])); } if (!empty($tuple['trimmed_value'])) { - $this->assertSubString($output, $tuple['trimmed_value'], format_string('The trimmed value (@trimmed) should appear in the trimmed output (@output).', ['@trimmed' => $tuple['trimmed_value'], '@output' => $output])); + $this->assertSubString($output, $tuple['trimmed_value'], new FormattableMarkup('The trimmed value (@trimmed) should appear in the trimmed output (@output).', ['@trimmed' => $tuple['trimmed_value'], '@output' => $output])); } } diff --git a/core/modules/views/tests/src/Functional/Handler/HandlerAllTest.php b/core/modules/views/tests/src/Functional/Handler/HandlerAllTest.php index 1a37ce83070..3c3ed24e2ac 100644 --- a/core/modules/views/tests/src/Functional/Handler/HandlerAllTest.php +++ b/core/modules/views/tests/src/Functional/Handler/HandlerAllTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views\Functional\Handler; +use Drupal\Component\Render\FormattableMarkup; use Drupal\comment\Tests\CommentTestTrait; use Drupal\Tests\views\Functional\ViewTestBase; use Drupal\views\ViewExecutable; @@ -101,7 +102,7 @@ class HandlerAllTest extends ViewTestBase { foreach ($object_types as $type) { if (isset($view->{$type})) { foreach ($view->{$type} as $handler) { - $this->assertTrue($handler instanceof HandlerBase, format_string( + $this->assertTrue($handler instanceof HandlerBase, new FormattableMarkup( '@type handler of class %class is an instance of HandlerBase', [ '@type' => $type, diff --git a/core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php b/core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php index b12e43e857c..a5eb2f02fe1 100644 --- a/core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views\Functional\Plugin; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Url; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; @@ -102,7 +103,7 @@ class ArgumentDefaultTest extends ViewTestBase { '%function' => 'views_handler_argument->validateOptionsForm()', ]; $message = t('%type: @message in %function', $error); - $this->assertNoRaw($message, format_string('Did not find error message: @message.', ['@message' => $message])); + $this->assertNoRaw($message, new FormattableMarkup('Did not find error message: @message.', ['@message' => $message])); } /** diff --git a/core/modules/views/tests/src/Functional/Plugin/FilterTest.php b/core/modules/views/tests/src/Functional/Plugin/FilterTest.php index a08bad8438c..90c00f786dd 100644 --- a/core/modules/views/tests/src/Functional/Plugin/FilterTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/FilterTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views\Functional\Plugin; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Tests\views\Functional\ViewTestBase; use Drupal\views\Views; use Drupal\views_test_data\Plugin\views\filter\FilterTest as FilterPlugin; @@ -91,7 +92,7 @@ class FilterTest extends ViewTestBase { // Check that we have a single element, as a result of applying the '= John' // filter. - $this->assertEqual(count($view->result), 1, format_string('Results were returned. @count results.', ['@count' => count($view->result)])); + $this->assertEqual(count($view->result), 1, new FormattableMarkup('Results were returned. @count results.', ['@count' => count($view->result)])); $view->destroy(); @@ -117,7 +118,7 @@ class FilterTest extends ViewTestBase { // Check if we have the other elements in the dataset, as a result of // applying the '<> John' filter. - $this->assertEqual(count($view->result), 4, format_string('Results were returned. @count results.', ['@count' => count($view->result)])); + $this->assertEqual(count($view->result), 4, new FormattableMarkup('Results were returned. @count results.', ['@count' => count($view->result)])); $view->destroy(); $view->initDisplay(); @@ -141,7 +142,7 @@ class FilterTest extends ViewTestBase { $this->executeView($view); // Check if we have all 5 results. - $this->assertEqual(count($view->result), 5, format_string('All @count results returned', ['@count' => count($view->displayHandlers)])); + $this->assertEqual(count($view->result), 5, new FormattableMarkup('All @count results returned', ['@count' => count($view->displayHandlers)])); } /** diff --git a/core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php b/core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php index 1cc6ea80793..428796fdfba 100644 --- a/core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views\Kernel\Handler; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormState; use Drupal\Tests\block\Traits\BlockCreationTrait; @@ -70,9 +71,9 @@ class AreaEntityTest extends ViewsKernelTestBase { // Test that all expected entity types have data. foreach (array_keys($expected_entities) as $entity) { - $this->assertTrue(!empty($data['entity_' . $entity]), format_string('Views entity area data found for @entity', ['@entity' => $entity])); + $this->assertTrue(!empty($data['entity_' . $entity]), new FormattableMarkup('Views entity area data found for @entity', ['@entity' => $entity])); // Test that entity_type is set correctly in the area data. - $this->assertEqual($entity, $data['entity_' . $entity]['area']['entity_type'], format_string('Correct entity_type set for @entity', ['@entity' => $entity])); + $this->assertEqual($entity, $data['entity_' . $entity]['area']['entity_type'], new FormattableMarkup('Correct entity_type set for @entity', ['@entity' => $entity])); } $expected_entities = array_filter($entity_types, function (EntityTypeInterface $type) { @@ -81,7 +82,7 @@ class AreaEntityTest extends ViewsKernelTestBase { // Test that no configuration entity types have data. foreach (array_keys($expected_entities) as $entity) { - $this->assertTrue(empty($data['entity_' . $entity]), format_string('Views config entity area data not found for @entity', ['@entity' => $entity])); + $this->assertTrue(empty($data['entity_' . $entity]), new FormattableMarkup('Views config entity area data not found for @entity', ['@entity' => $entity])); } } diff --git a/core/modules/views/tests/src/Kernel/Handler/FieldCounterTest.php b/core/modules/views/tests/src/Kernel/Handler/FieldCounterTest.php index 07f4b2c17d0..7300606f238 100644 --- a/core/modules/views/tests/src/Kernel/Handler/FieldCounterTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/FieldCounterTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views\Kernel\Handler; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Tests\views\Kernel\ViewsKernelTestBase; use Drupal\views\Views; @@ -49,11 +50,11 @@ class FieldCounterTest extends ViewsKernelTestBase { $view->preview(); $counter = $view->style_plugin->getField(0, 'counter'); - $this->assertEqual($counter, '1', format_string('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => 1, '@counter' => $counter])); + $this->assertEqual($counter, '1', new FormattableMarkup('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => 1, '@counter' => $counter])); $counter = $view->style_plugin->getField(1, 'counter'); - $this->assertEqual($counter, '2', format_string('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => 2, '@counter' => $counter])); + $this->assertEqual($counter, '2', new FormattableMarkup('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => 2, '@counter' => $counter])); $counter = $view->style_plugin->getField(2, 'counter'); - $this->assertEqual($counter, '3', format_string('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => 3, '@counter' => $counter])); + $this->assertEqual($counter, '3', new FormattableMarkup('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => 3, '@counter' => $counter])); $view->destroy(); $view->storage->invalidateCaches(); @@ -78,13 +79,13 @@ class FieldCounterTest extends ViewsKernelTestBase { $counter = $view->style_plugin->getField(0, 'counter'); $expected_number = 0 + $rand_start; - $this->assertEqual($counter, (string) $expected_number, format_string('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => $expected_number, '@counter' => $counter])); + $this->assertEqual($counter, (string) $expected_number, new FormattableMarkup('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => $expected_number, '@counter' => $counter])); $counter = $view->style_plugin->getField(1, 'counter'); $expected_number = 1 + $rand_start; - $this->assertEqual($counter, (string) $expected_number, format_string('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => $expected_number, '@counter' => $counter])); + $this->assertEqual($counter, (string) $expected_number, new FormattableMarkup('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => $expected_number, '@counter' => $counter])); $counter = $view->style_plugin->getField(2, 'counter'); $expected_number = 2 + $rand_start; - $this->assertEqual($counter, (string) $expected_number, format_string('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => $expected_number, '@counter' => $counter])); + $this->assertEqual($counter, (string) $expected_number, new FormattableMarkup('Make sure the expected number (@expected) patches with the rendered number (@counter)', ['@expected' => $expected_number, '@counter' => $counter])); } } diff --git a/core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php b/core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php index b619a05fe52..faee4e66a6a 100644 --- a/core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/FieldKernelTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views\Kernel\Handler; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Render\RenderContext; use Drupal\Tests\views\Kernel\ViewsKernelTestBase; use Drupal\views\Plugin\views\field\FieldPluginBase; @@ -298,7 +299,7 @@ class FieldKernelTest extends ViewsKernelTestBase { $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field_0, $row) { return $name_field_0->advancedRender($row); }); - $this->assertEqual($output, $expected_output_0, format_string('Test token replacement: "@token" gave "@output"', [ + $this->assertEqual($output, $expected_output_0, new FormattableMarkup('Test token replacement: "@token" gave "@output"', [ '@token' => $name_field_0->options['alter']['text'], '@output' => $output, ])); @@ -306,7 +307,7 @@ class FieldKernelTest extends ViewsKernelTestBase { $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field_1, $row) { return $name_field_1->advancedRender($row); }); - $this->assertEqual($output, $expected_output_1, format_string('Test token replacement: "@token" gave "@output"', [ + $this->assertEqual($output, $expected_output_1, new FormattableMarkup('Test token replacement: "@token" gave "@output"', [ '@token' => $name_field_1->options['alter']['text'], '@output' => $output, ])); @@ -314,7 +315,7 @@ class FieldKernelTest extends ViewsKernelTestBase { $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field_2, $row) { return $name_field_2->advancedRender($row); }); - $this->assertEqual($output, $expected_output_2, format_string('Test token replacement: "@token" gave "@output"', [ + $this->assertEqual($output, $expected_output_2, new FormattableMarkup('Test token replacement: "@token" gave "@output"', [ '@token' => $name_field_2->options['alter']['text'], '@output' => $output, ])); @@ -329,7 +330,7 @@ class FieldKernelTest extends ViewsKernelTestBase { $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($job_field, $row) { return $job_field->advancedRender($row); }); - $this->assertSubString($output, $random_text, format_string('Make sure the self token (@token => @value) appears in the output (@output)', [ + $this->assertSubString($output, $random_text, new FormattableMarkup('Make sure the self token (@token => @value) appears in the output (@output)', [ '@value' => $random_text, '@output' => $output, '@token' => $job_field->options['alter']['text'], @@ -343,7 +344,7 @@ class FieldKernelTest extends ViewsKernelTestBase { $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($job_field, $row) { return $job_field->advancedRender($row); }); - $this->assertEqual($output, $old_token, format_string('Make sure the old token style (@token => @value) is not changed in the output (@output)', [ + $this->assertEqual($output, $old_token, new FormattableMarkup('Make sure the old token style (@token => @value) is not changed in the output (@output)', [ '@value' => $random_text, '@output' => $output, '@token' => $job_field->options['alter']['text'], @@ -376,7 +377,7 @@ class FieldKernelTest extends ViewsKernelTestBase { $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($job_field, $row) { return $job_field->advancedRender($row); }); - $this->assertEqual($output, $random_text, format_string('Make sure a script tag in the template (@template) is removed, leaving only the replaced token in the output (@output)', [ + $this->assertEqual($output, $random_text, new FormattableMarkup('Make sure a script tag in the template (@template) is removed, leaving only the replaced token in the output (@output)', [ '@output' => $output, '@template' => $rewrite_template, ])); diff --git a/core/modules/views/tests/src/Kernel/ModuleTest.php b/core/modules/views/tests/src/Kernel/ModuleTest.php index a05558f8e1a..db43e96cea2 100644 --- a/core/modules/views/tests/src/Kernel/ModuleTest.php +++ b/core/modules/views/tests/src/Kernel/ModuleTest.php @@ -89,7 +89,7 @@ class ModuleTest extends ViewsKernelTestBase { 'field' => 'field_invalid', ]; $this->container->get('plugin.manager.views.field')->getHandler($item); - $this->assertTrue(strpos($this->lastErrorMessage, format_string("Missing handler: @table @field @type", ['@table' => 'views_test_data', '@field' => 'field_invalid', '@type' => 'field'])) !== FALSE, 'An invalid field name throws a debug message.'); + $this->assertTrue(strpos($this->lastErrorMessage, new FormattableMarkup("Missing handler: @table @field @type", ['@table' => 'views_test_data', '@field' => 'field_invalid', '@type' => 'field'])) !== FALSE, 'An invalid field name throws a debug message.'); unset($this->lastErrorMessage); $item = [ @@ -97,7 +97,7 @@ class ModuleTest extends ViewsKernelTestBase { 'field' => 'id', ]; $this->container->get('plugin.manager.views.filter')->getHandler($item); - $this->assertEqual(strpos($this->lastErrorMessage, format_string("Missing handler: @table @field @type", ['@table' => 'table_invalid', '@field' => 'id', '@type' => 'filter'])) !== FALSE, 'An invalid table name throws a debug message.'); + $this->assertEqual(strpos($this->lastErrorMessage, new FormattableMarkup("Missing handler: @table @field @type", ['@table' => 'table_invalid', '@field' => 'id', '@type' => 'filter'])) !== FALSE, 'An invalid table name throws a debug message.'); unset($this->lastErrorMessage); $item = [ @@ -105,7 +105,7 @@ class ModuleTest extends ViewsKernelTestBase { 'field' => 'id', ]; $this->container->get('plugin.manager.views.filter')->getHandler($item); - $this->assertEqual(strpos($this->lastErrorMessage, format_string("Missing handler: @table @field @type", ['@table' => 'table_invalid', '@field' => 'id', '@type' => 'filter'])) !== FALSE, 'An invalid table name throws a debug message.'); + $this->assertEqual(strpos($this->lastErrorMessage, new FormattableMarkup("Missing handler: @table @field @type", ['@table' => 'table_invalid', '@field' => 'id', '@type' => 'filter'])) !== FALSE, 'An invalid table name throws a debug message.'); unset($this->lastErrorMessage); restore_error_handler(); diff --git a/core/modules/views/tests/src/Kernel/Plugin/DisplayExtenderTest.php b/core/modules/views/tests/src/Kernel/Plugin/DisplayExtenderTest.php index 4ee33fb783f..ffd8d762a91 100644 --- a/core/modules/views/tests/src/Kernel/Plugin/DisplayExtenderTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/DisplayExtenderTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views\Kernel\Plugin; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Tests\views\Kernel\ViewsKernelTestBase; use Drupal\views_test_data\Plugin\views\display_extender\DisplayExtenderTest as DisplayExtenderTestData; use Drupal\views\Views; @@ -52,7 +53,7 @@ class DisplayExtenderTest extends ViewsKernelTestBase { $errors = $view->validate(); foreach ($view->displayHandlers as $id => $display) { - $this->assertTrue(isset($errors[$id]) && in_array('Display extender test error.', $errors[$id]), format_string('Error message found for @id display', ['@id' => $id])); + $this->assertTrue(isset($errors[$id]) && in_array('Display extender test error.', $errors[$id]), new FormattableMarkup('Error message found for @id display', ['@id' => $id])); } } diff --git a/core/modules/views/tests/src/Kernel/Plugin/StyleMappingTest.php b/core/modules/views/tests/src/Kernel/Plugin/StyleMappingTest.php index d0683deb47a..d83b2643ac8 100644 --- a/core/modules/views/tests/src/Kernel/Plugin/StyleMappingTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/StyleMappingTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views\Kernel\Plugin; +use Drupal\Component\Render\FormattableMarkup; use Drupal\views\Views; /** @@ -68,7 +69,7 @@ class StyleMappingTest extends StyleTestBase { // separated by ':'. $expected_result = $name . ':' . $data_set[$count][$field_id]; $actual_result = (string) $field; - $this->assertIdentical($expected_result, $actual_result, format_string('The fields were mapped successfully: %name => %field_id', ['%name' => $name, '%field_id' => $field_id])); + $this->assertIdentical($expected_result, $actual_result, new FormattableMarkup('The fields were mapped successfully: %name => %field_id', ['%name' => $name, '%field_id' => $field_id])); } $count++; diff --git a/core/modules/views/tests/src/Kernel/PluginInstanceTest.php b/core/modules/views/tests/src/Kernel/PluginInstanceTest.php index 1584b11b494..8000c960c99 100644 --- a/core/modules/views/tests/src/Kernel/PluginInstanceTest.php +++ b/core/modules/views/tests/src/Kernel/PluginInstanceTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\views\Views; use Drupal\views\Plugin\views\PluginBase; @@ -70,8 +71,8 @@ class PluginInstanceTest extends ViewsKernelTestBase { // Check all plugin types. foreach ($this->pluginTypes as $type) { - $this->assertTrue(array_key_exists($type, $this->definitions), format_string('Key for plugin type @type found.', ['@type' => $type])); - $this->assertTrue(is_array($this->definitions[$type]) && !empty($this->definitions[$type]), format_string('Plugin type @type has an array of plugins.', ['@type' => $type])); + $this->assertTrue(array_key_exists($type, $this->definitions), new FormattableMarkup('Key for plugin type @type found.', ['@type' => $type])); + $this->assertTrue(is_array($this->definitions[$type]) && !empty($this->definitions[$type]), new FormattableMarkup('Plugin type @type has an array of plugins.', ['@type' => $type])); } // Tests that the plugin list has not missed any types. diff --git a/core/modules/views/tests/src/Kernel/QueryGroupByTest.php b/core/modules/views/tests/src/Kernel/QueryGroupByTest.php index 256192ba1ea..dbedd805e8a 100644 --- a/core/modules/views/tests/src/Kernel/QueryGroupByTest.php +++ b/core/modules/views/tests/src/Kernel/QueryGroupByTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\entity_test\Entity\EntityTestMul; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; @@ -104,8 +105,8 @@ class QueryGroupByTest extends ViewsKernelTestBase { foreach ($view->result as $item) { $results[$item->entity_test_name] = $item->id; } - $this->assertEqual($results['name1'], $values[0], format_string('Aggregation with @aggregation_function and groupby name: name1 returned the expected amount of results', ['@aggregation_function' => $aggregation_function])); - $this->assertEqual($results['name2'], $values[1], format_string('Aggregation with @aggregation_function and groupby name: name2 returned the expected amount of results', ['@aggregation_function' => $aggregation_function])); + $this->assertEqual($results['name1'], $values[0], new FormattableMarkup('Aggregation with @aggregation_function and groupby name: name1 returned the expected amount of results', ['@aggregation_function' => $aggregation_function])); + $this->assertEqual($results['name2'], $values[1], new FormattableMarkup('Aggregation with @aggregation_function and groupby name: name2 returned the expected amount of results', ['@aggregation_function' => $aggregation_function])); } /** diff --git a/core/modules/views/tests/src/Kernel/TokenReplaceTest.php b/core/modules/views/tests/src/Kernel/TokenReplaceTest.php index 4b1cfc362c8..40c2709b6ca 100644 --- a/core/modules/views/tests/src/Kernel/TokenReplaceTest.php +++ b/core/modules/views/tests/src/Kernel/TokenReplaceTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Render\BubbleableMetadata; use Drupal\views\Views; @@ -68,7 +69,7 @@ class TokenReplaceTest extends ViewsKernelTestBase { foreach ($expected as $token => $expected_output) { $bubbleable_metadata = new BubbleableMetadata(); $output = $token_handler->replace($token, ['view' => $view], [], $bubbleable_metadata); - $this->assertIdentical($output, $expected_output, format_string('Token %token replaced correctly.', ['%token' => $token])); + $this->assertIdentical($output, $expected_output, new FormattableMarkup('Token %token replaced correctly.', ['%token' => $token])); $this->assertEqual($bubbleable_metadata, $metadata_tests[$token]); } } @@ -125,7 +126,7 @@ class TokenReplaceTest extends ViewsKernelTestBase { foreach ($expected as $token => $expected_output) { $output = $token_handler->replace($token, ['view' => $view]); - $this->assertIdentical($output, $expected_output, format_string('Token %token replaced correctly.', ['%token' => $token])); + $this->assertIdentical($output, $expected_output, new FormattableMarkup('Token %token replaced correctly.', ['%token' => $token])); } } @@ -144,7 +145,7 @@ class TokenReplaceTest extends ViewsKernelTestBase { foreach ($expected as $token => $expected_output) { $output = $token_handler->replace($token, ['view' => $view]); - $this->assertIdentical($output, $expected_output, format_string('Token %token replaced correctly.', ['%token' => $token])); + $this->assertIdentical($output, $expected_output, new FormattableMarkup('Token %token replaced correctly.', ['%token' => $token])); } } diff --git a/core/modules/views/tests/src/Kernel/ViewExecutableTest.php b/core/modules/views/tests/src/Kernel/ViewExecutableTest.php index 44036c6b0a3..d120856c0fd 100644 --- a/core/modules/views/tests/src/Kernel/ViewExecutableTest.php +++ b/core/modules/views/tests/src/Kernel/ViewExecutableTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\comment\Tests\CommentTestTrait; use Drupal\Component\Utility\Xss; use Drupal\node\Entity\NodeType; @@ -123,7 +124,7 @@ class ViewExecutableTest extends ViewsKernelTestBase { if ($type == 'relationship') { continue; } - $this->assertTrue(count($view->$type), format_string('Make sure a %type instance got instantiated.', ['%type' => $type])); + $this->assertTrue(count($view->$type), new FormattableMarkup('Make sure a %type instance got instantiated.', ['%type' => $type])); } // initHandlers() should create display handlers automatically as well. @@ -435,7 +436,7 @@ class ViewExecutableTest extends ViewsKernelTestBase { $match = function ($value) use ($display) { return strpos($value, $display->display['display_title']) !== FALSE; }; - $this->assertTrue(array_filter($validate[$id], $match), format_string('Error message found for @id display', ['@id' => $id])); + $this->assertTrue(array_filter($validate[$id], $match), new FormattableMarkup('Error message found for @id display', ['@id' => $id])); $count++; } diff --git a/core/modules/views/tests/src/Kernel/ViewStorageTest.php b/core/modules/views/tests/src/Kernel/ViewStorageTest.php index b192048d913..f3f4f09616f 100644 --- a/core/modules/views/tests/src/Kernel/ViewStorageTest.php +++ b/core/modules/views/tests/src/Kernel/ViewStorageTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\views\Entity\View; use Drupal\views\Plugin\views\display\Page; @@ -85,7 +86,7 @@ class ViewStorageTest extends ViewsKernelTestBase { // expected properties. $this->assertTrue($view instanceof View, 'Single View instance loaded.'); foreach ($this->configProperties as $property) { - $this->assertTrue($view->get($property) !== NULL, format_string('Property: @property loaded onto View.', ['@property' => $property])); + $this->assertTrue($view->get($property) !== NULL, new FormattableMarkup('Property: @property loaded onto View.', ['@property' => $property])); } // Check the displays have been loaded correctly from config display data. @@ -101,7 +102,7 @@ class ViewStorageTest extends ViewsKernelTestBase { // exists. $original_options = $data['display'][$key]; foreach ($original_options as $orig_key => $value) { - $this->assertIdentical($display[$orig_key], $value, format_string('@key is identical to saved data', ['@key' => $key])); + $this->assertIdentical($display[$orig_key], $value, new FormattableMarkup('@key is identical to saved data', ['@key' => $key])); } } @@ -120,7 +121,7 @@ class ViewStorageTest extends ViewsKernelTestBase { $this->assertTrue($created instanceof View, 'Created object is a View.'); // Check that the View contains all of the properties. foreach ($this->configProperties as $property) { - $this->assertTrue(property_exists($created, $property), format_string('Property: @property created on View.', ['@property' => $property])); + $this->assertTrue(property_exists($created, $property), new FormattableMarkup('Property: @property created on View.', ['@property' => $property])); } // Create a new View instance with config values. @@ -137,8 +138,8 @@ class ViewStorageTest extends ViewsKernelTestBase { // Test all properties except displays. foreach ($properties as $property) { - $this->assertTrue($created->get($property) !== NULL, format_string('Property: @property created on View.', ['@property' => $property])); - $this->assertIdentical($values[$property], $created->get($property), format_string('Property value: @property matches configuration value.', ['@property' => $property])); + $this->assertTrue($created->get($property) !== NULL, new FormattableMarkup('Property: @property created on View.', ['@property' => $property])); + $this->assertIdentical($values[$property], $created->get($property), new FormattableMarkup('Property value: @property matches configuration value.', ['@property' => $property])); } // Check the UUID of the loaded View. @@ -207,14 +208,14 @@ class ViewStorageTest extends ViewsKernelTestBase { $random_title = $this->randomMachineName(); $id = $view->addDisplay('page', $random_title); - $this->assertEqual($id, 'page_1', format_string('Make sure the first display (%id_new) has the expected ID (%id)', ['%id_new' => $id, '%id' => 'page_1'])); + $this->assertEqual($id, 'page_1', new FormattableMarkup('Make sure the first display (%id_new) has the expected ID (%id)', ['%id_new' => $id, '%id' => 'page_1'])); $display = $view->get('display'); $this->assertEqual($display[$id]['display_title'], $random_title); $random_title = $this->randomMachineName(); $id = $view->addDisplay('page', $random_title); $display = $view->get('display'); - $this->assertEqual($id, 'page_2', format_string('Make sure the second display (%id_new) has the expected ID (%id)', ['%id_new' => $id, '%id' => 'page_2'])); + $this->assertEqual($id, 'page_2', new FormattableMarkup('Make sure the second display (%id_new) has the expected ID (%id)', ['%id_new' => $id, '%id' => 'page_2'])); $this->assertEqual($display[$id]['display_title'], $random_title); $id = $view->addDisplay('page'); @@ -337,14 +338,14 @@ class ViewStorageTest extends ViewsKernelTestBase { ]; foreach ($config_properties as $property) { - $this->assertIdentical($view->storage->get($property), $copy->get($property), format_string('@property property is identical.', ['@property' => $property])); + $this->assertIdentical($view->storage->get($property), $copy->get($property), new FormattableMarkup('@property property is identical.', ['@property' => $property])); } // Check the displays are the same. $copy_display = $copy->get('display'); foreach ($view->storage->get('display') as $id => $display) { // assertIdentical will not work here. - $this->assertEqual($display, $copy_display[$id], format_string('The @display display has been copied correctly.', ['@display' => $id])); + $this->assertEqual($display, $copy_display[$id], new FormattableMarkup('The @display display has been copied correctly.', ['@display' => $id])); } } diff --git a/core/modules/views/tests/src/Kernel/ViewsHooksTest.php b/core/modules/views/tests/src/Kernel/ViewsHooksTest.php index 5b1b756d211..7d170050f4b 100644 --- a/core/modules/views/tests/src/Kernel/ViewsHooksTest.php +++ b/core/modules/views/tests/src/Kernel/ViewsHooksTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Render\RenderContext; use Drupal\views\Form\ViewsFormMainForm; use Drupal\views\Views; @@ -66,7 +67,7 @@ class ViewsHooksTest extends ViewsKernelTestBase { // Test each hook is found in the implementations array and is invoked. foreach (static::$hooks as $hook => $type) { - $this->assertTrue($this->moduleHandler->implementsHook('views_test_data', $hook), format_string('The hook @hook was registered.', ['@hook' => $hook])); + $this->assertTrue($this->moduleHandler->implementsHook('views_test_data', $hook), new FormattableMarkup('The hook @hook was registered.', ['@hook' => $hook])); if ($hook == 'views_post_render') { $this->moduleHandler->invoke('views_test_data', $hook, [$view, &$view->display_handler->output, $view->display_handler->getPlugin('cache')]); @@ -87,7 +88,7 @@ class ViewsHooksTest extends ViewsKernelTestBase { $this->moduleHandler->invoke('views_test_data', $hook); } - $this->assertTrue($this->container->get('state')->get('views_hook_test_' . $hook), format_string('The %hook hook was invoked.', ['%hook' => $hook])); + $this->assertTrue($this->container->get('state')->get('views_hook_test_' . $hook), new FormattableMarkup('The %hook hook was invoked.', ['%hook' => $hook])); // Reset the module implementations cache, so we ensure that the // .views.inc file is loaded actively. $this->moduleHandler->resetImplementations(); diff --git a/core/modules/views_ui/tests/src/Functional/AnalyzeTest.php b/core/modules/views_ui/tests/src/Functional/AnalyzeTest.php index 32d1ae98023..2492944235c 100644 --- a/core/modules/views_ui/tests/src/Functional/AnalyzeTest.php +++ b/core/modules/views_ui/tests/src/Functional/AnalyzeTest.php @@ -2,6 +2,8 @@ namespace Drupal\Tests\views_ui\Functional; +use Drupal\Component\Render\FormattableMarkup; + /** * Tests the views analyze system. * @@ -38,7 +40,7 @@ class AnalyzeTest extends UITestBase { foreach (['ok', 'warning', 'error'] as $type) { $xpath = $this->xpath('//div[contains(@class, :class)]', [':class' => $type]); - $this->assertTrue(count($xpath), format_string('Analyse messages with @type found', ['@type' => $type])); + $this->assertTrue(count($xpath), new FormattableMarkup('Analyse messages with @type found', ['@type' => $type])); } // This redirects the user back to the main views edit page. diff --git a/core/modules/views_ui/tests/src/Functional/DefaultViewsTest.php b/core/modules/views_ui/tests/src/Functional/DefaultViewsTest.php index 91ee05be0cb..6fe73093ca6 100644 --- a/core/modules/views_ui/tests/src/Functional/DefaultViewsTest.php +++ b/core/modules/views_ui/tests/src/Functional/DefaultViewsTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views_ui\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Url; use Drupal\user\Entity\Role; use Drupal\user\RoleInterface; @@ -235,7 +236,7 @@ class DefaultViewsTest extends UITestBase { break; } } - $this->assertTrue(isset($index), format_string('Link to "@label" containing @part found.', ['@label' => $label, '@part' => $unique_href_part])); + $this->assertTrue(isset($index), new FormattableMarkup('Link to "@label" containing @part found.', ['@label' => $label, '@part' => $unique_href_part])); if (isset($index)) { return $this->clickLink((string) $label, $index); } diff --git a/core/modules/views_ui/tests/src/Functional/DisplayAttachmentTest.php b/core/modules/views_ui/tests/src/Functional/DisplayAttachmentTest.php index 057a785c2ab..537cedf656e 100644 --- a/core/modules/views_ui/tests/src/Functional/DisplayAttachmentTest.php +++ b/core/modules/views_ui/tests/src/Functional/DisplayAttachmentTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views_ui\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\views\Views; /** @@ -33,7 +34,7 @@ class DisplayAttachmentTest extends UITestBase { $this->assertEscaped('<em>Page</em>'); foreach (['default', 'page-1'] as $display_id) { - $this->assertNoFieldChecked("edit-displays-$display_id", format_string('Make sure the @display_id can be marked as attached', ['@display_id' => $display_id])); + $this->assertNoFieldChecked("edit-displays-$display_id", new FormattableMarkup('Make sure the @display_id can be marked as attached', ['@display_id' => $display_id])); } // Save the attachments and test the value on the view. diff --git a/core/modules/views_ui/tests/src/Functional/StorageTest.php b/core/modules/views_ui/tests/src/Functional/StorageTest.php index df3d030e701..02f4fc77df7 100644 --- a/core/modules/views_ui/tests/src/Functional/StorageTest.php +++ b/core/modules/views_ui/tests/src/Functional/StorageTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views_ui\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\views\Views; @@ -49,7 +50,7 @@ class StorageTest extends UITestBase { $view = Views::getView($view_name); foreach (['label', 'tag', 'description', 'langcode'] as $property) { - $this->assertEqual($view->storage->get($property), $edit[$property], format_string('Make sure the property @property got probably saved.', ['@property' => $property])); + $this->assertEqual($view->storage->get($property), $edit[$property], new FormattableMarkup('Make sure the property @property got probably saved.', ['@property' => $property])); } } diff --git a/core/modules/views_ui/tests/src/Kernel/TagTest.php b/core/modules/views_ui/tests/src/Kernel/TagTest.php index 44d341776d7..b54ce0617e9 100644 --- a/core/modules/views_ui/tests/src/Kernel/TagTest.php +++ b/core/modules/views_ui/tests/src/Kernel/TagTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views_ui\Kernel; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Tests\views\Kernel\ViewsKernelTestBase; use Drupal\views_ui\Controller\ViewsUIController; use Drupal\Component\Utility\Html; @@ -58,7 +59,7 @@ class TagTest extends ViewsKernelTestBase { $matches = (array) json_decode($result->getContent(), TRUE); $this->assertEqual(count($matches), 8, 'Make sure that only a subset is returned.'); foreach ($matches as $tag) { - $this->assertTrue(array_search($tag['value'], $tags) !== FALSE, format_string('Make sure the returned tag @tag actually exists.', ['@tag' => $tag['value']])); + $this->assertTrue(array_search($tag['value'], $tags) !== FALSE, new FormattableMarkup('Make sure the returned tag @tag actually exists.', ['@tag' => $tag['value']])); } // Make sure an invalid result doesn't return anything. diff --git a/core/tests/Drupal/FunctionalTests/MailCaptureTest.php b/core/tests/Drupal/FunctionalTests/MailCaptureTest.php index fdcc664f6f7..0f48d79e0e0 100644 --- a/core/tests/Drupal/FunctionalTests/MailCaptureTest.php +++ b/core/tests/Drupal/FunctionalTests/MailCaptureTest.php @@ -2,6 +2,7 @@ namespace Drupal\FunctionalTests; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Tests\BrowserTestBase; use Drupal\Core\Test\AssertMailTrait; @@ -45,7 +46,7 @@ class MailCaptureTest extends BrowserTestBase { // Assert that the email was sent by iterating over the message properties // and ensuring that they are captured intact. foreach ($message as $field => $value) { - $this->assertMail($field, $value, format_string('The email was sent and the value for property @field is intact.', ['@field' => $field]), 'Email'); + $this->assertMail($field, $value, new FormattableMarkup('The email was sent and the value for property @field is intact.', ['@field' => $field]), 'Email'); } // Send additional emails so more than one email is captured. diff --git a/core/tests/Drupal/KernelTests/AssertContentTrait.php b/core/tests/Drupal/KernelTests/AssertContentTrait.php index e075ffe857f..c2bd32571c9 100644 --- a/core/tests/Drupal/KernelTests/AssertContentTrait.php +++ b/core/tests/Drupal/KernelTests/AssertContentTrait.php @@ -885,7 +885,7 @@ trait AssertContentTrait { if (!$message) { $message = '%callback rendered correctly.'; } - $message = format_string($message, ['%callback' => 'theme_' . $callback . '()']); + $message = new FormattableMarkup($message, ['%callback' => 'theme_' . $callback . '()']); return $this->assertIdentical($output, $expected, $message, $group); } diff --git a/core/tests/Drupal/KernelTests/ConfigFormTestBase.php b/core/tests/Drupal/KernelTests/ConfigFormTestBase.php index 6436247357a..e873bad322e 100644 --- a/core/tests/Drupal/KernelTests/ConfigFormTestBase.php +++ b/core/tests/Drupal/KernelTests/ConfigFormTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\KernelTests; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Form\FormState; /** @@ -56,7 +57,7 @@ abstract class ConfigFormTestBase extends KernelTestBase { '%values' => print_r($values, TRUE), '%errors' => $valid_form ? t('None') : implode(' ', $errors), ]; - $this->assertTrue($valid_form, format_string('Input values: %values<br/>Validation handler errors: %errors', $args)); + $this->assertTrue($valid_form, new FormattableMarkup('Input values: %values<br/>Validation handler errors: %errors', $args)); foreach ($this->values as $data) { $this->assertEqual($data['#value'], $this->config($data['#config_name'])->get($data['#config_key'])); diff --git a/core/tests/Drupal/KernelTests/Core/Bootstrap/FormatStringTest.php b/core/tests/Drupal/KernelTests/Core/Bootstrap/FormatStringTest.php new file mode 100644 index 00000000000..afb865e9786 --- /dev/null +++ b/core/tests/Drupal/KernelTests/Core/Bootstrap/FormatStringTest.php @@ -0,0 +1,26 @@ +<?php + +namespace Drupal\KernelTests\Core\Bootstrap; + +use Drupal\Component\Render\FormattableMarkup; +use Drupal\KernelTests\KernelTestBase; + +/** + * Tests deprecated behavior of format_string. + * + * @group Bootstrap + * @group legacy + */ +class FormatStringTest extends KernelTestBase { + + /** + * Tests error triggering on format_string. + * + * @expectedDeprecation format_string() is deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal\Component\Render\FormattableMarkup instead. See https://www.drupal.org/node/2302363 + */ + public function testFormatString() { + $markup = \format_string("Test", []); + $this->assertInstanceOf(FormattableMarkup::class, $markup); + } + +} diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigCRUDTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigCRUDTest.php index 1237e724877..52269c0dfe5 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/ConfigCRUDTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigCRUDTest.php @@ -225,7 +225,7 @@ class ConfigCRUDTest extends KernelTestBase { unset($test_characters[$i]); } } - $this->assertTrue(empty($test_characters), format_string('Expected ConfigNameException was thrown for all invalid name characters: @characters', [ + $this->assertTrue(empty($test_characters), new FormattableMarkup('Expected ConfigNameException was thrown for all invalid name characters: @characters', [ '@characters' => implode(' ', $characters), ])); diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStorageTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStorageTest.php index a8a377db746..cf5ba3154a0 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStorageTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityStorageTest.php @@ -2,6 +2,7 @@ namespace Drupal\KernelTests\Core\Config; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Config\ConfigDuplicateUUIDException; use Drupal\KernelTests\KernelTestBase; @@ -43,7 +44,7 @@ class ConfigEntityStorageTest extends KernelTestBase { $this->fail('Exception thrown when attempting to save a configuration entity with a UUID that does not match the existing UUID.'); } catch (ConfigDuplicateUUIDException $e) { - $this->pass(format_string('Exception thrown when attempting to save a configuration entity with a UUID that does not match existing data: %e.', ['%e' => $e])); + $this->pass(new FormattableMarkup('Exception thrown when attempting to save a configuration entity with a UUID that does not match existing data: %e.', ['%e' => $e])); } // Ensure that the config entity was not corrupted. diff --git a/core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php b/core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php index c17e4b3aab0..c9ab16a551a 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php @@ -2,6 +2,7 @@ namespace Drupal\KernelTests\Core\Database; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Database\Database; use Drupal\Core\Database\DatabaseExceptionWrapper; @@ -168,9 +169,9 @@ class ConnectionTest extends DatabaseTestBase { $stmt->execute(); foreach ($stmt->fetchAllAssoc('word') as $word => $row) { $expected = '"' . $word . '"'; - $this->assertIdentical($db->escapeTable($word), $expected, format_string('The reserved word %word was correctly escaped when used as a table name.', ['%word' => $word])); - $this->assertIdentical($db->escapeField($word), $expected, format_string('The reserved word %word was correctly escaped when used as a column name.', ['%word' => $word])); - $this->assertIdentical($db->escapeAlias($word), $expected, format_string('The reserved word %word was correctly escaped when used as an alias.', ['%word' => $word])); + $this->assertIdentical($db->escapeTable($word), $expected, new FormattableMarkup('The reserved word %word was correctly escaped when used as a table name.', ['%word' => $word])); + $this->assertIdentical($db->escapeField($word), $expected, new FormattableMarkup('The reserved word %word was correctly escaped when used as a column name.', ['%word' => $word])); + $this->assertIdentical($db->escapeAlias($word), $expected, new FormattableMarkup('The reserved word %word was correctly escaped when used as an alias.', ['%word' => $word])); } } diff --git a/core/tests/Drupal/KernelTests/Core/Database/ConnectionUnitTest.php b/core/tests/Drupal/KernelTests/Core/Database/ConnectionUnitTest.php index a7424d2534c..9002ef46f7c 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/ConnectionUnitTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/ConnectionUnitTest.php @@ -2,6 +2,7 @@ namespace Drupal\KernelTests\Core\Database; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Database\Database; use Drupal\KernelTests\KernelTestBase; @@ -75,7 +76,7 @@ class ConnectionUnitTest extends KernelTestBase { */ protected function assertConnection($id) { $list = $this->monitor->query('SHOW PROCESSLIST')->fetchAllKeyed(0, 0); - return $this->assertTrue(isset($list[$id]), format_string('Connection ID @id found.', ['@id' => $id])); + return $this->assertTrue(isset($list[$id]), new FormattableMarkup('Connection ID @id found.', ['@id' => $id])); } /** @@ -86,7 +87,7 @@ class ConnectionUnitTest extends KernelTestBase { */ protected function assertNoConnection($id) { $list = $this->monitor->query('SHOW PROCESSLIST')->fetchAllKeyed(0, 0); - return $this->assertFalse(isset($list[$id]), format_string('Connection ID @id not found.', ['@id' => $id])); + return $this->assertFalse(isset($list[$id]), new FormattableMarkup('Connection ID @id not found.', ['@id' => $id])); } /** diff --git a/core/tests/Drupal/KernelTests/Core/Database/InsertLobTest.php b/core/tests/Drupal/KernelTests/Core/Database/InsertLobTest.php index b71e5e52815..4554268cf32 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/InsertLobTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/InsertLobTest.php @@ -2,6 +2,8 @@ namespace Drupal\KernelTests\Core\Database; +use Drupal\Component\Render\FormattableMarkup; + /** * Tests the Insert query builder with LOB fields. * @@ -19,7 +21,7 @@ class InsertLobTest extends DatabaseTestBase { ->fields(['blob1' => $data]) ->execute(); $r = $this->connection->query('SELECT * FROM {test_one_blob} WHERE id = :id', [':id' => $id])->fetchAssoc(); - $this->assertTrue($r['blob1'] === $data, format_string('Can insert a blob: id @id, @data.', ['@id' => $id, '@data' => serialize($r)])); + $this->assertTrue($r['blob1'] === $data, new FormattableMarkup('Can insert a blob: id @id, @data.', ['@id' => $id, '@data' => serialize($r)])); } /** diff --git a/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php index a900e2d4723..2a86e3470f3 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php @@ -2,6 +2,7 @@ namespace Drupal\KernelTests\Core\Database; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Database\Database; use Drupal\Core\Database\SchemaException; use Drupal\Core\Database\SchemaObjectDoesNotExistException; @@ -554,8 +555,8 @@ class SchemaTest extends KernelTestBase { // Finally, check each column and try to insert invalid values into them. foreach ($table_spec['fields'] as $column_name => $column_spec) { - $this->assertTrue($this->schema->fieldExists($table_name, $column_name), format_string('Unsigned @type column was created.', ['@type' => $column_spec['type']])); - $this->assertFalse($this->tryUnsignedInsert($table_name, $column_name), format_string('Unsigned @type column rejected a negative value.', ['@type' => $column_spec['type']])); + $this->assertTrue($this->schema->fieldExists($table_name, $column_name), new FormattableMarkup('Unsigned @type column was created.', ['@type' => $column_spec['type']])); + $this->assertFalse($this->tryUnsignedInsert($table_name, $column_name), new FormattableMarkup('Unsigned @type column rejected a negative value.', ['@type' => $column_spec['type']])); } } @@ -686,7 +687,7 @@ class SchemaTest extends KernelTestBase { 'primary key' => ['serial_column'], ]; $this->schema->createTable($table_name, $table_spec); - $this->pass(format_string('Table %table created.', ['%table' => $table_name])); + $this->pass(new FormattableMarkup('Table %table created.', ['%table' => $table_name])); // Check the characteristics of the field. $this->assertFieldCharacteristics($table_name, 'test_field', $field_spec); @@ -704,7 +705,7 @@ class SchemaTest extends KernelTestBase { 'primary key' => ['serial_column'], ]; $this->schema->createTable($table_name, $table_spec); - $this->pass(format_string('Table %table created.', ['%table' => $table_name])); + $this->pass(new FormattableMarkup('Table %table created.', ['%table' => $table_name])); // Insert some rows to the table to test the handling of initial values. for ($i = 0; $i < 3; $i++) { @@ -722,7 +723,7 @@ class SchemaTest extends KernelTestBase { ->execute(); $this->schema->addField($table_name, 'test_field', $field_spec); - $this->pass(format_string('Column %column created.', ['%column' => 'test_field'])); + $this->pass(new FormattableMarkup('Column %column created.', ['%column' => 'test_field'])); // Check the characteristics of the field. $this->assertFieldCharacteristics($table_name, 'test_field', $field_spec); @@ -1024,7 +1025,7 @@ class SchemaTest extends KernelTestBase { 'primary key' => ['serial_column'], ]; $this->schema->createTable($table_name, $table_spec); - $this->pass(format_string('Table %table created.', ['%table' => $table_name])); + $this->pass(new FormattableMarkup('Table %table created.', ['%table' => $table_name])); // Check the characteristics of the field. $this->assertFieldCharacteristics($table_name, 'test_field', $old_spec); diff --git a/core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php b/core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php index 4844cef645d..c4a2f349cf3 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php @@ -2,6 +2,7 @@ namespace Drupal\KernelTests\Core\Database; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Database\Database; use Drupal\Core\Database\Query\Condition; use Drupal\Core\Database\RowCountException; @@ -100,7 +101,7 @@ class SelectComplexTest extends DatabaseTestBase { ]; foreach ($correct_results as $task => $count) { - $this->assertEqual($records[$task], $count, format_string("Correct number of '@task' records found.", ['@task' => $task])); + $this->assertEqual($records[$task], $count, new FormattableMarkup("Correct number of '@task' records found.", ['@task' => $task])); } $this->assertEqual($num_records, 6, 'Returned the correct number of total rows.'); @@ -134,7 +135,7 @@ class SelectComplexTest extends DatabaseTestBase { ]; foreach ($correct_results as $task => $count) { - $this->assertEqual($records[$task], $count, format_string("Correct number of '@task' records found.", ['@task' => $task])); + $this->assertEqual($records[$task], $count, new FormattableMarkup("Correct number of '@task' records found.", ['@task' => $task])); } $this->assertEqual($num_records, 1, 'Returned the correct number of total rows.'); diff --git a/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php b/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php index f3607547cf8..fae1f69bf8c 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php @@ -2,6 +2,7 @@ namespace Drupal\KernelTests\Core\Database; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Database\TransactionOutOfOrderException; use Drupal\Core\Database\TransactionNoActiveException; @@ -352,7 +353,7 @@ class TransactionTest extends DatabaseTestBase { */ public function assertRowPresent($name, $message = NULL) { if (!isset($message)) { - $message = format_string('Row %name is present.', ['%name' => $name]); + $message = new FormattableMarkup('Row %name is present.', ['%name' => $name]); } $present = (boolean) $this->connection->query('SELECT 1 FROM {test} WHERE name = :name', [':name' => $name])->fetchField(); return $this->assertTrue($present, $message); @@ -368,7 +369,7 @@ class TransactionTest extends DatabaseTestBase { */ public function assertRowAbsent($name, $message = NULL) { if (!isset($message)) { - $message = format_string('Row %name is absent.', ['%name' => $name]); + $message = new FormattableMarkup('Row %name is absent.', ['%name' => $name]); } $present = (boolean) $this->connection->query('SELECT 1 FROM {test} WHERE name = :name', [':name' => $name])->fetchField(); return $this->assertFalse($present, $message); diff --git a/core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php b/core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php index 45322cdc1b8..326c3a666ff 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php @@ -2,6 +2,8 @@ namespace Drupal\KernelTests\Core\Database; +use Drupal\Component\Render\FormattableMarkup; + /** * Tests the Update query builder with LOB fields. * @@ -26,7 +28,7 @@ class UpdateLobTest extends DatabaseTestBase { ->execute(); $r = $this->connection->query('SELECT * FROM {test_one_blob} WHERE id = :id', [':id' => $id])->fetchAssoc(); - $this->assertTrue($r['blob1'] === $data, format_string('Can update a blob: id @id, @data.', ['@id' => $id, '@data' => serialize($r)])); + $this->assertTrue($r['blob1'] === $data, new FormattableMarkup('Can update a blob: id @id, @data.', ['@id' => $id, '@data' => serialize($r)])); } /** diff --git a/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityCloneTest.php b/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityCloneTest.php index 8f08b272de3..4bbe2453ac8 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityCloneTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityCloneTest.php @@ -62,12 +62,12 @@ class ContentEntityCloneTest extends EntityKernelTestBase { foreach ($translation->getFields() as $field_name => $field) { if ($field->getFieldDefinition()->isTranslatable()) { $args = ['%field_name' => $field_name, '%langcode' => $langcode]; - $this->assertEqual($langcode, $field->getEntity()->language()->getId(), format_string('Translatable field %field_name on translation %langcode has correct entity reference in translation %langcode after cloning.', $args)); + $this->assertEqual($langcode, $field->getEntity()->language()->getId(), new FormattableMarkup('Translatable field %field_name on translation %langcode has correct entity reference in translation %langcode after cloning.', $args)); $this->assertSame($translation, $field->getEntity(), new FormattableMarkup('Translatable field %field_name on translation %langcode has correct reference to the cloned entity object.', $args)); } else { $args = ['%field_name' => $field_name, '%langcode' => $langcode, '%default_langcode' => $default_langcode]; - $this->assertEqual($default_langcode, $field->getEntity()->language()->getId(), format_string('Non translatable field %field_name on translation %langcode has correct entity reference in the default translation %default_langcode after cloning.', $args)); + $this->assertEqual($default_langcode, $field->getEntity()->language()->getId(), new FormattableMarkup('Non translatable field %field_name on translation %langcode has correct entity reference in the default translation %default_langcode after cloning.', $args)); $this->assertSame($translation->getUntranslated(), $field->getEntity(), new FormattableMarkup('Non translatable field %field_name on translation %langcode has correct reference to the cloned entity object in the default translation %default_langcode.', $args)); } } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php index 2ce4ef53895..d83706aaafe 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityAccessControlHandlerTest.php @@ -2,6 +2,7 @@ namespace Drupal\KernelTests\Core\Entity; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Access\AccessibleInterface; @@ -40,7 +41,7 @@ class EntityAccessControlHandlerTest extends EntityLanguageTestBase { */ public function assertEntityAccess($ops, AccessibleInterface $object, AccountInterface $account = NULL) { foreach ($ops as $op => $result) { - $message = format_string("Entity access returns @result with operation '@op'.", [ + $message = new FormattableMarkup("Entity access returns @result with operation '@op'.", [ '@result' => !isset($result) ? 'null' : ($result ? 'true' : 'false'), '@op' => $op, ]); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityApiTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityApiTest.php index ed47d096c3b..b46661374a8 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityApiTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityApiTest.php @@ -2,6 +2,7 @@ namespace Drupal\KernelTests\Core\Entity; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Database\Database; use Drupal\Core\Entity\EntityStorageException; use Drupal\entity_test\Entity\EntityTest; @@ -66,32 +67,32 @@ class EntityApiTest extends EntityKernelTestBase { ->getStorage($entity_type); $entities = array_values($storage->loadByProperties(['name' => 'test'])); - $this->assertEqual($entities[0]->name->value, 'test', format_string('%entity_type: Created and loaded entity', ['%entity_type' => $entity_type])); - $this->assertEqual($entities[1]->name->value, 'test', format_string('%entity_type: Created and loaded entity', ['%entity_type' => $entity_type])); + $this->assertEqual($entities[0]->name->value, 'test', new FormattableMarkup('%entity_type: Created and loaded entity', ['%entity_type' => $entity_type])); + $this->assertEqual($entities[1]->name->value, 'test', new FormattableMarkup('%entity_type: Created and loaded entity', ['%entity_type' => $entity_type])); // Test loading a single entity. $loaded_entity = $storage->load($entity->id()); - $this->assertEqual($loaded_entity->id(), $entity->id(), format_string('%entity_type: Loaded a single entity by id.', ['%entity_type' => $entity_type])); + $this->assertEqual($loaded_entity->id(), $entity->id(), new FormattableMarkup('%entity_type: Loaded a single entity by id.', ['%entity_type' => $entity_type])); // Test deleting an entity. $entities = array_values($storage->loadByProperties(['name' => 'test2'])); $entities[0]->delete(); $entities = array_values($storage->loadByProperties(['name' => 'test2'])); - $this->assertEqual($entities, [], format_string('%entity_type: Entity deleted.', ['%entity_type' => $entity_type])); + $this->assertEqual($entities, [], new FormattableMarkup('%entity_type: Entity deleted.', ['%entity_type' => $entity_type])); // Test updating an entity. $entities = array_values($storage->loadByProperties(['name' => 'test'])); $entities[0]->name->value = 'test3'; $entities[0]->save(); $entity = $storage->load($entities[0]->id()); - $this->assertEqual($entity->name->value, 'test3', format_string('%entity_type: Entity updated.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->name->value, 'test3', new FormattableMarkup('%entity_type: Entity updated.', ['%entity_type' => $entity_type])); // Try deleting multiple test entities by deleting all. $entities = $storage->loadMultiple(); $storage->delete($entities); $all = $storage->loadMultiple(); - $this->assertTrue(empty($all), format_string('%entity_type: Deleted all entities.', ['%entity_type' => $entity_type])); + $this->assertTrue(empty($all), new FormattableMarkup('%entity_type: Deleted all entities.', ['%entity_type' => $entity_type])); // Verify that all data got deleted. $definition = \Drupal::entityTypeManager()->getDefinition($entity_type); @@ -120,7 +121,7 @@ class EntityApiTest extends EntityKernelTestBase { // Verify that entities got deleted. $all = $storage->loadMultiple(); - $this->assertTrue(empty($all), format_string('%entity_type: Deleted all entities.', ['%entity_type' => $entity_type])); + $this->assertTrue(empty($all), new FormattableMarkup('%entity_type: Deleted all entities.', ['%entity_type' => $entity_type])); // Verify that all data got deleted from the tables. $definition = \Drupal::entityTypeManager()->getDefinition($entity_type); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php index 0c36fbbe011..fbbd3a68d56 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php @@ -2,6 +2,7 @@ namespace Drupal\KernelTests\Core\Entity; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Entity\RevisionLogInterface; @@ -115,66 +116,66 @@ class EntityFieldTest extends EntityKernelTestBase { $langcode = 'en'; // Access the name field. - $this->assertTrue($entity->name instanceof FieldItemListInterface, format_string('%entity_type: Field implements interface', ['%entity_type' => $entity_type])); - $this->assertTrue($entity->name[0] instanceof FieldItemInterface, format_string('%entity_type: Field item implements interface', ['%entity_type' => $entity_type])); + $this->assertTrue($entity->name instanceof FieldItemListInterface, new FormattableMarkup('%entity_type: Field implements interface', ['%entity_type' => $entity_type])); + $this->assertTrue($entity->name[0] instanceof FieldItemInterface, new FormattableMarkup('%entity_type: Field item implements interface', ['%entity_type' => $entity_type])); - $this->assertEqual($this->entityName, $entity->name->value, format_string('%entity_type: Name value can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($this->entityName, $entity->name[0]->value, format_string('%entity_type: Name value can be read through list access.', ['%entity_type' => $entity_type])); - $this->assertEqual($entity->name->getValue(), [0 => ['value' => $this->entityName]], format_string('%entity_type: Plain field value returned.', ['%entity_type' => $entity_type])); + $this->assertEqual($this->entityName, $entity->name->value, new FormattableMarkup('%entity_type: Name value can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($this->entityName, $entity->name[0]->value, new FormattableMarkup('%entity_type: Name value can be read through list access.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->name->getValue(), [0 => ['value' => $this->entityName]], new FormattableMarkup('%entity_type: Plain field value returned.', ['%entity_type' => $entity_type])); // Change the name. $new_name = $this->randomMachineName(); $entity->name->value = $new_name; - $this->assertEqual($new_name, $entity->name->value, format_string('%entity_type: Name can be updated and read.', ['%entity_type' => $entity_type])); - $this->assertEqual($entity->name->getValue(), [0 => ['value' => $new_name]], format_string('%entity_type: Plain field value reflects the update.', ['%entity_type' => $entity_type])); + $this->assertEqual($new_name, $entity->name->value, new FormattableMarkup('%entity_type: Name can be updated and read.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->name->getValue(), [0 => ['value' => $new_name]], new FormattableMarkup('%entity_type: Plain field value reflects the update.', ['%entity_type' => $entity_type])); $new_name = $this->randomMachineName(); $entity->name[0]->value = $new_name; - $this->assertEqual($new_name, $entity->name->value, format_string('%entity_type: Name can be updated and read through list access.', ['%entity_type' => $entity_type])); + $this->assertEqual($new_name, $entity->name->value, new FormattableMarkup('%entity_type: Name can be updated and read through list access.', ['%entity_type' => $entity_type])); // Access the user field. - $this->assertTrue($entity->user_id instanceof FieldItemListInterface, format_string('%entity_type: Field implements interface', ['%entity_type' => $entity_type])); - $this->assertTrue($entity->user_id[0] instanceof FieldItemInterface, format_string('%entity_type: Field item implements interface', ['%entity_type' => $entity_type])); + $this->assertTrue($entity->user_id instanceof FieldItemListInterface, new FormattableMarkup('%entity_type: Field implements interface', ['%entity_type' => $entity_type])); + $this->assertTrue($entity->user_id[0] instanceof FieldItemInterface, new FormattableMarkup('%entity_type: Field item implements interface', ['%entity_type' => $entity_type])); - $this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($this->entityUser->getAccountName(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, new FormattableMarkup('%entity_type: User id can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($this->entityUser->getAccountName(), $entity->user_id->entity->name->value, new FormattableMarkup('%entity_type: User name can be read.', ['%entity_type' => $entity_type])); // Change the assigned user by entity. $new_user1 = $this->createUser(); $entity->user_id->entity = $new_user1; - $this->assertEqual($new_user1->id(), $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($new_user1->getAccountName(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated username value can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($new_user1->id(), $entity->user_id->target_id, new FormattableMarkup('%entity_type: Updated user id can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($new_user1->getAccountName(), $entity->user_id->entity->name->value, new FormattableMarkup('%entity_type: Updated username value can be read.', ['%entity_type' => $entity_type])); // Change the assigned user by id. $new_user2 = $this->createUser(); $entity->user_id->target_id = $new_user2->id(); - $this->assertEqual($new_user2->id(), $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($new_user2->getAccountName(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated username value can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($new_user2->id(), $entity->user_id->target_id, new FormattableMarkup('%entity_type: Updated user id can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($new_user2->getAccountName(), $entity->user_id->entity->name->value, new FormattableMarkup('%entity_type: Updated username value can be read.', ['%entity_type' => $entity_type])); // Try unsetting a field property. $entity->name->value = NULL; $entity->user_id->target_id = NULL; - $this->assertNull($entity->name->value, format_string('%entity_type: Name field is not set.', ['%entity_type' => $entity_type])); - $this->assertNull($entity->user_id->target_id, format_string('%entity_type: User ID field is not set.', ['%entity_type' => $entity_type])); - $this->assertNull($entity->user_id->entity, format_string('%entity_type: User entity field is not set.', ['%entity_type' => $entity_type])); + $this->assertNull($entity->name->value, new FormattableMarkup('%entity_type: Name field is not set.', ['%entity_type' => $entity_type])); + $this->assertNull($entity->user_id->target_id, new FormattableMarkup('%entity_type: User ID field is not set.', ['%entity_type' => $entity_type])); + $this->assertNull($entity->user_id->entity, new FormattableMarkup('%entity_type: User entity field is not set.', ['%entity_type' => $entity_type])); // Test setting the values via the typed data API works as well. // Change the assigned user by entity. $entity->user_id->first()->get('entity')->setValue($new_user2); - $this->assertEqual($new_user2->id(), $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($new_user2->getAccountName(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated user name value can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($new_user2->id(), $entity->user_id->target_id, new FormattableMarkup('%entity_type: Updated user id can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($new_user2->getAccountName(), $entity->user_id->entity->name->value, new FormattableMarkup('%entity_type: Updated user name value can be read.', ['%entity_type' => $entity_type])); // Change the assigned user by id. $entity->user_id->first()->get('target_id')->setValue($new_user2->id()); - $this->assertEqual($new_user2->id(), $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($new_user2->getAccountName(), $entity->user_id->entity->name->value, format_string('%entity_type: Updated user name value can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($new_user2->id(), $entity->user_id->target_id, new FormattableMarkup('%entity_type: Updated user id can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($new_user2->getAccountName(), $entity->user_id->entity->name->value, new FormattableMarkup('%entity_type: Updated user name value can be read.', ['%entity_type' => $entity_type])); // Try unsetting a field. $entity->name->first()->get('value')->setValue(NULL); $entity->user_id->first()->get('target_id')->setValue(NULL); - $this->assertNull($entity->name->value, format_string('%entity_type: Name field is not set.', ['%entity_type' => $entity_type])); - $this->assertNull($entity->user_id->target_id, format_string('%entity_type: User ID field is not set.', ['%entity_type' => $entity_type])); - $this->assertNull($entity->user_id->entity, format_string('%entity_type: User entity field is not set.', ['%entity_type' => $entity_type])); + $this->assertNull($entity->name->value, new FormattableMarkup('%entity_type: Name field is not set.', ['%entity_type' => $entity_type])); + $this->assertNull($entity->user_id->target_id, new FormattableMarkup('%entity_type: User ID field is not set.', ['%entity_type' => $entity_type])); + $this->assertNull($entity->user_id->entity, new FormattableMarkup('%entity_type: User entity field is not set.', ['%entity_type' => $entity_type])); // Create a fresh entity so target_id does not get its property object // instantiated, then verify setting a new value via typed data API works. @@ -185,38 +186,38 @@ class EntityFieldTest extends EntityKernelTestBase { ]); // Access the property object, and set a value. $entity2->user_id->first()->get('target_id')->setValue($new_user2->id()); - $this->assertEqual($new_user2->id(), $entity2->user_id->target_id, format_string('%entity_type: Updated user id can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($new_user2->name->value, $entity2->user_id->entity->name->value, format_string('%entity_type: Updated user name value can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($new_user2->id(), $entity2->user_id->target_id, new FormattableMarkup('%entity_type: Updated user id can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($new_user2->name->value, $entity2->user_id->entity->name->value, new FormattableMarkup('%entity_type: Updated user name value can be read.', ['%entity_type' => $entity_type])); // Test using isset(), empty() and unset(). $entity->name->value = 'test unset'; unset($entity->name->value); - $this->assertFalse(isset($entity->name->value), format_string('%entity_type: Name is not set.', ['%entity_type' => $entity_type])); - $this->assertFalse(isset($entity->name[0]->value), format_string('%entity_type: Name is not set.', ['%entity_type' => $entity_type])); - $this->assertTrue(empty($entity->name->value), format_string('%entity_type: Name is empty.', ['%entity_type' => $entity_type])); - $this->assertTrue(empty($entity->name[0]->value), format_string('%entity_type: Name is empty.', ['%entity_type' => $entity_type])); + $this->assertFalse(isset($entity->name->value), new FormattableMarkup('%entity_type: Name is not set.', ['%entity_type' => $entity_type])); + $this->assertFalse(isset($entity->name[0]->value), new FormattableMarkup('%entity_type: Name is not set.', ['%entity_type' => $entity_type])); + $this->assertTrue(empty($entity->name->value), new FormattableMarkup('%entity_type: Name is empty.', ['%entity_type' => $entity_type])); + $this->assertTrue(empty($entity->name[0]->value), new FormattableMarkup('%entity_type: Name is empty.', ['%entity_type' => $entity_type])); $entity->name->value = 'a value'; - $this->assertTrue(isset($entity->name->value), format_string('%entity_type: Name is set.', ['%entity_type' => $entity_type])); - $this->assertTrue(isset($entity->name[0]->value), format_string('%entity_type: Name is set.', ['%entity_type' => $entity_type])); - $this->assertFalse(empty($entity->name->value), format_string('%entity_type: Name is not empty.', ['%entity_type' => $entity_type])); - $this->assertFalse(empty($entity->name[0]->value), format_string('%entity_type: Name is not empty.', ['%entity_type' => $entity_type])); - $this->assertTrue(isset($entity->name[0]), format_string('%entity_type: Name string item is set.', ['%entity_type' => $entity_type])); - $this->assertFalse(isset($entity->name[1]), format_string('%entity_type: Second name string item is not set as it does not exist', ['%entity_type' => $entity_type])); - $this->assertTrue(isset($entity->name), format_string('%entity_type: Name field is set.', ['%entity_type' => $entity_type])); - $this->assertFalse(isset($entity->nameInvalid), format_string('%entity_type: Not existing field is not set.', ['%entity_type' => $entity_type])); + $this->assertTrue(isset($entity->name->value), new FormattableMarkup('%entity_type: Name is set.', ['%entity_type' => $entity_type])); + $this->assertTrue(isset($entity->name[0]->value), new FormattableMarkup('%entity_type: Name is set.', ['%entity_type' => $entity_type])); + $this->assertFalse(empty($entity->name->value), new FormattableMarkup('%entity_type: Name is not empty.', ['%entity_type' => $entity_type])); + $this->assertFalse(empty($entity->name[0]->value), new FormattableMarkup('%entity_type: Name is not empty.', ['%entity_type' => $entity_type])); + $this->assertTrue(isset($entity->name[0]), new FormattableMarkup('%entity_type: Name string item is set.', ['%entity_type' => $entity_type])); + $this->assertFalse(isset($entity->name[1]), new FormattableMarkup('%entity_type: Second name string item is not set as it does not exist', ['%entity_type' => $entity_type])); + $this->assertTrue(isset($entity->name), new FormattableMarkup('%entity_type: Name field is set.', ['%entity_type' => $entity_type])); + $this->assertFalse(isset($entity->nameInvalid), new FormattableMarkup('%entity_type: Not existing field is not set.', ['%entity_type' => $entity_type])); unset($entity->name[0]); - $this->assertFalse(isset($entity->name[0]), format_string('%entity_type: Name field item is not set.', ['%entity_type' => $entity_type])); - $this->assertFalse(isset($entity->name[0]->value), format_string('%entity_type: Name is not set.', ['%entity_type' => $entity_type])); - $this->assertFalse(isset($entity->name->value), format_string('%entity_type: Name is not set.', ['%entity_type' => $entity_type])); + $this->assertFalse(isset($entity->name[0]), new FormattableMarkup('%entity_type: Name field item is not set.', ['%entity_type' => $entity_type])); + $this->assertFalse(isset($entity->name[0]->value), new FormattableMarkup('%entity_type: Name is not set.', ['%entity_type' => $entity_type])); + $this->assertFalse(isset($entity->name->value), new FormattableMarkup('%entity_type: Name is not set.', ['%entity_type' => $entity_type])); // Test emptying a field by assigning an empty value. NULL and array() // behave the same. foreach ([NULL, [], 'unset'] as $empty) { // Make sure a value is present $entity->name->value = 'a value'; - $this->assertTrue(isset($entity->name->value), format_string('%entity_type: Name is set.', ['%entity_type' => $entity_type])); + $this->assertTrue(isset($entity->name->value), new FormattableMarkup('%entity_type: Name is set.', ['%entity_type' => $entity_type])); // Now, empty the field. if ($empty === 'unset') { unset($entity->name); @@ -224,36 +225,36 @@ class EntityFieldTest extends EntityKernelTestBase { else { $entity->name = $empty; } - $this->assertTrue(isset($entity->name), format_string('%entity_type: Name field is set.', ['%entity_type' => $entity_type])); - $this->assertTrue($entity->name->isEmpty(), format_string('%entity_type: Name field is set.', ['%entity_type' => $entity_type])); - $this->assertIdentical(count($entity->name), 0, format_string('%entity_type: Name field contains no items.', ['%entity_type' => $entity_type])); - $this->assertIdentical($entity->name->getValue(), [], format_string('%entity_type: Name field value is an empty array.', ['%entity_type' => $entity_type])); - $this->assertFalse(isset($entity->name[0]), format_string('%entity_type: Name field item is not set.', ['%entity_type' => $entity_type])); - $this->assertFalse(isset($entity->name[0]->value), format_string('%entity_type: First name item value is not set.', ['%entity_type' => $entity_type])); - $this->assertFalse(isset($entity->name->value), format_string('%entity_type: Name value is not set.', ['%entity_type' => $entity_type])); + $this->assertTrue(isset($entity->name), new FormattableMarkup('%entity_type: Name field is set.', ['%entity_type' => $entity_type])); + $this->assertTrue($entity->name->isEmpty(), new FormattableMarkup('%entity_type: Name field is set.', ['%entity_type' => $entity_type])); + $this->assertIdentical(count($entity->name), 0, new FormattableMarkup('%entity_type: Name field contains no items.', ['%entity_type' => $entity_type])); + $this->assertIdentical($entity->name->getValue(), [], new FormattableMarkup('%entity_type: Name field value is an empty array.', ['%entity_type' => $entity_type])); + $this->assertFalse(isset($entity->name[0]), new FormattableMarkup('%entity_type: Name field item is not set.', ['%entity_type' => $entity_type])); + $this->assertFalse(isset($entity->name[0]->value), new FormattableMarkup('%entity_type: First name item value is not set.', ['%entity_type' => $entity_type])); + $this->assertFalse(isset($entity->name->value), new FormattableMarkup('%entity_type: Name value is not set.', ['%entity_type' => $entity_type])); } // Access the language field. $langcode_key = $this->entityTypeManager->getDefinition($entity_type)->getKey('langcode'); - $this->assertEqual($langcode, $entity->{$langcode_key}->value, format_string('%entity_type: Language code can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual(\Drupal::languageManager()->getLanguage($langcode), $entity->{$langcode_key}->language, format_string('%entity_type: Language object can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($langcode, $entity->{$langcode_key}->value, new FormattableMarkup('%entity_type: Language code can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual(\Drupal::languageManager()->getLanguage($langcode), $entity->{$langcode_key}->language, new FormattableMarkup('%entity_type: Language object can be read.', ['%entity_type' => $entity_type])); // Change the language by code. $entity->{$langcode_key}->value = \Drupal::languageManager()->getDefaultLanguage()->getId(); - $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), $entity->{$langcode_key}->value, format_string('%entity_type: Language code can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage(), $entity->{$langcode_key}->language, format_string('%entity_type: Language object can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), $entity->{$langcode_key}->value, new FormattableMarkup('%entity_type: Language code can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage(), $entity->{$langcode_key}->language, new FormattableMarkup('%entity_type: Language object can be read.', ['%entity_type' => $entity_type])); // Revert language by code then try setting it by language object. $entity->{$langcode_key}->value = $langcode; $entity->{$langcode_key}->language = \Drupal::languageManager()->getDefaultLanguage(); - $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), $entity->{$langcode_key}->value, format_string('%entity_type: Language code can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage(), $entity->{$langcode_key}->language, format_string('%entity_type: Language object can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->getId(), $entity->{$langcode_key}->value, new FormattableMarkup('%entity_type: Language code can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual(\Drupal::languageManager()->getDefaultLanguage(), $entity->{$langcode_key}->language, new FormattableMarkup('%entity_type: Language object can be read.', ['%entity_type' => $entity_type])); // Access the text field and test updating. - $this->assertEqual($entity->field_test_text->value, $this->entityFieldText, format_string('%entity_type: Text field can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->field_test_text->value, $this->entityFieldText, new FormattableMarkup('%entity_type: Text field can be read.', ['%entity_type' => $entity_type])); $new_text = $this->randomMachineName(); $entity->field_test_text->value = $new_text; - $this->assertEqual($entity->field_test_text->value, $new_text, format_string('%entity_type: Updated text field can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->field_test_text->value, $new_text, new FormattableMarkup('%entity_type: Updated text field can be read.', ['%entity_type' => $entity_type])); // Test creating the entity by passing in plain values. $this->entityName = $this->randomMachineName(); @@ -270,70 +271,70 @@ class EntityFieldTest extends EntityKernelTestBase { 'user_id' => $user_item, 'field_test_text' => $text_item, ]); - $this->assertEqual($this->entityName, $entity->name->value, format_string('%entity_type: Name value can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($this->entityUser->getAccountName(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($this->entityFieldText, $entity->field_test_text->value, format_string('%entity_type: Text field can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($this->entityName, $entity->name->value, new FormattableMarkup('%entity_type: Name value can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, new FormattableMarkup('%entity_type: User id can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($this->entityUser->getAccountName(), $entity->user_id->entity->name->value, new FormattableMarkup('%entity_type: User name can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($this->entityFieldText, $entity->field_test_text->value, new FormattableMarkup('%entity_type: Text field can be read.', ['%entity_type' => $entity_type])); // Tests copying field values by assigning the TypedData objects. $entity2 = $this->createTestEntity($entity_type); $entity2->name = $entity->name; $entity2->user_id = $entity->user_id; $entity2->field_test_text = $entity->field_test_text; - $this->assertFalse($entity->name === $entity2->name, format_string('%entity_type: Copying properties results in a different field object.', ['%entity_type' => $entity_type])); - $this->assertEqual($entity->name->value, $entity2->name->value, format_string('%entity_type: Name field copied.', ['%entity_type' => $entity_type])); - $this->assertEqual($entity->user_id->target_id, $entity2->user_id->target_id, format_string('%entity_type: User id field copied.', ['%entity_type' => $entity_type])); - $this->assertEqual($entity->field_test_text->value, $entity2->field_test_text->value, format_string('%entity_type: Text field copied.', ['%entity_type' => $entity_type])); + $this->assertFalse($entity->name === $entity2->name, new FormattableMarkup('%entity_type: Copying properties results in a different field object.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->name->value, $entity2->name->value, new FormattableMarkup('%entity_type: Name field copied.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->user_id->target_id, $entity2->user_id->target_id, new FormattableMarkup('%entity_type: User id field copied.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->field_test_text->value, $entity2->field_test_text->value, new FormattableMarkup('%entity_type: Text field copied.', ['%entity_type' => $entity_type])); // Tests that assigning TypedData objects to non-field properties keeps the // assigned value as is. $entity2 = $this->createTestEntity($entity_type); $entity2->_not_a_field = $entity->name; - $this->assertTrue($entity2->_not_a_field === $entity->name, format_string('%entity_type: Typed data objects can be copied to non-field properties as is.', ['%entity_type' => $entity_type])); + $this->assertTrue($entity2->_not_a_field === $entity->name, new FormattableMarkup('%entity_type: Typed data objects can be copied to non-field properties as is.', ['%entity_type' => $entity_type])); // Tests adding a value to a field item list. $entity->name[] = 'Another name'; - $this->assertEqual($entity->name[1]->value, 'Another name', format_string('%entity_type: List item added via [] and the first property.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->name[1]->value, 'Another name', new FormattableMarkup('%entity_type: List item added via [] and the first property.', ['%entity_type' => $entity_type])); $entity->name[] = ['value' => 'Third name']; - $this->assertEqual($entity->name[2]->value, 'Third name', format_string('%entity_type: List item added via [] and an array of properties.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->name[2]->value, 'Third name', new FormattableMarkup('%entity_type: List item added via [] and an array of properties.', ['%entity_type' => $entity_type])); $entity->name[3] = ['value' => 'Fourth name']; - $this->assertEqual($entity->name[3]->value, 'Fourth name', format_string('%entity_type: List item added via offset and an array of properties.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->name[3]->value, 'Fourth name', new FormattableMarkup('%entity_type: List item added via offset and an array of properties.', ['%entity_type' => $entity_type])); unset($entity->name[3]); // Test removing and empty-ing list items. - $this->assertEqual(count($entity->name), 3, format_string('%entity_type: List has 3 items.', ['%entity_type' => $entity_type])); + $this->assertEqual(count($entity->name), 3, new FormattableMarkup('%entity_type: List has 3 items.', ['%entity_type' => $entity_type])); unset($entity->name[1]); - $this->assertEqual(count($entity->name), 2, format_string('%entity_type: Second list item has been removed.', ['%entity_type' => $entity_type])); - $this->assertEqual($entity->name[1]->value, 'Third name', format_string('%entity_type: The subsequent items have been shifted up.', ['%entity_type' => $entity_type])); - $this->assertEqual($entity->name[1]->getName(), 1, format_string('%entity_type: The items names have been updated to their new delta.', ['%entity_type' => $entity_type])); + $this->assertEqual(count($entity->name), 2, new FormattableMarkup('%entity_type: Second list item has been removed.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->name[1]->value, 'Third name', new FormattableMarkup('%entity_type: The subsequent items have been shifted up.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->name[1]->getName(), 1, new FormattableMarkup('%entity_type: The items names have been updated to their new delta.', ['%entity_type' => $entity_type])); $entity->name[1] = NULL; - $this->assertEqual(count($entity->name), 2, format_string('%entity_type: Assigning NULL does not reduce array count.', ['%entity_type' => $entity_type])); - $this->assertTrue($entity->name[1]->isEmpty(), format_string('%entity_type: Assigning NULL empties the item.', ['%entity_type' => $entity_type])); + $this->assertEqual(count($entity->name), 2, new FormattableMarkup('%entity_type: Assigning NULL does not reduce array count.', ['%entity_type' => $entity_type])); + $this->assertTrue($entity->name[1]->isEmpty(), new FormattableMarkup('%entity_type: Assigning NULL empties the item.', ['%entity_type' => $entity_type])); // Test using isEmpty(). unset($entity->name[1]); - $this->assertFalse($entity->name[0]->isEmpty(), format_string('%entity_type: Name item is not empty.', ['%entity_type' => $entity_type])); + $this->assertFalse($entity->name[0]->isEmpty(), new FormattableMarkup('%entity_type: Name item is not empty.', ['%entity_type' => $entity_type])); $entity->name->value = NULL; - $this->assertTrue($entity->name[0]->isEmpty(), format_string('%entity_type: Name item is empty.', ['%entity_type' => $entity_type])); - $this->assertTrue($entity->name->isEmpty(), format_string('%entity_type: Name field is empty.', ['%entity_type' => $entity_type])); - $this->assertEqual(count($entity->name), 1, format_string('%entity_type: Empty item is considered when counting.', ['%entity_type' => $entity_type])); - $this->assertEqual(count(iterator_to_array($entity->name->getIterator())), count($entity->name), format_string('%entity_type: Count matches iterator count.', ['%entity_type' => $entity_type])); - $this->assertTrue($entity->name->getValue() === [0 => ['value' => NULL]], format_string('%entity_type: Name field value contains a NULL value.', ['%entity_type' => $entity_type])); + $this->assertTrue($entity->name[0]->isEmpty(), new FormattableMarkup('%entity_type: Name item is empty.', ['%entity_type' => $entity_type])); + $this->assertTrue($entity->name->isEmpty(), new FormattableMarkup('%entity_type: Name field is empty.', ['%entity_type' => $entity_type])); + $this->assertEqual(count($entity->name), 1, new FormattableMarkup('%entity_type: Empty item is considered when counting.', ['%entity_type' => $entity_type])); + $this->assertEqual(count(iterator_to_array($entity->name->getIterator())), count($entity->name), new FormattableMarkup('%entity_type: Count matches iterator count.', ['%entity_type' => $entity_type])); + $this->assertTrue($entity->name->getValue() === [0 => ['value' => NULL]], new FormattableMarkup('%entity_type: Name field value contains a NULL value.', ['%entity_type' => $entity_type])); // Test using filterEmptyItems(). $entity->name = [NULL, 'foo']; - $this->assertEqual(count($entity->name), 2, format_string('%entity_type: List has 2 items.', ['%entity_type' => $entity_type])); + $this->assertEqual(count($entity->name), 2, new FormattableMarkup('%entity_type: List has 2 items.', ['%entity_type' => $entity_type])); $entity->name->filterEmptyItems(); - $this->assertEqual(count($entity->name), 1, format_string('%entity_type: The empty item was removed.', ['%entity_type' => $entity_type])); - $this->assertEqual($entity->name[0]->value, 'foo', format_string('%entity_type: The items were renumbered.', ['%entity_type' => $entity_type])); - $this->assertEqual($entity->name[0]->getName(), 0, format_string('%entity_type: The deltas were updated in the items.', ['%entity_type' => $entity_type])); + $this->assertEqual(count($entity->name), 1, new FormattableMarkup('%entity_type: The empty item was removed.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->name[0]->value, 'foo', new FormattableMarkup('%entity_type: The items were renumbered.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->name[0]->getName(), 0, new FormattableMarkup('%entity_type: The deltas were updated in the items.', ['%entity_type' => $entity_type])); // Test get and set field values. $entity->name = 'foo'; - $this->assertEqual($entity->name[0]->toArray(), ['value' => 'foo'], format_string('%entity_type: Field value has been retrieved via toArray()', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->name[0]->toArray(), ['value' => 'foo'], new FormattableMarkup('%entity_type: Field value has been retrieved via toArray()', ['%entity_type' => $entity_type])); $values = $entity->toArray(); - $this->assertEqual($values['name'], [0 => ['value' => 'foo']], format_string('%entity_type: Field value has been retrieved via toArray() from an entity.', ['%entity_type' => $entity_type])); + $this->assertEqual($values['name'], [0 => ['value' => 'foo']], new FormattableMarkup('%entity_type: Field value has been retrieved via toArray() from an entity.', ['%entity_type' => $entity_type])); // Make sure the user id can be set to zero. $user_item[0]['target_id'] = 0; @@ -344,8 +345,8 @@ class EntityFieldTest extends EntityKernelTestBase { 'user_id' => $user_item, 'field_test_text' => $text_item, ]); - $this->assertNotNull($entity->user_id->target_id, format_string('%entity_type: User id is not NULL', ['%entity_type' => $entity_type])); - $this->assertIdentical($entity->user_id->target_id, 0, format_string('%entity_type: User id has been set to 0', ['%entity_type' => $entity_type])); + $this->assertNotNull($entity->user_id->target_id, new FormattableMarkup('%entity_type: User id is not NULL', ['%entity_type' => $entity_type])); + $this->assertIdentical($entity->user_id->target_id, 0, new FormattableMarkup('%entity_type: User id has been set to 0', ['%entity_type' => $entity_type])); // Test setting the ID with the value only. $entity = $this->container->get('entity_type.manager') @@ -355,8 +356,8 @@ class EntityFieldTest extends EntityKernelTestBase { 'user_id' => 0, 'field_test_text' => $text_item, ]); - $this->assertNotNull($entity->user_id->target_id, format_string('%entity_type: User id is not NULL', ['%entity_type' => $entity_type])); - $this->assertIdentical($entity->user_id->target_id, 0, format_string('%entity_type: User id has been set to 0', ['%entity_type' => $entity_type])); + $this->assertNotNull($entity->user_id->target_id, new FormattableMarkup('%entity_type: User id is not NULL', ['%entity_type' => $entity_type])); + $this->assertIdentical($entity->user_id->target_id, 0, new FormattableMarkup('%entity_type: User id has been set to 0', ['%entity_type' => $entity_type])); } /** @@ -379,21 +380,21 @@ class EntityFieldTest extends EntityKernelTestBase { $langcode_key = $this->entityTypeManager->getDefinition($entity_type)->getKey('langcode'); $entity = $this->createTestEntity($entity_type); $entity->save(); - $this->assertTrue((bool) $entity->id(), format_string('%entity_type: Entity has received an id.', ['%entity_type' => $entity_type])); + $this->assertTrue((bool) $entity->id(), new FormattableMarkup('%entity_type: Entity has received an id.', ['%entity_type' => $entity_type])); $entity = $this->container->get('entity_type.manager') ->getStorage($entity_type) ->load($entity->id()); - $this->assertTrue((bool) $entity->id(), format_string('%entity_type: Entity loaded.', ['%entity_type' => $entity_type])); + $this->assertTrue((bool) $entity->id(), new FormattableMarkup('%entity_type: Entity loaded.', ['%entity_type' => $entity_type])); // Access the name field. - $this->assertEqual(1, $entity->id->value, format_string('%entity_type: ID value can be read.', ['%entity_type' => $entity_type])); - $this->assertTrue(is_string($entity->uuid->value), format_string('%entity_type: UUID value can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual('en', $entity->{$langcode_key}->value, format_string('%entity_type: Language code can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual(\Drupal::languageManager()->getLanguage('en'), $entity->{$langcode_key}->language, format_string('%entity_type: Language object can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($this->entityUser->getAccountName(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', ['%entity_type' => $entity_type])); - $this->assertEqual($this->entityFieldText, $entity->field_test_text->value, format_string('%entity_type: Text field can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual(1, $entity->id->value, new FormattableMarkup('%entity_type: ID value can be read.', ['%entity_type' => $entity_type])); + $this->assertTrue(is_string($entity->uuid->value), new FormattableMarkup('%entity_type: UUID value can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual('en', $entity->{$langcode_key}->value, new FormattableMarkup('%entity_type: Language code can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual(\Drupal::languageManager()->getLanguage('en'), $entity->{$langcode_key}->language, new FormattableMarkup('%entity_type: Language object can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, new FormattableMarkup('%entity_type: User id can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($this->entityUser->getAccountName(), $entity->user_id->entity->name->value, new FormattableMarkup('%entity_type: User name can be read.', ['%entity_type' => $entity_type])); + $this->assertEqual($this->entityFieldText, $entity->field_test_text->value, new FormattableMarkup('%entity_type: Text field can be read.', ['%entity_type' => $entity_type])); } /** @@ -535,8 +536,8 @@ class EntityFieldTest extends EntityKernelTestBase { } $fields = $entity->getFields(); - $this->assertEqual(array_keys($fields), array_keys($entity->getTypedData()->getDataDefinition()->getPropertyDefinitions()), format_string('%entity_type: All fields returned.', ['%entity_type' => $entity_type])); - $this->assertEqual($fields, iterator_to_array($entity->getIterator()), format_string('%entity_type: Entity iterator iterates over all fields.', ['%entity_type' => $entity_type])); + $this->assertEqual(array_keys($fields), array_keys($entity->getTypedData()->getDataDefinition()->getPropertyDefinitions()), new FormattableMarkup('%entity_type: All fields returned.', ['%entity_type' => $entity_type])); + $this->assertEqual($fields, iterator_to_array($entity->getIterator()), new FormattableMarkup('%entity_type: Entity iterator iterates over all fields.', ['%entity_type' => $entity_type])); } /** @@ -584,7 +585,7 @@ class EntityFieldTest extends EntityKernelTestBase { asort($strings); asort($target_strings); - $this->assertEqual(array_values($strings), array_values($target_strings), format_string('%entity_type: All contained strings found.', ['%entity_type' => $entity_type])); + $this->assertEqual(array_values($strings), array_values($target_strings), new FormattableMarkup('%entity_type: All contained strings found.', ['%entity_type' => $entity_type])); } /** @@ -910,14 +911,14 @@ class EntityFieldTest extends EntityKernelTestBase { $entity->field_test_text->format = filter_default_format(); $target = "<p>The <strong>text</strong> text to filter.</p>\n"; - $this->assertEqual($entity->field_test_text->processed, $target, format_string('%entity_type: Text is processed with the default filter.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->field_test_text->processed, $target, new FormattableMarkup('%entity_type: Text is processed with the default filter.', ['%entity_type' => $entity_type])); // Save and load entity and make sure it still works. $entity->save(); $entity = $this->container->get('entity_type.manager') ->getStorage($entity_type) ->load($entity->id()); - $this->assertEqual($entity->field_test_text->processed, $target, format_string('%entity_type: Text is processed with the default filter.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->field_test_text->processed, $target, new FormattableMarkup('%entity_type: Text is processed with the default filter.', ['%entity_type' => $entity_type])); } /** diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php index 951a70b0aa8..aa2a999f2db 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php @@ -42,7 +42,7 @@ class EntityTranslationTest extends EntityLanguageTestBase { 'name' => 'test', 'user_id' => $this->container->get('current_user')->id(), ]); - $this->assertEqual($entity->language()->getId(), $this->languageManager->getDefaultLanguage()->getId(), format_string('%entity_type: Entity created with API has default language.', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->language()->getId(), $this->languageManager->getDefaultLanguage()->getId(), new FormattableMarkup('%entity_type: Entity created with API has default language.', ['%entity_type' => $entity_type])); $entity = $this->container->get('entity_type.manager') ->getStorage($entity_type) ->create([ @@ -51,15 +51,15 @@ class EntityTranslationTest extends EntityLanguageTestBase { $langcode_key => LanguageInterface::LANGCODE_NOT_SPECIFIED, ]); - $this->assertEqual($entity->language()->getId(), LanguageInterface::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Entity language not specified.', ['%entity_type' => $entity_type])); - $this->assertFalse($entity->getTranslationLanguages(FALSE), format_string('%entity_type: No translations are available', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->language()->getId(), LanguageInterface::LANGCODE_NOT_SPECIFIED, new FormattableMarkup('%entity_type: Entity language not specified.', ['%entity_type' => $entity_type])); + $this->assertFalse($entity->getTranslationLanguages(FALSE), new FormattableMarkup('%entity_type: No translations are available', ['%entity_type' => $entity_type])); // Set the value in default language. $entity->set($this->fieldName, [0 => ['value' => 'default value']]); // Get the value. $field = $entity->getTranslation(LanguageInterface::LANGCODE_DEFAULT)->get($this->fieldName); - $this->assertEqual($field->value, 'default value', format_string('%entity_type: Untranslated value retrieved.', ['%entity_type' => $entity_type])); - $this->assertEqual($field->getLangcode(), LanguageInterface::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Field object has the expected langcode.', ['%entity_type' => $entity_type])); + $this->assertEqual($field->value, 'default value', new FormattableMarkup('%entity_type: Untranslated value retrieved.', ['%entity_type' => $entity_type])); + $this->assertEqual($field->getLangcode(), LanguageInterface::LANGCODE_NOT_SPECIFIED, new FormattableMarkup('%entity_type: Field object has the expected langcode.', ['%entity_type' => $entity_type])); // Try to get add a translation to language neutral entity. $message = 'Adding a translation to a language-neutral entity results in an error.'; @@ -76,21 +76,21 @@ class EntityTranslationTest extends EntityLanguageTestBase { $default_langcode = $this->langcodes[0]; $entity->{$langcode_key}->value = $default_langcode; $entity->{$this->fieldName} = []; - $this->assertEqual($entity->language(), \Drupal::languageManager()->getLanguage($this->langcodes[0]), format_string('%entity_type: Entity language retrieved.', ['%entity_type' => $entity_type])); - $this->assertFalse($entity->getTranslationLanguages(FALSE), format_string('%entity_type: No translations are available', ['%entity_type' => $entity_type])); + $this->assertEqual($entity->language(), \Drupal::languageManager()->getLanguage($this->langcodes[0]), new FormattableMarkup('%entity_type: Entity language retrieved.', ['%entity_type' => $entity_type])); + $this->assertFalse($entity->getTranslationLanguages(FALSE), new FormattableMarkup('%entity_type: No translations are available', ['%entity_type' => $entity_type])); // Set the value in default language. $entity->set($this->fieldName, [0 => ['value' => 'default value']]); // Get the value. $field = $entity->get($this->fieldName); - $this->assertEqual($field->value, 'default value', format_string('%entity_type: Untranslated value retrieved.', ['%entity_type' => $entity_type])); - $this->assertEqual($field->getLangcode(), $default_langcode, format_string('%entity_type: Field object has the expected langcode.', ['%entity_type' => $entity_type])); + $this->assertEqual($field->value, 'default value', new FormattableMarkup('%entity_type: Untranslated value retrieved.', ['%entity_type' => $entity_type])); + $this->assertEqual($field->getLangcode(), $default_langcode, new FormattableMarkup('%entity_type: Field object has the expected langcode.', ['%entity_type' => $entity_type])); // Set a translation. $entity->addTranslation($this->langcodes[1])->set($this->fieldName, [0 => ['value' => 'translation 1']]); $field = $entity->getTranslation($this->langcodes[1])->{$this->fieldName}; - $this->assertEqual($field->value, 'translation 1', format_string('%entity_type: Translated value set.', ['%entity_type' => $entity_type])); - $this->assertEqual($field->getLangcode(), $this->langcodes[1], format_string('%entity_type: Field object has the expected langcode.', ['%entity_type' => $entity_type])); + $this->assertEqual($field->value, 'translation 1', new FormattableMarkup('%entity_type: Translated value set.', ['%entity_type' => $entity_type])); + $this->assertEqual($field->getLangcode(), $this->langcodes[1], new FormattableMarkup('%entity_type: Field object has the expected langcode.', ['%entity_type' => $entity_type])); // Make sure the untranslated value stays. $field = $entity->get($this->fieldName); @@ -111,7 +111,7 @@ class EntityTranslationTest extends EntityLanguageTestBase { } // Try to get a not available translation. - $this->assertNull($entity->addTranslation($this->langcodes[2])->get($this->fieldName)->value, format_string('%entity_type: A translation that is not available is NULL.', ['%entity_type' => $entity_type])); + $this->assertNull($entity->addTranslation($this->langcodes[2])->get($this->fieldName)->value, new FormattableMarkup('%entity_type: A translation that is not available is NULL.', ['%entity_type' => $entity_type])); // Try to get a value using an invalid language code. $message = 'Getting an invalid translation results in an error.'; @@ -126,10 +126,10 @@ class EntityTranslationTest extends EntityLanguageTestBase { // Try to set a value using an invalid language code. try { $entity->getTranslation('invalid')->set($this->fieldName, NULL); - $this->fail(format_string('%entity_type: Setting a translation for an invalid language throws an exception.', ['%entity_type' => $entity_type])); + $this->fail(new FormattableMarkup('%entity_type: Setting a translation for an invalid language throws an exception.', ['%entity_type' => $entity_type])); } catch (\InvalidArgumentException $e) { - $this->pass(format_string('%entity_type: Setting a translation for an invalid language throws an exception.', ['%entity_type' => $entity_type])); + $this->pass(new FormattableMarkup('%entity_type: Setting a translation for an invalid language throws an exception.', ['%entity_type' => $entity_type])); } // Set the value in default language. @@ -137,8 +137,8 @@ class EntityTranslationTest extends EntityLanguageTestBase { $entity->getTranslation($this->langcodes[1])->set($field_name, [0 => ['value' => 'default value2']]); // Get the value. $field = $entity->get($field_name); - $this->assertEqual($field->value, 'default value2', format_string('%entity_type: Untranslated value set into a translation in non-strict mode.', ['%entity_type' => $entity_type])); - $this->assertEqual($field->getLangcode(), $default_langcode, format_string('%entity_type: Field object has the expected langcode.', ['%entity_type' => $entity_type])); + $this->assertEqual($field->value, 'default value2', new FormattableMarkup('%entity_type: Untranslated value set into a translation in non-strict mode.', ['%entity_type' => $entity_type])); + $this->assertEqual($field->getLangcode(), $default_langcode, new FormattableMarkup('%entity_type: Field object has the expected langcode.', ['%entity_type' => $entity_type])); } /** @@ -172,21 +172,21 @@ class EntityTranslationTest extends EntityLanguageTestBase { $entity->save(); $entity = $storage->load($entity->id()); $default_langcode = $entity->language()->getId(); - $this->assertEqual($default_langcode, LanguageInterface::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Entity created as language neutral.', ['%entity_type' => $entity_type])); + $this->assertEqual($default_langcode, LanguageInterface::LANGCODE_NOT_SPECIFIED, new FormattableMarkup('%entity_type: Entity created as language neutral.', ['%entity_type' => $entity_type])); $field = $entity->getTranslation(LanguageInterface::LANGCODE_DEFAULT)->get('name'); - $this->assertEqual($name, $field->value, format_string('%entity_type: The entity name has been correctly stored as language neutral.', ['%entity_type' => $entity_type])); - $this->assertEqual($default_langcode, $field->getLangcode(), format_string('%entity_type: The field object has the expect langcode.', ['%entity_type' => $entity_type])); - $this->assertEqual($uid, $entity->getTranslation(LanguageInterface::LANGCODE_DEFAULT)->get('user_id')->target_id, format_string('%entity_type: The entity author has been correctly stored as language neutral.', ['%entity_type' => $entity_type])); + $this->assertEqual($name, $field->value, new FormattableMarkup('%entity_type: The entity name has been correctly stored as language neutral.', ['%entity_type' => $entity_type])); + $this->assertEqual($default_langcode, $field->getLangcode(), new FormattableMarkup('%entity_type: The field object has the expect langcode.', ['%entity_type' => $entity_type])); + $this->assertEqual($uid, $entity->getTranslation(LanguageInterface::LANGCODE_DEFAULT)->get('user_id')->target_id, new FormattableMarkup('%entity_type: The entity author has been correctly stored as language neutral.', ['%entity_type' => $entity_type])); $translation = $entity->getTranslation(LanguageInterface::LANGCODE_DEFAULT); $field = $translation->get('name'); - $this->assertEqual($name, $field->value, format_string('%entity_type: The entity name defaults to neutral language.', ['%entity_type' => $entity_type])); - $this->assertEqual($default_langcode, $field->getLangcode(), format_string('%entity_type: The field object has the expect langcode.', ['%entity_type' => $entity_type])); - $this->assertEqual($uid, $translation->get('user_id')->target_id, format_string('%entity_type: The entity author defaults to neutral language.', ['%entity_type' => $entity_type])); + $this->assertEqual($name, $field->value, new FormattableMarkup('%entity_type: The entity name defaults to neutral language.', ['%entity_type' => $entity_type])); + $this->assertEqual($default_langcode, $field->getLangcode(), new FormattableMarkup('%entity_type: The field object has the expect langcode.', ['%entity_type' => $entity_type])); + $this->assertEqual($uid, $translation->get('user_id')->target_id, new FormattableMarkup('%entity_type: The entity author defaults to neutral language.', ['%entity_type' => $entity_type])); $field = $entity->get('name'); - $this->assertEqual($name, $field->value, format_string('%entity_type: The entity name can be retrieved without specifying a language.', ['%entity_type' => $entity_type])); - $this->assertEqual($default_langcode, $field->getLangcode(), format_string('%entity_type: The field object has the expect langcode.', ['%entity_type' => $entity_type])); - $this->assertEqual($uid, $entity->get('user_id')->target_id, format_string('%entity_type: The entity author can be retrieved without specifying a language.', ['%entity_type' => $entity_type])); + $this->assertEqual($name, $field->value, new FormattableMarkup('%entity_type: The entity name can be retrieved without specifying a language.', ['%entity_type' => $entity_type])); + $this->assertEqual($default_langcode, $field->getLangcode(), new FormattableMarkup('%entity_type: The field object has the expect langcode.', ['%entity_type' => $entity_type])); + $this->assertEqual($uid, $entity->get('user_id')->target_id, new FormattableMarkup('%entity_type: The entity author can be retrieved without specifying a language.', ['%entity_type' => $entity_type])); // Create a language-aware entity and check that properties are stored // as language-aware. @@ -196,11 +196,11 @@ class EntityTranslationTest extends EntityLanguageTestBase { $entity->save(); $entity = $storage->load($entity->id()); $default_langcode = $entity->language()->getId(); - $this->assertEqual($default_langcode, $langcode, format_string('%entity_type: Entity created as language specific.', ['%entity_type' => $entity_type])); + $this->assertEqual($default_langcode, $langcode, new FormattableMarkup('%entity_type: Entity created as language specific.', ['%entity_type' => $entity_type])); $field = $entity->getTranslation($langcode)->get('name'); - $this->assertEqual($name, $field->value, format_string('%entity_type: The entity name has been correctly stored as a language-aware property.', ['%entity_type' => $entity_type])); - $this->assertEqual($default_langcode, $field->getLangcode(), format_string('%entity_type: The field object has the expect langcode.', ['%entity_type' => $entity_type])); - $this->assertEqual($uid, $entity->getTranslation($langcode)->get('user_id')->target_id, format_string('%entity_type: The entity author has been correctly stored as a language-aware property.', ['%entity_type' => $entity_type])); + $this->assertEqual($name, $field->value, new FormattableMarkup('%entity_type: The entity name has been correctly stored as a language-aware property.', ['%entity_type' => $entity_type])); + $this->assertEqual($default_langcode, $field->getLangcode(), new FormattableMarkup('%entity_type: The field object has the expect langcode.', ['%entity_type' => $entity_type])); + $this->assertEqual($uid, $entity->getTranslation($langcode)->get('user_id')->target_id, new FormattableMarkup('%entity_type: The entity author has been correctly stored as a language-aware property.', ['%entity_type' => $entity_type])); // Create property translations. $properties = []; @@ -233,10 +233,10 @@ class EntityTranslationTest extends EntityLanguageTestBase { '%langcode' => $langcode, ]; $field = $entity->getTranslation($langcode)->get('name'); - $this->assertEqual($properties[$langcode]['name'][0], $field->value, format_string('%entity_type: The entity name has been correctly stored for language %langcode.', $args)); + $this->assertEqual($properties[$langcode]['name'][0], $field->value, new FormattableMarkup('%entity_type: The entity name has been correctly stored for language %langcode.', $args)); $field_langcode = ($langcode == $entity->language()->getId()) ? $default_langcode : $langcode; - $this->assertEqual($field_langcode, $field->getLangcode(), format_string('%entity_type: The field object has the expected langcode %langcode.', $args)); - $this->assertEqual($properties[$langcode]['user_id'][0], $entity->getTranslation($langcode)->get('user_id')->target_id, format_string('%entity_type: The entity author has been correctly stored for language %langcode.', $args)); + $this->assertEqual($field_langcode, $field->getLangcode(), new FormattableMarkup('%entity_type: The field object has the expected langcode %langcode.', $args)); + $this->assertEqual($properties[$langcode]['user_id'][0], $entity->getTranslation($langcode)->get('user_id')->target_id, new FormattableMarkup('%entity_type: The entity author has been correctly stored for language %langcode.', $args)); } // Test query conditions (cache is reset at each call). @@ -255,24 +255,24 @@ class EntityTranslationTest extends EntityLanguageTestBase { ->save(); $entities = $storage->loadMultiple(); - $this->assertEqual(count($entities), 3, format_string('%entity_type: Three entities were created.', ['%entity_type' => $entity_type])); + $this->assertEqual(count($entities), 3, new FormattableMarkup('%entity_type: Three entities were created.', ['%entity_type' => $entity_type])); $entities = $storage->loadMultiple([$translated_id]); - $this->assertEqual(count($entities), 1, format_string('%entity_type: One entity correctly loaded by id.', ['%entity_type' => $entity_type])); + $this->assertEqual(count($entities), 1, new FormattableMarkup('%entity_type: One entity correctly loaded by id.', ['%entity_type' => $entity_type])); $entities = $storage->loadByProperties(['name' => $name]); - $this->assertEqual(count($entities), 2, format_string('%entity_type: Two entities correctly loaded by name.', ['%entity_type' => $entity_type])); + $this->assertEqual(count($entities), 2, new FormattableMarkup('%entity_type: Two entities correctly loaded by name.', ['%entity_type' => $entity_type])); // @todo The default language condition should go away in favor of an // explicit parameter. $entities = $storage->loadByProperties(['name' => $properties[$langcode]['name'][0], $default_langcode_key => 0]); - $this->assertEqual(count($entities), 1, format_string('%entity_type: One entity correctly loaded by name translation.', ['%entity_type' => $entity_type])); + $this->assertEqual(count($entities), 1, new FormattableMarkup('%entity_type: One entity correctly loaded by name translation.', ['%entity_type' => $entity_type])); $entities = $storage->loadByProperties([$langcode_key => $default_langcode, 'name' => $name]); - $this->assertEqual(count($entities), 1, format_string('%entity_type: One entity correctly loaded by name and language.', ['%entity_type' => $entity_type])); + $this->assertEqual(count($entities), 1, new FormattableMarkup('%entity_type: One entity correctly loaded by name and language.', ['%entity_type' => $entity_type])); $entities = $storage->loadByProperties([$langcode_key => $langcode, 'name' => $properties[$langcode]['name'][0]]); - $this->assertEqual(count($entities), 0, format_string('%entity_type: No entity loaded by name translation specifying the translation language.', ['%entity_type' => $entity_type])); + $this->assertEqual(count($entities), 0, new FormattableMarkup('%entity_type: No entity loaded by name translation specifying the translation language.', ['%entity_type' => $entity_type])); $entities = $storage->loadByProperties([$langcode_key => $langcode, 'name' => $properties[$langcode]['name'][0], $default_langcode_key => 0]); - $this->assertEqual(count($entities), 1, format_string('%entity_type: One entity loaded by name translation and language specifying to look for translations.', ['%entity_type' => $entity_type])); + $this->assertEqual(count($entities), 1, new FormattableMarkup('%entity_type: One entity loaded by name translation and language specifying to look for translations.', ['%entity_type' => $entity_type])); $entities = $storage->loadByProperties(['user_id' => $properties[$langcode]['user_id'][0], $default_langcode_key => NULL]); - $this->assertEqual(count($entities), 2, format_string('%entity_type: Two entities loaded by uid without caring about property translatability.', ['%entity_type' => $entity_type])); + $this->assertEqual(count($entities), 2, new FormattableMarkup('%entity_type: Two entities loaded by uid without caring about property translatability.', ['%entity_type' => $entity_type])); // Test property conditions and orders with multiple languages in the same // query. @@ -284,7 +284,7 @@ class EntityTranslationTest extends EntityLanguageTestBase { ->condition($group) ->condition('name', $properties[$langcode]['name'][0], '=', $langcode) ->execute(); - $this->assertEqual(count($result), 1, format_string('%entity_type: One entity loaded by name and uid using different language meta conditions.', ['%entity_type' => $entity_type])); + $this->assertEqual(count($result), 1, new FormattableMarkup('%entity_type: One entity loaded by name and uid using different language meta conditions.', ['%entity_type' => $entity_type])); // Test mixed property and field conditions. $storage->resetCache($result); @@ -304,7 +304,7 @@ class EntityTranslationTest extends EntityLanguageTestBase { ->condition($default_langcode_group) ->condition($langcode_group) ->execute(); - $this->assertEqual(count($result), 1, format_string('%entity_type: One entity loaded by name, uid and field value using different language meta conditions.', ['%entity_type' => $entity_type])); + $this->assertEqual(count($result), 1, new FormattableMarkup('%entity_type: One entity loaded by name, uid and field value using different language meta conditions.', ['%entity_type' => $entity_type])); } /** @@ -464,7 +464,7 @@ class EntityTranslationTest extends EntityLanguageTestBase { $translation = $entity->getTranslation($langcode2); $entity->removeTranslation($langcode2); foreach (['get', 'set', '__get', '__set', 'createDuplicate'] as $method) { - $message = format_string('The @method method raises an exception when trying to manipulate a removed translation.', ['@method' => $method]); + $message = new FormattableMarkup('The @method method raises an exception when trying to manipulate a removed translation.', ['@method' => $method]); try { $translation->{$method}('name', $this->randomMachineName()); $this->fail($message); @@ -486,7 +486,7 @@ class EntityTranslationTest extends EntityLanguageTestBase { // Check that removing an invalid translation causes an exception to be // thrown. foreach ([$default_langcode, LanguageInterface::LANGCODE_DEFAULT, $this->randomMachineName()] as $invalid_langcode) { - $message = format_string('Removing an invalid translation (@langcode) causes an exception to be thrown.', ['@langcode' => $invalid_langcode]); + $message = new FormattableMarkup('Removing an invalid translation (@langcode) causes an exception to be thrown.', ['@langcode' => $invalid_langcode]); try { $entity->removeTranslation($invalid_langcode); $this->fail($message); @@ -714,7 +714,7 @@ class EntityTranslationTest extends EntityLanguageTestBase { foreach ($translatable_fields as $name => $translatable) { $this->state->set('entity_test.field_definitions.translatable', [$name => $translatable]); $entity_field_manager->clearCachedFieldDefinitions(); - $message = format_string('Field %field cannot be translatable.', ['%field' => $name]); + $message = new FormattableMarkup('Field %field cannot be translatable.', ['%field' => $name]); try { $entity_field_manager->getBaseFieldDefinitions($entity_type); @@ -831,11 +831,11 @@ class EntityTranslationTest extends EntityLanguageTestBase { foreach ($translation->getFields() as $field_name => $field) { if ($field->getFieldDefinition()->isTranslatable()) { $args = ['%field_name' => $field_name, '%langcode' => $langcode]; - $this->assertEqual($langcode, $field->getEntity()->language()->getId(), format_string('Translatable field %field_name on translation %langcode has correct entity reference in translation %langcode.', $args)); + $this->assertEqual($langcode, $field->getEntity()->language()->getId(), new FormattableMarkup('Translatable field %field_name on translation %langcode has correct entity reference in translation %langcode.', $args)); } else { $args = ['%field_name' => $field_name, '%langcode' => $langcode, '%default_langcode' => $default_langcode]; - $this->assertEqual($default_langcode, $field->getEntity()->language()->getId(), format_string('Non translatable field %field_name on translation %langcode has correct entity reference in the default translation %default_langcode.', $args)); + $this->assertEqual($default_langcode, $field->getEntity()->language()->getId(), new FormattableMarkup('Non translatable field %field_name on translation %langcode has correct entity reference in the default translation %default_langcode.', $args)); } } } diff --git a/core/tests/Drupal/KernelTests/Core/File/DirectoryTest.php b/core/tests/Drupal/KernelTests/Core/File/DirectoryTest.php index f346d31ee5c..f57a5c3e420 100644 --- a/core/tests/Drupal/KernelTests/Core/File/DirectoryTest.php +++ b/core/tests/Drupal/KernelTests/Core/File/DirectoryTest.php @@ -2,6 +2,7 @@ namespace Drupal\KernelTests\Core\File; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\PhpStorage\FileStorage; use Drupal\Core\File\Exception\FileException; use Drupal\Core\File\FileSystemInterface; @@ -115,14 +116,14 @@ class DirectoryTest extends FileTestBase { /** @var \Drupal\Core\File\FileSystemInterface $file_system */ $file_system = \Drupal::service('file_system'); $path = $file_system->createFilename($basename, $directory); - $this->assertEqual($path, $original, format_string('New filepath %new equals %original.', ['%new' => $path, '%original' => $original]), 'File'); + $this->assertEqual($path, $original, new FormattableMarkup('New filepath %new equals %original.', ['%new' => $path, '%original' => $original]), 'File'); // Then we test against a file that already exists within that directory. $basename = 'druplicon.png'; $original = $directory . '/' . $basename; $expected = $directory . '/druplicon_0.png'; $path = $file_system->createFilename($basename, $directory); - $this->assertEqual($path, $expected, format_string('Creating a new filepath from %original equals %new (expected %expected).', ['%new' => $path, '%original' => $original, '%expected' => $expected]), 'File'); + $this->assertEqual($path, $expected, new FormattableMarkup('Creating a new filepath from %original equals %new (expected %expected).', ['%new' => $path, '%original' => $original, '%expected' => $expected]), 'File'); // @TODO: Finally we copy a file into a directory several times, to ensure a properly iterating filename suffix. } diff --git a/core/tests/Drupal/KernelTests/Core/File/MimeTypeTest.php b/core/tests/Drupal/KernelTests/Core/File/MimeTypeTest.php index 01bf221fca5..c959166850c 100644 --- a/core/tests/Drupal/KernelTests/Core/File/MimeTypeTest.php +++ b/core/tests/Drupal/KernelTests/Core/File/MimeTypeTest.php @@ -2,6 +2,8 @@ namespace Drupal\KernelTests\Core\File; +use Drupal\Component\Render\FormattableMarkup; + /** * Tests filename mimetype detection. * @@ -45,12 +47,12 @@ class MimeTypeTest extends FileTestBase { // Test stream [URI]. foreach ($prefixes as $prefix) { $output = $guesser->guess($prefix . $input); - $this->assertIdentical($output, $expected, format_string('Mimetype for %input is %output (expected: %expected).', ['%input' => $prefix . $input, '%output' => $output, '%expected' => $expected])); + $this->assertIdentical($output, $expected, new FormattableMarkup('Mimetype for %input is %output (expected: %expected).', ['%input' => $prefix . $input, '%output' => $output, '%expected' => $expected])); } // Test normal path equivalent $output = $guesser->guess($input); - $this->assertIdentical($output, $expected, format_string('Mimetype (using default mappings) for %input is %output (expected: %expected).', ['%input' => $input, '%output' => $output, '%expected' => $expected])); + $this->assertIdentical($output, $expected, new FormattableMarkup('Mimetype (using default mappings) for %input is %output (expected: %expected).', ['%input' => $input, '%output' => $output, '%expected' => $expected])); } // Now test the extension guesser by passing in a custom mapping. @@ -85,7 +87,7 @@ class MimeTypeTest extends FileTestBase { foreach ($test_case as $input => $expected) { $output = $extension_guesser->guess($input); - $this->assertIdentical($output, $expected, format_string('Mimetype (using passed-in mappings) for %input is %output (expected: %expected).', ['%input' => $input, '%output' => $output, '%expected' => $expected])); + $this->assertIdentical($output, $expected, new FormattableMarkup('Mimetype (using passed-in mappings) for %input is %output (expected: %expected).', ['%input' => $input, '%output' => $output, '%expected' => $expected])); } } diff --git a/core/tests/Drupal/KernelTests/Core/File/NameMungingTest.php b/core/tests/Drupal/KernelTests/Core/File/NameMungingTest.php index 3cf351b031f..789e3fca006 100644 --- a/core/tests/Drupal/KernelTests/Core/File/NameMungingTest.php +++ b/core/tests/Drupal/KernelTests/Core/File/NameMungingTest.php @@ -2,6 +2,8 @@ namespace Drupal\KernelTests\Core\File; +use Drupal\Component\Render\FormattableMarkup; + /** * Tests filename munging and unmunging. * @@ -41,7 +43,7 @@ class NameMungingTest extends FileTestBase { $messages = \Drupal::messenger()->all(); \Drupal::messenger()->deleteAll(); $this->assertTrue(in_array(strtr('For security reasons, your upload has been renamed to <em class="placeholder">%filename</em>.', ['%filename' => $munged_name]), $messages['status']), 'Alert properly set when a file is renamed.'); - $this->assertNotEqual($munged_name, $this->name, format_string('The new filename (%munged) has been modified from the original (%original)', ['%munged' => $munged_name, '%original' => $this->name])); + $this->assertNotEqual($munged_name, $this->name, new FormattableMarkup('The new filename (%munged) has been modified from the original (%original)', ['%munged' => $munged_name, '%original' => $this->name])); } /** @@ -60,7 +62,7 @@ class NameMungingTest extends FileTestBase { public function testMungeIgnoreInsecure() { $this->config('system.file')->set('allow_insecure_uploads', 1)->save(); $munged_name = file_munge_filename($this->name, ''); - $this->assertSame($munged_name, $this->name, format_string('The original filename (%original) matches the munged filename (%munged) when insecure uploads are enabled.', ['%munged' => $munged_name, '%original' => $this->name])); + $this->assertSame($munged_name, $this->name, new FormattableMarkup('The original filename (%original) matches the munged filename (%munged) when insecure uploads are enabled.', ['%munged' => $munged_name, '%original' => $this->name])); } /** @@ -70,10 +72,10 @@ class NameMungingTest extends FileTestBase { // Declare our extension as whitelisted. The declared extensions should // be case insensitive so test using one with a different case. $munged_name = file_munge_filename($this->nameWithUcExt, $this->badExtension); - $this->assertSame($munged_name, $this->nameWithUcExt, format_string('The new filename (%munged) matches the original (%original) once the extension has been whitelisted.', ['%munged' => $munged_name, '%original' => $this->nameWithUcExt])); + $this->assertSame($munged_name, $this->nameWithUcExt, new FormattableMarkup('The new filename (%munged) matches the original (%original) once the extension has been whitelisted.', ['%munged' => $munged_name, '%original' => $this->nameWithUcExt])); // The allowed extensions should also be normalized. $munged_name = file_munge_filename($this->name, strtoupper($this->badExtension)); - $this->assertSame($munged_name, $this->name, format_string('The new filename (%munged) matches the original (%original) also when the whitelisted extension is in uppercase.', ['%munged' => $munged_name, '%original' => $this->name])); + $this->assertSame($munged_name, $this->name, new FormattableMarkup('The new filename (%munged) matches the original (%original) also when the whitelisted extension is in uppercase.', ['%munged' => $munged_name, '%original' => $this->name])); } /** @@ -82,7 +84,7 @@ class NameMungingTest extends FileTestBase { public function testUnMunge() { $munged_name = file_munge_filename($this->name, '', FALSE); $unmunged_name = file_unmunge_filename($munged_name); - $this->assertSame($unmunged_name, $this->name, format_string('The unmunged (%unmunged) filename matches the original (%original)', ['%unmunged' => $unmunged_name, '%original' => $this->name])); + $this->assertSame($unmunged_name, $this->name, new FormattableMarkup('The unmunged (%unmunged) filename matches the original (%original)', ['%unmunged' => $unmunged_name, '%original' => $this->name])); } } diff --git a/core/tests/Drupal/KernelTests/Core/Installer/InstallerLanguageTest.php b/core/tests/Drupal/KernelTests/Core/Installer/InstallerLanguageTest.php index 1f7b9104ee9..e0bb6df6846 100644 --- a/core/tests/Drupal/KernelTests/Core/Installer/InstallerLanguageTest.php +++ b/core/tests/Drupal/KernelTests/Core/Installer/InstallerLanguageTest.php @@ -2,6 +2,7 @@ namespace Drupal\KernelTests\Core\Installer; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\StringTranslation\Translator\FileTranslation; use Drupal\KernelTests\KernelTestBase; @@ -30,9 +31,9 @@ class InstallerLanguageTest extends KernelTestBase { $file_translation = new FileTranslation('core/modules/simpletest/files/translations'); foreach ($expected_translation_files as $langcode => $files_expected) { $files_found = $file_translation->findTranslationFiles($langcode); - $this->assertTrue(count($files_found) == count($files_expected), format_string('@count installer languages found.', ['@count' => count($files_expected)])); + $this->assertTrue(count($files_found) == count($files_expected), new FormattableMarkup('@count installer languages found.', ['@count' => count($files_expected)])); foreach ($files_found as $file) { - $this->assertTrue(in_array($file->filename, $files_expected), format_string('@file found.', ['@file' => $file->filename])); + $this->assertTrue(in_array($file->filename, $files_expected), new FormattableMarkup('@file found.', ['@file' => $file->filename])); } } } diff --git a/core/tests/Drupal/KernelTests/Core/Path/AliasTest.php b/core/tests/Drupal/KernelTests/Core/Path/AliasTest.php index 48d6b7d985d..0892edd09f2 100644 --- a/core/tests/Drupal/KernelTests/Core/Path/AliasTest.php +++ b/core/tests/Drupal/KernelTests/Core/Path/AliasTest.php @@ -2,6 +2,7 @@ namespace Drupal\KernelTests\Core\Path; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Cache\MemoryCounterBackend; use Drupal\Core\Path\AliasStorage; use Drupal\Core\Database\Database; @@ -32,7 +33,7 @@ class AliasTest extends PathUnitTestBase { $result = $connection->query('SELECT * FROM {url_alias} WHERE source = :source AND alias= :alias AND langcode = :langcode', [':source' => $alias['source'], ':alias' => $alias['alias'], ':langcode' => $alias['langcode']]); $rows = $result->fetchAll(); - $this->assertEqual(count($rows), 1, format_string('Created an entry for %alias.', ['%alias' => $alias['alias']])); + $this->assertEqual(count($rows), 1, new FormattableMarkup('Created an entry for %alias.', ['%alias' => $alias['alias']])); // Cache the pid for further tests. $aliases[$idx]['pid'] = $rows[0]->pid; @@ -42,7 +43,7 @@ class AliasTest extends PathUnitTestBase { foreach ($aliases as $alias) { $pid = $alias['pid']; $loadedAlias = $aliasStorage->load(['pid' => $pid]); - $this->assertEqual($loadedAlias, $alias, format_string('Loaded the expected path with pid %pid.', ['%pid' => $pid])); + $this->assertEqual($loadedAlias, $alias, new FormattableMarkup('Loaded the expected path with pid %pid.', ['%pid' => $pid])); } // Load alias by source path. @@ -58,7 +59,7 @@ class AliasTest extends PathUnitTestBase { $result = $connection->query('SELECT pid FROM {url_alias} WHERE source = :source AND alias= :alias AND langcode = :langcode', [':source' => $alias['source'], ':alias' => $alias['alias'] . '_updated', ':langcode' => $alias['langcode']]); $pid = $result->fetchField(); - $this->assertEqual($pid, $alias['pid'], format_string('Updated entry for pid %pid.', ['%pid' => $pid])); + $this->assertEqual($pid, $alias['pid'], new FormattableMarkup('Updated entry for pid %pid.', ['%pid' => $pid])); } // Delete a few aliases @@ -69,7 +70,7 @@ class AliasTest extends PathUnitTestBase { $result = $connection->query('SELECT * FROM {url_alias} WHERE pid = :pid', [':pid' => $pid]); $rows = $result->fetchAll(); - $this->assertEqual(count($rows), 0, format_string('Deleted entry with pid %pid.', ['%pid' => $pid])); + $this->assertEqual(count($rows), 0, new FormattableMarkup('Deleted entry with pid %pid.', ['%pid' => $pid])); } }