Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mondrake created an issue. See original summary.

jungle’s picture

Issue tags: +Deprecated assertions

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

jungle’s picture

Status: Active » Needs review
FileSize
58.76 KB
xjm’s picture

Title: Replace usages of AssertLegacyTrait::assert(No)FieldChecked, that is deprecated » Replace usages of deprecated AssertLegacyTrait::assert(No)FieldChecked()

Status: Needs review » Needs work

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

ridhimaabrol24’s picture

Assigned: Unassigned » ridhimaabrol24
ridhimaabrol24’s picture

Assigned: ridhimaabrol24 » Unassigned
Status: Needs work » Needs review
FileSize
54.64 KB
21.7 KB

Patched #3 failed to apply on 9.1.x-dev. Rerolled the patch and fixed the failed tests.

Bunty Badgujar’s picture

Status: Needs review » Needs work

In #7
Remove Deprecation Listener
There still assertFieldChecked() and assertNoFieldChecked() left. For example, core/modules/comment/tests/src/Functional/CommentAdminTest.php
Add Test for AssertLegacyTrait::assert(No)FieldChecked()

mrinalini9’s picture

Assigned: Unassigned » mrinalini9
mrinalini9’s picture

Assigned: mrinalini9 » Unassigned
Status: Needs work » Needs review
FileSize
55.72 KB
19.25 KB

Updated patch #7 and removed Deprecation Listener as mentioned in #8, please review.

Status: Needs review » Needs work

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

Hardik_Patel_12’s picture

Status: Needs work » Needs review
FileSize
55.4 KB
703 bytes

There is mis-matching between the patch at #10 and description of this issue. Either we should update the patch or update the description. Right now i am creating new patch according to description of the issue and removing deprecation listener from core/modules/comment/tests/src/Functional/CommentAdminTest.php which was missed in patch no #7.

And there are many more deprecated methods are still present like as below.

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

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

AssertLegacyTrait::constructFieldXpath() is deprecated in drupal:8.5.0 and is removed from drupal:10.0.0. Use $this->getSession()->getPage()->findField() instead. See https://www.drupal.org/node/3129738

and many more for this we can create different issues and try to solve accordingly.

Bunty Badgujar’s picture

Status: Needs review » Needs work

Thanks for contribution @hardik_patel,

#12 still not addressed all the issues mentioned in #8.

And there are many more deprecated methods are still present like as below.

I don't see any reason, why should we consider other deprecated function here.

Hardik_Patel_12’s picture

Status: Needs work » Needs review
FileSize
55.66 KB

Last patch failed to apply , kindly follow a new patch. Deprecation error is coming in core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php file is mainly because #3139440: Replace usages of deprecated AssertLegacyTrait::buildXPathQuery() , #3139431: Replace usages of AssertLegacyTrait::assertFieldsByValue, that is deprecated and #3139442: Replace usages of AssertLegacyTrait::constructFieldXpath, that is deprecated is not fixed yet.

Let's fix them first, it will automatically gone pass.

Status: Needs review » Needs work

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

jungle’s picture

Status: Needs work » Needs review
FileSize
56 KB
2.36 KB

Trying to fix #14

jungle’s picture

Two \Drupal\FunctionalTests\BrowserTestBaseTest::testFieldAssertsForCheckbox(), removed one of them.

mondrake’s picture

Status: Needs review » Needs work

Thanks.

  1. +++ b/core/modules/views_ui/tests/src/Functional/DisplayAttachmentTest.php
    @@ -39,7 +38,7 @@ public function testAttachmentUI() {
         foreach (['default', 'page-1'] as $display_id) {
    -      $this->assertNoFieldChecked("edit-displays-$display_id", new FormattableMarkup('Make sure the @display_id can be marked as attached', ['@display_id' => $display_id]));
    +      $this->assertSession()->checkboxNotChecked("edit-displays-$display_id");
         }
    

    It seems overkill to have this in a foreach loop. Better two straight individual calls?

  2. +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
    @@ -582,101 +582,15 @@ public function testFieldAssertsForButton() {
       /**
        * Tests legacy field asserts for checkbox field type.
    +   *
    +   * @group legacy
    +   * @expectedDeprecation AssertLegacyTrait::assertFieldChecked() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->checkboxChecked() instead. See https://www.drupal.org/node/3129738
    +   * @expectedDeprecation AssertLegacyTrait::assertNoFieldChecked() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->checkboxNotChecked() instead. See https://www.drupal.org/node/3129738
        */
       public function testFieldAssertsForCheckbox() {
         $this->drupalGet('test-field-xpath');
    -
    -    // Part 1 - Test by name.
    -    // Test that checkboxes are found/not found correctly by name, when using
    -    // TRUE or FALSE to match their 'checked' state.
    -    $this->assertFieldByName('checkbox_enabled', TRUE);
    -    $this->assertFieldByName('checkbox_disabled', FALSE);
    -    $this->assertNoFieldByName('checkbox_enabled', FALSE);
    -    $this->assertNoFieldByName('checkbox_disabled', TRUE);
    -
    -    // Test that checkboxes are found by name when using NULL to ignore the
    -    // 'checked' state.
    -    $this->assertFieldByName('checkbox_enabled', NULL);
    -    $this->assertFieldByName('checkbox_disabled', NULL);
    -
    -    // Test that checkboxes are found by name when passing no second parameter.
    -    $this->assertFieldByName('checkbox_enabled');
    -    $this->assertFieldByName('checkbox_disabled');
    -
    -    // Test that we have legacy support.
    -    $this->assertFieldByName('checkbox_enabled', '1');
    -    $this->assertFieldByName('checkbox_disabled', '');
    -
    -    // Test that the assertion fails correctly when using NULL to ignore state.
    -    try {
    -      $this->assertNoFieldByName('checkbox_enabled', NULL);
    -      $this->fail('The "checkbox_enabled" field was not found by name, using NULL value.');
    -    }
    -    catch (ExpectationException $e) {
    -      $this->pass('assertNoFieldByName failed correctly. The "checkbox_enabled" field was found using NULL value.');
    -    }
    -
    -    // Part 2 - Test by ID.
    -    // Test that checkboxes are found/not found correctly by ID, when using
    -    // TRUE or FALSE to match their 'checked' state.
    -    $this->assertFieldById('edit-checkbox-enabled', TRUE);
    -    $this->assertFieldById('edit-checkbox-disabled', FALSE);
    -    $this->assertNoFieldById('edit-checkbox-enabled', FALSE);
    -    $this->assertNoFieldById('edit-checkbox-disabled', TRUE);
    -
    -    // Test that checkboxes are found by ID, when using NULL to ignore the
    -    // 'checked' state.
    -    $this->assertFieldById('edit-checkbox-enabled', NULL);
    -    $this->assertFieldById('edit-checkbox-disabled', NULL);
    -
    -    // Test that checkboxes are found by ID when passing no second parameter.
    -    $this->assertFieldById('edit-checkbox-enabled');
    -    $this->assertFieldById('edit-checkbox-disabled');
    -
    -    // Test that we have legacy support.
    -    $this->assertFieldById('edit-checkbox-enabled', '1');
    -    $this->assertFieldById('edit-checkbox-disabled', '');
    -
    -    // Test that the assertion fails correctly when using NULL to ignore state.
    -    try {
    -      $this->assertNoFieldById('edit-checkbox-disabled', NULL);
    -      $this->fail('The "edit-checkbox-disabled" field was not found by ID, using NULL value.');
    -    }
    -    catch (ExpectationException $e) {
    -      $this->pass('assertNoFieldById failed correctly. The "edit-checkbox-disabled" field was found by ID using NULL value.');
    -    }
    -
    -    // Part 3 - Test the specific 'checked' assertions.
         $this->assertFieldChecked('edit-checkbox-enabled');
         $this->assertNoFieldChecked('edit-checkbox-disabled');
    -
    -    // Test that the assertion fails correctly with non-existent field id.
    -    try {
    -      $this->assertNoFieldChecked('incorrect_checkbox_id');
    -      $this->fail('The "incorrect_checkbox_id" field was found');
    -    }
    -    catch (ExpectationException $e) {
    -      $this->pass('assertNoFieldChecked correctly failed. The "incorrect_checkbox_id" field was not found.');
    -    }
    -
    -    // Test that the assertion fails correctly for a checkbox that is checked.
    -    try {
    -      $this->assertNoFieldChecked('edit-checkbox-enabled');
    -      $this->fail('The "edit-checkbox-enabled" field was not found in a checked state.');
    -    }
    -    catch (ExpectationException $e) {
    -      $this->pass('assertNoFieldChecked correctly failed. The "edit-checkbox-enabled" field was found in a checked state.');
    -    }
    -
    -    // Test that the assertion fails correctly for a checkbox that is not
    -    // checked.
    -    try {
    -      $this->assertFieldChecked('edit-checkbox-disabled');
    -      $this->fail('The "edit-checkbox-disabled" field was found and checked.');
    -    }
    -    catch (ExpectationException $e) {
    -      $this->pass('assertFieldChecked correctly failed. The "edit-checkbox-disabled" field was not found in a checked state.');
    -    }
       }
    

    Are not we losing test coverage here? Better leave the test as-is converting the calls, and add a separate deprecation test just for the unconverted calls.

mondrake’s picture

Also, the deprecation silencer in DeprecationListener is not removed.

jungle’s picture

Thanks for reviewing @mondrake!

Re #18.2 yes, that's why two \Drupal\FunctionalTests\BrowserTestBaseTest::testFieldAssertsForCheckbox() in #16 by mistake. But later, i thought as the test is covering legacy ones, so removed it in #17. well, i will add it back.

Agree with #18.1

mondrake’s picture

@jungle #18.2 actually I did not check if there is other test coverage for that, but now I see that the docblock says 'Tests legacy field asserts for checkbox field type.'. If we're not losing coverage of other methods, that'd be fine I guess.

jungle’s picture

Status: Needs work » Needs review
FileSize
58.41 KB
8.74 KB

Re #21. Addressing #18, #19. Reverted the removal.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!

mondrake’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll
ridhimaabrol24’s picture

Status: Needs work » Needs review
FileSize
58.55 KB

Rerolling patch for the latest head for 9.1.x

Status: Needs review » Needs work

The last submitted patch, 25: 3139428-25.patch, failed testing. View results

mondrake’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll
FileSize
58.41 KB
6.18 KB

Reroll of #22. #25 is likely a random failure, but I rerolled from last green patch.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 09c6b3d and pushed to 9.1.x. Thanks!

There's already a few conflicts on 9.0.x so backporting this problem is not worth it.

  • alexpott committed 09c6b3d on 9.1.x
    Issue #3139428 by jungle, ridhimaabrol24, Hardik_Patel_12, mondrake,...

Status: Fixed » Closed (fixed)

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