By mondrake on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
9.1.x
Introduced in version:
9.1.0
Issue links:
Description:
The following test assertion methods, originally inherited in Drupal 8 from Simpletest, have been replaced by PHPUnit methods along the Drupal 8 lifecycle, and are now formally deprecated for removal in Drupal 10.
Developers are advised to convert their tests to replace usages of these methods to their recommended alternatives.
| Deprecated method | Replacement |
|---|---|
| assert() | $this->assertTrue() |
| assertEqual() | $this->assertEquals() |
| assertNotEqual() | $this->assertNotEquals() |
| assertIdentical() | $this->assertSame() |
| assertNotIdentical() | $this->assertNotSame() |
| assertIdenticalObject() | $this->assertEquals() |
| pass() | n/a - drop the call and/or refactor the test. PHPUnit fails a test as soon as an assertion fails. |
| assertElementPresent() | $this->assertSession()->elementExists() |
| assertElementNotPresent() | $this->assertSession()->elementNotExists() |
| assertText() | $this->assertSession()->responseContains() or $this->assertSession()->pageTextContains() |
| assertNoText() | $this->assertSession()->responseNotContains() or $this->assertSession()->pageTextNotContains() |
| assertUniqueText() | $this->getSession()->pageTextContainsOnce() or $this->getSession()->pageTextMatchesCount() |
| assertNoUniqueText() | $this->getSession()->pageTextMatchesCount() if you know the cardinality in advance, or $this->getSession()->getPage()->getText() and substr_count() |
| assertResponse() | $this->assertSession()->statusCodeEquals() |
| assertFieldByName() | $this->assertSession()->fieldExists() or $this->assertSession()->buttonExists() or $this->assertSession()->fieldValueEquals() |
| assertNoFieldByName() | $this->assertSession()->fieldNotExists() or $this->assertSession()->buttonNotExists() or $this->assertSession()->fieldValueNotEquals() |
| assertFieldById() | $this->assertSession()->fieldExists() or $this->assertSession()->buttonExists() or $this->assertSession()->fieldValueEquals() |
| assertField() | $this->assertSession()->fieldExists() or $this->assertSession()->buttonExists() |
| assertNoField() | $this->assertSession()->fieldNotExists() or $this->assertSession()->buttonNotExists() |
| assertRaw() | $this->assertSession()->responseContains() |
| assertNoRaw() | $this->assertSession()->responseNotContains() |
| assertTitle() | $this->assertSession()->titleEquals() |
| assertLink() | $this->assertSession()->linkExists() |
| assertNoLink() | $this->assertSession()->linkNotExists() |
| assertLinkByHref() | $this->assertSession()->linkByHrefExists() |
| assertNoLinkByHref() | $this->assertSession()->linkByHrefNotExists() |
| assertNoFieldById() | $this->assertSession()->fieldNotExists() or $this->assertSession()->buttonNotExists() or $this->assertSession()->fieldValueNotEquals() |
| assertUrl() | $this->assertSession()->addressEquals() |
| assertOption() | $this->assertSession()->optionExists() |
| assertOptionByText() | $this->assertSession()->optionExists() |
| assertNoOption() | $this->assertSession()->optionNotExists() |
| assertOptionSelected() | $this->assertSession()->optionExists() instead and check the "selected" attribute |
| assertFieldChecked() | $this->assertSession()->checkboxChecked() |
| assertNoFieldChecked() | $this->assertSession()->checkboxNotChecked() |
| assertFieldByXPath() | $this->xpath() instead and check the values directly in the test |
| assertNoFieldByXPath() | $this->xpath() instead and assert that the result is empty |
| assertFieldsByValue() | Iterate over the fields yourself instead and directly check the values in the test |
| assertEscaped() | $this->assertSession()->assertEscaped() |
| assertNoEscaped() | $this->assertSession()->assertNoEscaped() |
| assertPattern() | $this->assertSession()->responseMatches() |
| assertNoPattern() | $this->assertSession()->responseNotMatches() |
| assertCacheTag() | $this->assertSession()->responseHeaderContains() |
| assertNoCacheTag() | $this->assertSession()->responseHeaderNotContains() |
| assertHeader() | $this->assertSession()->responseHeaderEquals() |
| buildXPathQuery() | $this->assertSession()->buildXPathQuery() |
| constructFieldXpath() | $this->getSession()->getPage()->findField() |
| getRawContent() | $this->getSession()->getPage()->getContent() |
| getAllOptions() | $element->findAll('xpath', 'option') |
Impacts:
Module developers
Comments
Thanks for posting this CR
Thanks for posting this CR @mondrake. Should this line be removed?
assertText() | $this->assertSession()->pageTextContains() or $this->assertSession()->pageTextNotContains()Yes! Done, thanks.
Yes! Done, thanks.
Cool, thanks!
Cool, thanks!