Problem/Motivation

AssertLegacyTrait::assertTitle is deprecated and will be removed in Drupal 10.

There is a total of 17 occurrences which needs to be replaced.

Steps to reproduce

Proposed resolution

Replace usages with $this->assertSession()-> titleEquals() .

A big number of the assertions passes TranslatableMarkup to AssertLegacyTrait::assertTitle which casts it as a string, something that :: titleEquals() does not do. So we need to either cast it ourself before we pass it. Or just pass the expected title directly, removing the call to t().

Before:

$this->assertTitle('Translation | Drupal');

After:

$this->assertSession()->titleEquals('Translation | Drupal');

Remaining tasks

User interface changes

API changes

Data model changes

Comments

marcusml created an issue. See original summary.

larisse’s picture

Status: Active » Needs review
StatusFileSize
new6.54 KB

Hi! Here's a patch to fix this deprecated notice.

Status: Needs review » Needs work

The last submitted patch, 2: 3273371-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

marcusml’s picture

Wow thanks! That was fast!

-    $this->assertTitle(t('Settings | Drupal'));
+    $this->assertSession()->titleEquals(t('Settings | Drupal'));

There's a bunch of occurrences like this where we need to remove TranslatableMarkup and just pass the title directly:

Like this:

+    $this->assertSession()->titleEquals('Settings | Drupal');

Or alternativly cast the TranslatableMarkup to a string.

+    $this->assertSession()->titleEquals((string) t('Settings | Drupal'));

Not sure what's the preferred approach... looking at core I can't fint any examples of passing using t() in assertions like this. But maybe there's a case for it here?

larisse’s picture

I never saw any example of passing t(), so what do you prefer? Can I remove it? I can create a new patch.

marcusml’s picture

I'd remove the use of t() from the simple occurrences (like the example in #4) and cast the ones that uses it to format the string.

Like this one for example:

$this->assertSession()->titleEquals((string) t('Are you sure you want to delete the translation job @label? | Drupal', ['@label' => $job->label()]));
larisse’s picture

Status: Needs work » Needs review
StatusFileSize
new6.55 KB

A new patch.

marcusml’s picture

Status: Needs review » Reviewed & tested by the community

Thanks again larisse! I've gone through the changes and it all looks good to me. I've pulled the changes down locally and can verify that all assertTitle calls has been replaced.

berdir’s picture

Status: Reviewed & tested by the community » Needs work

This needs a reroll. Per my recommendation in the main meta issue, I recommend to not work on too many of these in parallel as you'll likely cause extra work as they are quite likely to conflict.

marcusml’s picture

Status: Needs work » Needs review
StatusFileSize
new6.6 KB

Here's a reroll. I checked and this shouldn't have any conflicts with the rerolled patch from #3273368: assertFieldByName and assertNoFieldByName is deprecated and will be removed in Drupal 10.

elber’s picture

Assigned: Unassigned » elber

I will review it.

elber’s picture

Assigned: elber » Unassigned
Status: Needs review » Reviewed & tested by the community

Hi I applied and tested the patch #10, I saw that all changes required on issue summary were corrected. And then I will to move issue status to RTBC.

  • Berdir committed e299f48 on 8.x-1.x authored by larisse
    Issue #3273371 by larisse, marcusml, elber: assertTitle is deprecated...
berdir’s picture

Status: Reviewed & tested by the community » Fixed

Yes, looks good to me as well.

Status: Fixed » Closed (fixed)

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