Problem/Motivation

AssertLegacyTrait::assertResponse() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->statusCodeEquals() instead. See https://www.drupal.org/node/3129738

Proposed resolution

Replace usages of AssertLegacyTrait::assertResponse().

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mondrake created an issue. See original summary.

mondrake’s picture

Version: 8.9.x-dev » 9.1.x-dev
mondrake’s picture

Test only patch only removes the depracation silencer. Patch changes the usages and adds a depreaction test in BrowserTestBase.

mondrake’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 3: 3139218-2.patch, failed testing. View results

sja112’s picture

@mondrake,

I have reviewed the patch and found one change which might lead to patch re-roll in the future if the other issue (#3131900) gets resolved before this.

diff --git a/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php b/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php
index 87c6c0f6..3cdc9a21 100644
--- a/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php
+++ b/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php
@@ -169,10 +169,10 @@ public function assertPagePath($path) {
     $this->container->get('router.builder')->rebuild();
     // Check if we successfully changed the path.
     $this->drupalGet($path);
-    $success = $this->assertResponse(200);
+    $success = $this->assertSession()->statusCodeEquals(200);
     // Check if we don't get any error on the view edit page.
     $this->drupalGet('admin/structure/views/view/test_page_display_path');
-    return $success && $this->assertResponse(200);
+    return $success && $this->assertSession()->statusCodeEquals(200);
   }
 
 }

Since another issue (Patch: #3131900.15) is already RTBC'd. You should avoid making changes in the method assertPagePath.

mondrake’s picture

Status: Needs work » Needs review
FileSize
393.65 KB
4.92 KB

Hi @sja112, it's normally not a problem to have patches on the same piece of code running in parallel. Actually, it's quite the normality. If #3131900: Refactor assertions that assign return values to variables goes in first, this will have to be rerolled; if this goes in first, #3131900: Refactor assertions that assign return values to variables will need a reroll. Postponing a patch on another is normally related to more complex situations to be addressed before continuing, but IMHO it's not the case here.

Failure in #3 is due to UncaughtExceptionTest having its own assertResponse method.

sja112’s picture

@mondrake,

I notice this same piece of change in other patch as well. So just pointed it out. Agreeing to your point here we need a re-roll any ways.

I will review the patch #7 after completion of testing job.

Thanks!

Status: Needs review » Needs work

The last submitted patch, 7: 3139218-7.patch, failed testing. View results

mondrake’s picture

Status: Needs work » Needs review
FileSize
754 bytes
393.25 KB
daffie’s picture

Status: Needs review » Reviewed & tested by the community

All occurrences of $this->assertResponse(XXX); have been replaced by $this->assertSession()->statusCodeEquals(XXX);.
The method was already deprecated in 8.2.
Test has been added for deprecation testing.
The supression of the deprecation message has been removed.
The method Drupal\FunctionalTests\Bootstrap\UncaughtExceptionTest::assertResponse() has been given a proper docblock instead of the @inheritdoc it had.
All code changes look good to me.
For me it is RTBC.

jungle’s picture

Issue tags: +Deprecated assertions

Adding the "Deprecated assertions" tag to add this into the kanban board https://contribkanban.com/board/Deprecatedassertions

xjm’s picture

Title: Replace usages of AssertLegacyTrait::assertResponse(), that is deprecated » Replace usages of AssertLegacyTrait::assertResponse(), which is deprecated

  • xjm committed 1138738 on 9.1.x
    Issue #3139218 by mondrake, daffie: Replace usages of AssertLegacyTrait...
xjm’s picture

Version: 9.1.x-dev » 8.8.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)
Issue tags: +Needs followup

Thanks for this. I confirmed with git diff --color-words that, with one exception, the change is 1:1 replacements of the method call, and that the only grep occurrences of assertResponse( outside the legacy code are in UncaughtExceptionTest.

Even though UncaughtExceptionTest caused a problem here, we should have filed a separate issue to address that. Especially with a patch of this size, it should be an entirely scannable set of one exact pattern of change with git diff --color-words. See https://www.drupal.org/core/scope#context. I almost marked the issue NW for this.

I think it would have been better to file an issue for UncaughtExceptionTest first to actually rename its methods to avoid this confusion. As it is, let's do that as a followup.

Let's make backport patches that replace the method calls but do not un-silence the deprecation. Thank you!

mondrake’s picture

@xjm re #15, I am not sure about the followup for UncaughtExceptionTest. In fact there assertResponse is a helper to the test class itself that overrides the trait implementation. Other methods in this test class fall under the same concept, first and foremost drupalGet - they seem to override mink and use cUrl for the calls to the webserver. In other words they have little to do with this issue - which is about removing the deprecated assertResponse methods that we inherited from Simpletest, using WebAssert assertions instead. If we need to rename those methods than probably a general rethinking of that test is needed, but that would IMHO deserve a full fat issue on its own (i.e. to decouple from BrowserTestBase, probably). If not, than I do not see an issue to have a protected assertResponse method in a concrete test class, it would live its own life.

xjm’s picture

@mondrake My point is mostly that the added docs should not be included in this issue. :) So I would have filed an issue when I noticed the test fail, something like:

Document UncaughtExceptionTest::assertResponse() and decide whether to rename it.

Edit: That doesn't affect the backport; backports are backports. Just a general practice that's increasingly important as we do more of this work.

mondrake’s picture

sja112’s picture

Assigned: Unassigned » sja112

On this.

sja112’s picture

Assigned: sja112 » Unassigned
FileSize
420.57 KB

Backported patch for 8.8.x branch.

sja112’s picture

Status: Patch (to be ported) » Needs review
sja112’s picture

Re-uploading patch caught one error while self-testing. Changes done in the wrong file.

The last submitted patch, 20: 3139218-20-8.8.x.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 22: 3139218-22-8.8.x.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

sja112’s picture

Assigned: Unassigned » sja112
sja112’s picture

Assigned: sja112 » Unassigned
Status: Needs work » Needs review
FileSize
416.57 KB
3.27 KB

Changed patch to fix failed tests.

SimpleTestBrowserTest extends WebTestBase which have its own assertResponse method.

xjm’s picture

Status: Needs review » Needs work

Thanks @sja112. Given the size of this patch, I would recommend backporting it one branch at a time. The version here is just to show which branches allow the change. It does not mean creating a patch that only works for 8.8.x when it has only been committed to 9.1.x. You can test the patch against a different branch than the version selector by selecting the correct version next to the upload button when you submit the patch. Edit: Also, you should just try to apply the patch to the relevant branches locally before uploading. :)

NW to start with a working 9.0.x patch.

sja112’s picture

Assigned: Unassigned » sja112
xjm’s picture

Title: Replace usages of AssertLegacyTrait::assertResponse(), which is deprecated » [backport, 9.0 to 8.8] Replace usages of AssertLegacyTrait::assertResponse(), which is deprecated

Oh and adding the reminder to the title that it's a backport.

sja112’s picture

Assigned: sja112 » Unassigned
Status: Needs work » Needs review
FileSize
389.85 KB

Patch for D9.0 and D8.9

ketikagrover’s picture

Assigned: Unassigned » ketikagrover
ketikagrover’s picture

1. As per #17 need follow up issue has been created in #18 for uncaughtExceptionTest::assertResponse()
2. Backport patches created for D8.8, D8.9, and D9.0
3. Checked all three branches for any occurrence of $this->assertResponse() and all are replaced by $this->assertSession()->statusCodeEquals()
All code changes look good to me.
For me it is RTBC.

ketikagrover’s picture

Assigned: ketikagrover » Unassigned
ketikagrover’s picture

Status: Needs review » Reviewed & tested by the community

  • xjm committed 8972542 on 9.0.x
    Issue #3139218 by sja112, mondrake, xjm, ketikagrover, daffie: Replace...

  • xjm committed fafe982 on 8.9.x
    Issue #3139218 by sja112, mondrake, xjm, ketikagrover, daffie: Replace...
xjm’s picture

Thanks @sja112 and @ketikagrover. I reviewed locally with git diff --color-words (which was very hypnotic; I almost dozed off a couple times!) and also checked 9.0.x for other usages:

[ibnsina:maintainer | Thu 13:59:36] $ grep -r "assertResponse(" * | grep -v "~"
core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php:    $this->assertResponse(500);
core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php:    $this->assertResponse(500);
core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php:    $this->assertResponse(500);
core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php:    $this->assertResponse(418);
core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php:    $this->assertResponse(500);
core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php:    $this->assertResponse(418);
core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php:    $this->assertResponse(500);
core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php:    $this->assertResponse(500);
core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php:    $this->assertResponse(500);
core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php:    $this->assertResponse(500);
core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php:  protected function assertResponse($code) {
core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php:  protected function assertResponse($code) {

That's the same test again (with the followup) plus the legacy method.

I cherry-picked it to 8.9.x as well. 8.9.x has a number of other matches:

[ibnsina:maintainer | Thu 14:04:03] $ grep -rl "assertResponse(" * | grep -v "~"
core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php
core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php
core/tests/Drupal/FunctionalTests/Installer/InstallerCustomConfigDirectoryCreateTest.php
core/tests/Drupal/FunctionalTests/Installer/InstallerExistingSettingsMismatchProfileTest.php
core/modules/file/tests/src/Functional/Update/FileUsageTemporaryDeletionConfigurationUpdateTest.php
core/modules/views_ui/src/Tests/UITestBase.php
core/modules/aggregator/src/Tests/AggregatorTestBase.php
core/modules/system/tests/src/Functional/Update/UpdatePathRC1TestBaseFilledTest.php
core/modules/system/tests/src/Functional/Render/AjaxPageStateTest.php
core/modules/system/src/Tests/Entity/EntityWithUriCacheTagsTestBase.php
core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php
core/modules/rest/src/Tests/RESTTestBase.php
core/modules/block/tests/src/Functional/Update/BlockContextMappingUpdateTest.php
core/modules/simpletest/src/WebTestBase.php
core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php

At least some of those are SimpleTests which should not be changed, but not all of them. That said, the main goal of backporting this is to keep the branches in sync so that other cherry-picks are successful. Therefore, there's not too much value in fixing additional cases that are D8-only, so I pushed the 8.9.x cherry-pick to avoid anything going stale there.

I'll review 8.8.x. in a bit. Thanks!

xjm’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

#26 does not apply anymore, so NW for that to be rerolled.

sja112’s picture

Assigned: Unassigned » sja112
sja112’s picture

Assigned: sja112 » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
417.01 KB

Re-rolled patch for the D8.8 branch.

ketikagrover’s picture

Status: Needs review » Reviewed & tested by the community

1. Patch re-rolled for D8.8 branch
2. One change I observed in this patch that some inline comments are added below is the example,

--- a/core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php
+++ b/core/modules/basic_auth/tests/src/Functional/BasicAuthTest.php
@@ -47,30 +47,36 @@ public function testBasicAuth() {
+    // Ensure we can log in with valid authentication details.
     $this->basicAuthGet($url, $account->getAccountName(), $account->pass_raw);

After debugging I noticed that changes are already present D8.9 and above branches.
as we are keeping all the branches the same and its good to have the appropriate information with the code this change is valid in my view.

Patch looks good to me.
Thanks!

xjm’s picture

Status: Reviewed & tested by the community » Postponed

Thanks @ketikagrover for describing how you reviewed this; that made me realize something that was affecting the 8.8.x backport. Example:

+++ b/core/modules/comment/tests/src/Functional/CommentAdminTest.php
@@ -159,9 +159,9 @@ public function testApprovalNodeInterface() {
     // Approve comment.
     $this->drupalLogin($this->adminUser);
     $this->drupalGet('comment/1/approve');
-    $this->assertResponse(403, 'Forged comment approval was denied.');
+    $this->assertSession()->statusCodeEquals(403);
     $this->drupalGet('comment/1/approve', ['query' => ['token' => 'forged']]);
-    $this->assertResponse(403, 'Forged comment approval was denied.');
+    $this->assertSession()->statusCodeEquals(403);

This is not being fixed correctly as it was in #3132964: assertResponse() does not actually support a $message parameter, so stop passing one.

I think what we should do is work on a backport of that patch first, and get that committed to 8.8.x. Then, we can reroll @sja112's patch on top of that. It should mostly be a clean rebase since @sja112's fixes have followed the same patterns, but a few hunks might need to be fixed manually. Then, this patch will be easier to review and commit as well. Thanks!

xjm’s picture

Note that the final commit freeze for 8.8.x is on June 2 at 1200 UTC, so if it gets too close to that, there's a chance we might not be able to commit the backport. That said, the review is easier when all the comment changes are happening in the separate issue, so that should help.

xjm’s picture

Title: [backport, 9.0 to 8.8] Replace usages of AssertLegacyTrait::assertResponse(), which is deprecated » [backport to 8.8] Replace usages of AssertLegacyTrait::assertResponse(), which is deprecated

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

mondrake’s picture

Title: [backport to 8.8] Replace usages of AssertLegacyTrait::assertResponse(), which is deprecated » Replace usages of AssertLegacyTrait::assertResponse(), which is deprecated
Status: Postponed » Fixed

I suppose this is no longer committable to D8.8.

Status: Fixed » Closed (fixed)

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