- 🇳🇿New Zealand quietone
Closing as a duplicate of 📌 [meta] Remove usage of t() in tests not testing translation Active and moving credit.
- 🇳🇿New Zealand quietone
I think I should not have closed this. I was probably focused on t() at the time but today I see uses of FormattableMarkup in tests where it could be removed. And I guess I didn't read #74.
Sorry folks.
- Status changed to Active
7 months ago 8:50am 30 November 2024 - 🇷🇺Russia zniki.ru
Thanks everyone for your effort.
It looks like title and summary are different, as already mentioned at #51, and it's extremely difficult to understand what is happening here/
As I understand original issue was "Remove all usage of SafeMarkup::format() and format_string() in tests apart from explicit tests of those methods".I checked patch #78, at the top we remove t() function.
My suggestion:
revert issue title to original value and close this issue, and create new one with focus to remove FormattableMarkup.In order to provide code contribution is better to use child issue #3227598: Remove uses of FormattableMarkup in kernel test assertions → .
- 🇳🇿New Zealand quietone
Since
SafeMarkup
was replaced byFormattableMarkup
I think we can continue with this issue. There is already a child issue here for Kernel tests. Another one is needed for Functional tests.As I understand #51, the follow up was to manage the number of changes. Since then, a separate issue has been created for Kernel test, which will help manage the scale of the changes. So, I don't think the tag is necessary any more.
- 🇳🇿New Zealand quietone
The current child issues have been fixed. So, time for a last check for any remaining occurrences that need to be changed.
There are 128 usages of FormattableMarkup in tests in 32 files, according to results from the following.git grep FormattableMarkup | grep Test.php: | wc -l git grep FormattableMarkup | grep Test.php: | awk -F: '{print $1}' | sort -u | nl
Expanding the search to 5 lines before and after results in 12 instances to check.
$ git grep -A5 -B5 FormattableMarkup | grep Test.php: | grep -i assert | nl 1 core/modules/comment/tests/src/Functional/CommentAdminTest.php: $this->assertSession()->responseContains(new FormattableMarkup('@label (Original translation) - <em>The following comment translations will be deleted:</em>', ['@label' => $comment1->label()])); 2 core/modules/comment/tests/src/Functional/CommentAdminTest.php: $this->assertSession()->responseContains(new FormattableMarkup('@label (Original translation) - <em>The following comment translations will be deleted:</em>', ['@label' => $comment2->label()])); 3 core/modules/contact/tests/src/Functional/ContactPersonalTest.php: $this->assertSession()->responseContains(new FormattableMarkup('@sender_name (@sender_email) sent @recipient_name an email.', $placeholders)); 4 core/modules/field/tests/src/Functional/FunctionalString/StringFieldTest.php: $this->assertSession()->responseContains(new FormattableMarkup('placeholder="A placeholder on @widget_type"', ['@widget_type' => $widget_type])); 5 core/modules/system/tests/src/Functional/Form/FormTest.php: $this->assertSession()->responseContains(new FormattableMarkup($message, $placeholders)); 6 core/modules/system/tests/src/Functional/Form/FormTest.php: $this->assertSession()->responseNotContains(new FormattableMarkup($message, $placeholders)); 7 core/modules/taxonomy/tests/src/Functional/VocabularyUiTest.php: $this->assertSession()->responseContains(new FormattableMarkup('Are you sure you want to delete the vocabulary %name?', ['%name' => $edit['name']])); 8 core/modules/taxonomy/tests/src/Functional/VocabularyUiTest.php: $this->assertSession()->responseContains(new FormattableMarkup('Deleted vocabulary %name.', ['%name' => $edit['name']])); 9 core/modules/views/tests/src/Functional/Plugin/DisplayTest.php: $this->assertEquals(new FormattableMarkup('The %relationship_name relationship used in %handler_type %handler is not present in the %display_name display.', ['%relationship_name' => 'uid', '%handler_type' => 'field', '%handler' => 'User: Last login', '%display_name' => 'Default']), $errors['default'][0]); 10 core/modules/views/tests/src/Functional/Plugin/DisplayTest.php: $this->assertEquals(new FormattableMarkup('The %relationship_name relationship used in %handler_type %handler is not present in the %display_name display.', ['%relationship_name' => 'uid', '%handler_type' => 'field', '%handler' => 'User: Created', '%display_name' => 'Default']), $errors['default'][1]); 11 core/tests/Drupal/KernelTests/Component/Render/FormattableMarkupKernelTest.php: $this->assertSame($expected, (string) new FormattableMarkup($string, $args)); 12 core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php: public function testIsStringAssertionWithFormattableMarkup(): void {
- 🇳🇿New Zealand quietone
Searching for remaining usages with the following. I then struck out the ones that are testing the API
$ git grep FormattableMarkup | grep -v "Test\.php:\s*\* " | grep Test.php: | awk -F: '{print $1}' | sort -u | nl 1 core/modules/system/tests/src/Functional/System/ErrorHandlerTest.php 2 core/modules/system/tests/src/Kernel/Theme/FunctionsTest.php 3 <del>core/modules/user/tests/modules/user_hooks_test/src/Hook/UserHooksTest.php</del> 4 core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php 5 <del> core/tests/Drupal/KernelTests/Component/Render/FormattableMarkupKernelTest.php</del> 6 core/tests/Drupal/KernelTests/Core/Routing/ExceptionHandlingTest.php 7 core/tests/Drupal/KernelTests/Core/Test/Comparator/MarkupInterfaceComparatorTest.php 8 <del>core/tests/Drupal/KernelTests/Core/Theme/TwigMarkupInterfaceTest.php</del> 9 <del>core/tests/Drupal/Tests/Component/Render/FormattableMarkupTest.php</del> 10 <del>core/tests/Drupal/Tests/Component/Render/PlainTextOutputTest.php</del> 11 core/tests/Drupal/Tests/Core/Config/Checkpoint/LinearHistoryTest.php 12 <del>core/tests/Drupal/Tests/Core/Logger/LogMessageParserTest.php</del> 13 core/tests/Drupal/Tests/Core/Mail/Plugin/Mail/SymfonyMailerTest.php 14 <del>core/tests/Drupal/Tests/Core/StringTranslation/TranslatableMarkupTest.php</del>
- 🇳🇿New Zealand quietone
to check
- core/modules/system/tests/src/Kernel/Theme/FunctionsTest.php
- core/tests/Drupal/Tests/Core/Logger/LogMessageParserTest.php
- 🇳🇿New Zealand quietone
There is one failing test, \Drupal\FunctionalTests\Bootstrap\UncaughtExceptionTest::testUncaughtFatalError, which passes locally for different versions of PHP. Not sure why it is failing here though.
Setting to NR because the existing changes can be reviewed as well as checking if there are other instances that need to change.