Problem/Motivation

From #3129002: Replace usages of deprecated AssertLegacyTrait::assert():

In cases of constructs like

    $view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'aggregator/sources/']);
    $this->assert(isset($view_link), 'The message area contains a link to a feed');

we are in fact failing to test appropriately: $this->xpath returns an empty array here, since the xpath selector is //div[@class="messages"] and in fact since the test was written the class changed to 'messages-list'. But an empty array is set as a variable, so the test passes anyway. I corrected by changing the selector to //div[@data-drupal-messages], and using the WebAssert::elementExists method.

Steps to reproduce

Proposed resolution

Review tests that use $this->xpath() and then an assertion using isset to ensure they are testing what they are meant to test.

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

Title: Review xpath based assertions for false negatives » [meta] Review xpath based assertions for false negatives

Switching to meta since this will likely need multiple issues.

andypost’s picture

Maybe that's remains/leftovers from css-select conversion?

mondrake’s picture

The POC #3168788: Convert assertions involving use of xpath to WebAssert, aggregator module was committed with the comment

I'm not sure about scope here. I think maybe this is an exception to the by-module rule. Not sure. Anyhow - this is way cleaner with these changes.

which may not be a blessing to move on with module-specific issues, but at least is an encouragement in that sense :)

mondrake’s picture

Issue summary: View changes
mondrake’s picture

Issue summary: View changes
mondrake’s picture

Issue summary: View changes
mondrake’s picture

Issue summary: View changes
mondrake’s picture

Issue summary: View changes
mondrake’s picture

Issue summary: View changes
mondrake’s picture

Issue summary: View changes
mondrake’s picture

Issue summary: View changes
mondrake’s picture

Issue summary: View changes
mondrake’s picture

Title: [meta] Review xpath based assertions for false negatives » [meta] Convert assertions involving use of xpath to WebAssert, where possible
mondrake’s picture

Issue summary: View changes
mondrake’s picture

Issue summary: View changes
paulocs’s picture

Issue summary: View changes
mondrake’s picture

Issue summary: View changes
xjm’s picture

I don't think #3168788: Convert assertions involving use of xpath to WebAssert, aggregator module should have been committed with a per-module scope (and therefore am not comfortable committing all the other issues scoped this way). As per: https://www.drupal.org/docs/develop/issues/issue-procedures-and-etiquett...

Can we rethink how these are scoped, please, instead of having the overhead of a bunch of little 5K patches? What is the motivation for doing this per module?

xjm’s picture

I've postponed the child issues pending a discussion and decision around #19. While these can be more difficult than your typical find-and-replace, it's still a lot of overhead to have so many issues in the 2-5K patch range. Are there patters we can establish? Etc.

longwave’s picture

@mondrake and I have discussed this both in Slack and in #3168788: Convert assertions involving use of xpath to WebAssert, aggregator module. We are open to suggestions for improved scoping but the problem is that this one isn't just a find-and-replace job like many of these PHPUnit improvement metas have been. There doesn't seem to be any obvious way to group them otherwise; each individual case needs careful checking to ensure it's actually testing what it is intended to test, and so smaller patches make this easier to both write and review.

mondrake’s picture

#21++

I would also say that the approach per module allows participation by many more contributors, and with different levels of experience, since there will be issues with different levels of complexity.

The alternative of a monster patch is practically unmanageable because of size, needs of rerolls, etc.

longwave’s picture

One other option is to go down the route of the unused variable removals and have one issue for each affected line (or perhaps test method) but that seems even more work for core committers than by-module.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

longwave’s picture

Opened #3184632: Convert assertions involving use of xpath on submit inputs to WebAssert to try scoping these in a different way. I suggest to anyone following this issue to refrain from opening similar issues just yet, in case this approach is not accepted either.

longwave’s picture

Encouraged by the acceptance of the previous issue I've identified and opened #3187309: Convert assertions involving use of xpath on select and option elements to WebAssert for the next batch of these.

longwave’s picture

mondrake’s picture

Issue summary: View changes

Closed all open issues of the now abandoned per-module approach,

mondrake’s picture

Issue summary: View changes
mondrake’s picture

Issue summary: View changes
mondrake’s picture

Issue summary: View changes
mondrake’s picture

Issue summary: View changes
longwave’s picture

mondrake’s picture

mondrake’s picture

Issue summary: View changes

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mondrake’s picture

Issue summary: View changes

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mondrake’s picture

Priority: Major » Normal

#3253715: Replace assertions involving calls to isset() on xpath results in functional tests with WebAssert calls landed, and I think now we can try to address the remaining cases in a single patch. Do we change this from a meta to a concrete issue, or open a new one child of this?

mondrake’s picture

Version: 9.4.x-dev » 10.0.x-dev
mondrake’s picture

Status: Active » Needs review
FileSize
35.39 KB

A few conversions.

mondrake’s picture

FileSize
55.14 KB
20.39 KB
mondrake’s picture

FileSize
2.54 KB
55.88 KB

Status: Needs review » Needs work

The last submitted patch, 43: 3167880-43.patch, failed testing. View results

mondrake’s picture

Status: Needs work » Active
mondrake’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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