Problem/Motivation

There is no need to use t() in tests, unless we're testing translations, however in core we do not follow this consistently, which does not set a good example for new contributions.

In #3133726: [meta] Remove usage of t() in tests not testing translation we identified there are severals of calls to t() in calls to clickViewsOperationLink(), helperButtonHasLabel() and optionExists() and that removing all these in one go seems to be a suitable way of attacking this problem.

Proposed resolution

Identify and remove all calls to t() wrapped in calls to clickViewsOperationLink(), helperButtonHasLabel() and optionExists(), except those used by translation-related code (if any).

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Hardik_Patel_12 created an issue. See original summary.

Hardik_Patel_12’s picture

Kindly review the patch.

Hardik_Patel_12’s picture

Status: Active » Needs review
siddhant.bhosale’s picture

Assigned: Unassigned » siddhant.bhosale
siddhant.bhosale’s picture

Status: Needs review » Needs work

Hi @Hardik_Patel_12,
The following hunk already exists in the core, and was skipping while applying the patch. So removing the code from your patch.

--- a/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php
+++ b/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php
@@ -460,23 +460,23 @@ public function testDatelistWidget() {
 
     $this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-year\"]", NULL, 'Year element found.');
     $this->assertOptionSelected("edit-$field_name-0-value-year", '', 'No year selected.');
-    $this->assertSession()->optionExists("edit-$field_name-0-value-year", t('Year'));
+    $this->assertSession()->optionExists("edit-$field_name-0-value-year", 'Year');
     $this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-month\"]", NULL, 'Month element found.');
     $this->assertOptionSelected("edit-$field_name-0-value-month", '', 'No month selected.');
-    $this->assertSession()->optionExists("edit-$field_name-0-value-month", t('Month'));
+    $this->assertSession()->optionExists("edit-$field_name-0-value-month", 'Month');
     $this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-day\"]", NULL, 'Day element found.');
     $this->assertOptionSelected("edit-$field_name-0-value-day", '', 'No day selected.');
-    $this->assertSession()->optionExists("edit-$field_name-0-value-day", t('Day'));
+    $this->assertSession()->optionExists("edit-$field_name-0-value-day", 'Day');
     $this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-hour\"]", NULL, 'Hour element found.');
     $this->assertOptionSelected("edit-$field_name-0-value-hour", '', 'No hour selected.');
-    $this->assertSession()->optionExists("edit-$field_name-0-value-hour", t('Hour'));
+    $this->assertSession()->optionExists("edit-$field_name-0-value-hour", 'Hour');
     $this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-minute\"]", NULL, 'Minute element found.');
     $this->assertOptionSelected("edit-$field_name-0-value-minute", '', 'No minute selected.');
-    $this->assertSession()->optionExists("edit-$field_name-0-value-minute", t('Minute'));
+    $this->assertSession()->optionExists("edit-$field_name-0-value-minute", 'Minute');
     $this->assertNoFieldByXPath("//*[@id=\"edit-$field_name-0-value-second\"]", NULL, 'Second element not found.');
     $this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-ampm\"]", NULL, 'AMPM element found.');
     $this->assertOptionSelected("edit-$field_name-0-value-ampm", '', 'No ampm selected.');
-    $this->assertSession()->optionExists("edit-$field_name-0-value-ampm", t('AM/PM'));
+    $this->assertSession()->optionExists("edit-$field_name-0-value-ampm", 'AM/PM');
 
     // Submit a valid date and ensure it is accepted.
     $date_value = ['year' => 2012, 'month' => 12, 'day' => 31, 'hour' => 5, 'minute' => 15];

Marking this to needs work.

siddhant.bhosale’s picture

Assigned: siddhant.bhosale » Unassigned
Status: Needs work » Needs review
FileSize
9.77 KB
2.62 KB

Hi,
Adding the new patch and interdiff. Please review

mondrake’s picture

Issue tags: -Deprecated assertions
longwave’s picture

Status: Needs review » Reviewed & tested by the community

Confirmed there are no uses of t() remaining in calls to these three methods after applying #6.

alexpott’s picture

Version: 9.1.x-dev » 8.9.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 7ad99c1ee8 to 9.1.x and b6c39ff6a2 to 9.0.x and 2ebe9ce923 to 8.9.x. Thanks!

Backported to 8.9.x to keep tests aligned.

  • alexpott committed 7ad99c1 on 9.1.x
    Issue #3153264 by siddhant.bhosale, Hardik_Patel_12, longwave: Remove...

  • alexpott committed b6c39ff on 9.0.x
    Issue #3153264 by siddhant.bhosale, Hardik_Patel_12, longwave: Remove...

  • alexpott committed 2ebe9ce on 8.9.x
    Issue #3153264 by siddhant.bhosale, Hardik_Patel_12, longwave: Remove...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.