Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
AssertLegacyTrait::assertNoText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseNotContains() or $this->assertSession()->pageTextNotContains() instead. See https://www.drupal.org/node/3129738
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|
Issue fork drupal-3191935
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3191935-9.2.x changes, plain diff MR !981
- 3191935-replace-usages-of changes, plain diff MR !697
Comments
Comment #2
mondrakeComment #3
mondrakeComment #5
mondrakeWorking on this.
Comment #7
mondrakeFirst batch of conversions
Comment #8
mondrakeUh, I'm afraid the failures are hitting #3175718: Random fails due to drupal-settings-json being counted as page text.
Comment #9
mondrakeComment #10
mondrakeBorrowed some of #3175718-21: Random fails due to drupal-settings-json being counted as page text.
Comment #11
mondrakeBlocked by #3175718: Random fails due to drupal-settings-json being counted as page text
Comment #12
alexpottThis problem is being caused by case sensitivity and not [3175718].
\Drupal\FunctionalTests\AssertLegacyTrait::assertNoText()
is case sensitive - it uses\PHPUnit\Framework\Assert::assertStringNotContainsString()
. The replacement code eventually uses\Behat\Mink\WebAssert::elementTextNotContains
which does$regex = '/'.preg_quote($text, '/').'/ui';
and then$this->assertElementText(!preg_match($regex, $actual), $message, $element);
It's true that [3175718] does help because it removes words you would not expect to be there and I also think that doing a case insensitive check is a good idea because asserting for missing text is fraught enough without having to worry about that.
Comment #13
mondrakeA patch combined with #3175718: Random fails due to drupal-settings-json being counted as page text.
Comment #14
alexpottYou need to revert this change.
Comment #15
mondrakeAh, yes, thx
Comment #16
mondrakeRerolled
Comment #17
mondrakeComment #18
mondrakeThe remaining ones after #3175718: Random fails due to drupal-settings-json being counted as page text are hard, because we have false positives coming from case insensivity. We need to change to more accurate checks on page elements, taking care to convert also corresponding
pageTextContains()
calls when the tests are checking first non presence and then presence (or vice versa). On this.Comment #19
mondrakeReady for review. Please note as per #18, some conversions required more elaborate refactoring due to false positives.
Comment #20
longwaveThis all looks OK to me. I read through the entire patch, the conversions are mostly 1:1 and the ones that are not appear to make sense in that they are now looking for more specific elements to avoid false positives.
Comment #21
xjmComment #22
xjmReviewed locally with
git diff --color-words
. Overall, the changes make sense. For the few cases that were not exactly a 1:1 replacement, my main concern is that using negative assertions tied to specific xpaths of page markup is pretty fragile -- we could easily get false passes if the page markup or theming is changed. It would be better to find a different way to fix those assertions, and I'd suggest splitting those tests into their own blocking issue that this could be postponed on. In particular:FieldUIDeleteTest
andUserAdminTest
pair negative and positive xpath assertions related to page markup, either as a before/after or including some things but not other things with a given markup pattern, so those might be okay.UpdateContribTest
only has a negative assertion based on specific page markup. This is a concern because the test could have a false pass if the markup or theme changes. Can we do this a different way?ExposedFormTest
only has a negative assertion, so I don't think an xpath assertion is the right choice here for the same reasons as above.As for the other things that are not the 1:1 replacement:
CommentRestExportTest
asserts that the response does not contain the text, which makes sense given that it's a REST test.LocaleTranslationUiTest
make sense.Finally, there are a few tests that still have
assertNoText()
following this patch, so they probably need to be addressed as well:I think this is really close -- just would like a smaller first step to potentially solve the negative xpath assertions a different way, and address the remaining usages.
Thanks!
Comment #23
mondrake#22
Note they're all Kernel tests that cannot be converted to WebAssert, this issue applies only to Functional and FunctionalJavascript ones.
Comment #24
xjmRe: #23 -- Aha, thanks for clarifying. Are there separate plans to deal with the kernel tests?
Comment #25
mondrake#24: see #3027952-50: [Plan] Remove the usage of deprecated methods in tests and #3129006: Modernize Drupal\KernelTests\AssertContentTrait
Comment #27
tedbowI addressed #22 2,3
Comment #28
xjmNW for recent feedback.
Comment #29
mondrakeOn this
Comment #30
mondrakeAddressed @phenaproxima's input.
Comment #31
longwaveAll feedback was addressed, changes look correct to me.
Comment #32
catchNeeds a re-roll.
Comment #33
mondrakeRerolled.
Comment #34
catchCommitted 068f00c and pushed to 9.3.x. Thanks!
Comment #36
catchWe should backport this to 9.2.x to keep other patches in sync.
Comment #37
paulocsOn it.
Comment #39
paulocsPlease review.
Comment #41
longwaveNeeds another reroll.
Comment #43
ankithashettyComment #44
longwaveThe MR looks perfect to me - thanks!
Comment #46
catchCommitted/pushed to 9.2.x, thanks!
Comment #47
mondrake