From 19b213dbef5902bcfaae99873c7ecaa6c8868be0 Mon Sep 17 00:00:00 2001 From: nod_ <nod_@598310.no-reply.drupal.org> Date: Thu, 22 Aug 2024 16:25:18 +0200 Subject: [PATCH] Issue #3405364 by quietone, dww, mstrelan, smustgrave: Update docs to stop recommending FormattableMarkup --- core/lib/Drupal/Core/Test/AssertMailTrait.php | 21 +- .../Drupal/KernelTests/AssertContentTrait.php | 259 ++++++++++-------- core/tests/Drupal/Tests/WebAssert.php | 28 +- 3 files changed, 176 insertions(+), 132 deletions(-) diff --git a/core/lib/Drupal/Core/Test/AssertMailTrait.php b/core/lib/Drupal/Core/Test/AssertMailTrait.php index 44e4a5d09a27..80b74b52242e 100644 --- a/core/lib/Drupal/Core/Test/AssertMailTrait.php +++ b/core/lib/Drupal/Core/Test/AssertMailTrait.php @@ -47,9 +47,10 @@ protected function getMails(array $filter = []) { * Value of the field to assert. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass. @@ -74,9 +75,10 @@ protected function assertMail($name, $value = '', $message = '') { * Number of emails to search for string, starting with most recent. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. */ protected function assertMailString($field_name, $string, $email_depth, $message = '') { $mails = $this->getMails(); @@ -109,9 +111,10 @@ protected function assertMailString($field_name, $string, $email_depth, $message * Pattern to search for. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. */ protected function assertMailPattern($field_name, $regex, $message = '') { $mails = $this->getMails(); diff --git a/core/tests/Drupal/KernelTests/AssertContentTrait.php b/core/tests/Drupal/KernelTests/AssertContentTrait.php index 8d16f053f53b..f5a73f1b6484 100644 --- a/core/tests/Drupal/KernelTests/AssertContentTrait.php +++ b/core/tests/Drupal/KernelTests/AssertContentTrait.php @@ -296,9 +296,10 @@ protected function assertLink($label, $index = 0, $message = ''): bool { * Text between the anchor tags. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE if the assertion succeeded. @@ -321,9 +322,10 @@ protected function assertNoLink($label, $message = ''): bool { * Link position counting from zero. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE if the assertion succeeded. @@ -342,9 +344,10 @@ protected function assertLinkByHref($href, $index = 0, $message = ''): bool { * The full or partial value of the 'href' attribute of the anchor tag. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE if the assertion succeeded. @@ -363,9 +366,10 @@ protected function assertNoLinkByHref($href, $message = ''): bool { * The full or partial value of the 'href' attribute of the anchor tag. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE if the assertion succeeded. @@ -386,9 +390,10 @@ protected function assertNoLinkByHrefInMainRegion($href, $message = ''): bool { * Raw (HTML) string to look for. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. */ protected function assertRaw($raw, $message = ''): void { if (!$message) { @@ -406,9 +411,10 @@ protected function assertRaw($raw, $message = ''): void { * Raw (HTML) string to look for. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. */ protected function assertNoRaw($raw, $message = ''): void { if (!$message) { @@ -426,9 +432,10 @@ protected function assertNoRaw($raw, $message = ''): void { * Raw (HTML) string to look for. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. */ protected function assertEscaped($raw, $message = ''): void { if (!$message) { @@ -446,9 +453,10 @@ protected function assertEscaped($raw, $message = ''): void { * Raw (HTML) string to look for. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. */ protected function assertNoEscaped($raw, $message = ''): void { if (!$message) { @@ -467,9 +475,10 @@ protected function assertNoEscaped($raw, $message = ''): void { * Plain text to look for. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @see \Drupal\KernelTests\AssertContentTrait::assertRaw() */ @@ -487,9 +496,10 @@ protected function assertText($text, $message = ''): void { * Plain text to look for. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @see \Drupal\KernelTests\AssertContentTrait::assertNoRaw() */ @@ -506,9 +516,10 @@ protected function assertNoText($text, $message = ''): void { * Plain text to look for. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * @param string $group * Deprecated. * @param bool $not_exists @@ -538,9 +549,10 @@ protected function assertTextHelper($text, $message = '', $group = NULL, $not_ex * Plain text to look for. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass, FALSE on fail. @@ -560,9 +572,10 @@ protected function assertUniqueText($text, $message = '') { * Plain text to look for. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass, FALSE on fail. @@ -580,9 +593,10 @@ protected function assertNoUniqueText($text, $message = '') { * Plain text to look for. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * @param string $group * Deprecated. * @param bool $be_unique @@ -615,9 +629,10 @@ protected function assertUniqueTextHelper($text, $message = '', $group = NULL, $ * Perl regex to look for including the regex delimiters. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass. @@ -637,9 +652,10 @@ protected function assertPattern($pattern, $message = ''): bool { * Perl regex to look for including the regex delimiters. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass. @@ -678,9 +694,10 @@ protected function assertTextPattern($pattern, $message = NULL): bool { * The string the title should be. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. */ protected function assertTitle($title, $message = '') { // Don't use xpath as it messes with HTML escaping. @@ -707,9 +724,10 @@ protected function assertTitle($title, $message = '') { * The string the title should not be. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. */ protected function assertNoTitle($title, $message = '') { $actual = (string) current($this->xpath('//title')); @@ -733,9 +751,10 @@ protected function assertNoTitle($title, $message = '') { * The expected themed output string. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. */ protected function assertThemeOutput($callback, array $variables = [], $expected = '', $message = '') { /** @var \Drupal\Core\Render\RendererInterface $renderer */ @@ -764,9 +783,10 @@ protected function assertThemeOutput($callback, array $variables = [], $expected * checking the actual value, while still checking that the field exists. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass. @@ -819,9 +839,10 @@ protected function assertFieldsByValue($fields, $value = NULL, $message = ''): b * exists. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass, FALSE on fail. @@ -865,9 +886,10 @@ protected function getSelectedItem(\SimpleXMLElement $element) { * page does not match it. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass. @@ -903,9 +925,10 @@ protected function assertNoFieldByXPath($xpath, $value = NULL, $message = ''): b * exists. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass, FALSE on fail. @@ -939,9 +962,10 @@ protected function assertFieldByName($name, $value = NULL, $message = NULL) { * default value ('') asserts that the field value is not an empty string. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass, FALSE on fail. @@ -962,9 +986,10 @@ protected function assertNoFieldByName($name, $value = '', $message = '') { * string. * @param string|\Drupal\Component\Render\MarkupInterface $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass, FALSE on fail. @@ -990,9 +1015,10 @@ protected function assertFieldById($id, $value = '', $message = '') { * value ('') asserts that the field value is not an empty string. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass, FALSE on fail. @@ -1008,9 +1034,10 @@ protected function assertNoFieldById($id, $value = '', $message = '') { * ID of field to assert. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass. @@ -1030,9 +1057,10 @@ protected function assertFieldChecked($id, $message = ''): bool { * ID of field to assert. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass. @@ -1054,9 +1082,10 @@ protected function assertNoFieldChecked($id, $message = ''): bool { * Option to assert. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. */ protected function assertOption($id, $option, $message = '') { $options = $this->xpath('//select[@id=:id]//option[@value=:option]', [':id' => $id, ':option' => $option]); @@ -1087,9 +1116,10 @@ protected function assertOptionByText($id, $text, $message = '') { * Option to assert. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. */ protected function assertOptionWithDrupalSelector($drupal_selector, $option, $message = '') { $options = $this->xpath('//select[@data-drupal-selector=:data_drupal_selector]//option[@value=:option]', [':data_drupal_selector' => $drupal_selector, ':option' => $option]); @@ -1105,9 +1135,10 @@ protected function assertOptionWithDrupalSelector($drupal_selector, $option, $me * Option to assert. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass. @@ -1130,9 +1161,10 @@ protected function assertNoOption($id, $option, $message = ''): bool { * Option to assert. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass. @@ -1156,9 +1188,10 @@ protected function assertOptionSelected($id, $option, $message = ''): bool { * Option to assert. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass, FALSE on fail. @@ -1182,9 +1215,10 @@ protected function assertOptionSelectedWithDrupalSelector($drupal_selector, $opt * Option to assert. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass. @@ -1204,9 +1238,10 @@ protected function assertNoOptionSelected($id, $option, $message = ''): bool { * Name or ID of field to assert. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass, FALSE on fail. @@ -1222,9 +1257,10 @@ protected function assertField($field, $message = '') { * Name or ID of field to assert. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @return bool * TRUE on pass, FALSE on fail. @@ -1238,9 +1274,10 @@ protected function assertNoField($field, $message = '') { * * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * @param string $group * Deprecated. * @param array $ids_to_skip diff --git a/core/tests/Drupal/Tests/WebAssert.php b/core/tests/Drupal/Tests/WebAssert.php index a2b26d8d523b..fd89b05f6bc7 100644 --- a/core/tests/Drupal/Tests/WebAssert.php +++ b/core/tests/Drupal/Tests/WebAssert.php @@ -387,9 +387,10 @@ public function linkNotExistsExact($label, $message = '') { * Link position counting from zero. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @throws \Behat\Mink\Exception\ExpectationException * Thrown when element doesn't exist, or the link label is a different one. @@ -410,9 +411,10 @@ public function linkByHrefExists($href, $index = 0, $message = '') { * Link position counting from zero. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @throws \Behat\Mink\Exception\ExpectationException * Thrown when element doesn't exist, or the link label is a different one. @@ -431,9 +433,10 @@ public function linkByHrefExistsExact(string $href, int $index = 0, string $mess * The full or partial value of the 'href' attribute of the anchor tag. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @throws \Behat\Mink\Exception\ExpectationException * Thrown when element doesn't exist, or the link label is a different one. @@ -452,9 +455,10 @@ public function linkByHrefNotExists($href, $message = '') { * The full value of the 'href' attribute of the anchor tag. * @param string $message * (optional) A message to display with the assertion. Do not translate - * messages: use \Drupal\Component\Render\FormattableMarkup to embed - * variables in the message text, not t(). If left blank, a default message - * will be displayed. + * messages with t(). Use double quotes and embed variables directly in + * message text, or use sprintf() if necessary. Avoid the use of + * \Drupal\Component\Render\FormattableMarkup unless you cast the object to + * a string. If left blank, a default message will be displayed. * * @throws \Behat\Mink\Exception\ExpectationException * Thrown when element doesn't exist, or the link label is a different one. -- GitLab