Problem/Motivation

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

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

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

munish.kumar’s picture

Assigned: Unassigned » munish.kumar
munish.kumar’s picture

Assigned: munish.kumar » Unassigned
Status: Active » Needs review
StatusFileSize
new5.43 KB

Status: Needs review » Needs work

The last submitted patch, 4: 3139442-4.patch, failed testing. View results

munish.kumar’s picture

Assigned: Unassigned » munish.kumar
munish.kumar’s picture

StatusFileSize
new5.87 KB
munish.kumar’s picture

Status: Needs work » Needs review
munish.kumar’s picture

Assigned: munish.kumar » Unassigned
mohrerao’s picture

Status: Needs review » Reviewed & tested by the community

Verified for presence of constructFieldXpath with grep -r "constructFieldXpath(" *
only core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php, core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php and core/tests/Drupal/KernelTests/AssertContentTrait.php show up.

kiran.rao@Srijans-MBP drupal % grep -r "constructFieldXpath(" *
core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php:    $this->assertFieldByXPath($this->constructFieldXpath('name', $name), $value);
core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php:    $this->assertNoFieldByXPath($this->constructFieldXpath('name', $name), $value);
core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php:    $this->assertFieldByXPath($this->constructFieldXpath('id', $id), $value);
core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php:    $this->assertFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field));
core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php:    $this->assertNoFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field));
core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php:    $this->assertNoFieldByXPath($this->constructFieldXpath('id', $id), $value);
core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php:  protected function constructFieldXpath($attribute, $value) {
core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php:    @trigger_error('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', E_USER_DEPRECATED);
core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php:      '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',
core/tests/Drupal/KernelTests/AssertContentTrait.php:    return $this->assertFieldByXPath($this->constructFieldXpath('name', $name), $value, $message, $group);
core/tests/Drupal/KernelTests/AssertContentTrait.php:    return $this->assertNoFieldByXPath($this->constructFieldXpath('name', $name), $value, $message ? $message : new FormattableMarkup('Did not find field by name @name', ['@name' => $name]), $group);
core/tests/Drupal/KernelTests/AssertContentTrait.php:    return $this->assertFieldByXPath($this->constructFieldXpath('id', $id), $value, $message ? $message : new FormattableMarkup('Found field by id @id', ['@id' => $id]), $group);
core/tests/Drupal/KernelTests/AssertContentTrait.php:    return $this->assertNoFieldByXPath($this->constructFieldXpath('id', $id), $value, $message ? $message : new FormattableMarkup('Did not find field by id @id', ['@id' => $id]), $group);
core/tests/Drupal/KernelTests/AssertContentTrait.php:    return $this->assertFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field), NULL, $message, $group);
core/tests/Drupal/KernelTests/AssertContentTrait.php:    return $this->assertNoFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field), NULL, $message, $group);
core/tests/Drupal/KernelTests/AssertContentTrait.php:  protected function constructFieldXpath($attribute, $value) {

Moving to RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Once we're removed all the usages we can add an @trigger_error to the method. See \Drupal\FunctionalTests\AssertLegacyTrait::getAllOptions() for an example of how to do that.

munish.kumar’s picture

Status: Needs work » Needs review

Hi @alexpott, Thanks for the review. Correct me if I am wrong, but I found @trigger_error is already there in the method in core/tests/Drupal/FunctionalTests/AssertLegacyTrait . see here.

protected function constructFieldXpath($attribute, $value) {
    @trigger_error('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', E_USER_DEPRECATED);
    $xpath = '//textarea[@' . $attribute . '=:value]|//input[@' . $attribute . '=:value]|//select[@' . $attribute . '=:value]';
    return $this->buildXPathQuery($xpath, [':value' => $value]);
  }
hardik_patel_12’s picture

StatusFileSize
new7.08 KB
new1.06 KB

Hi @alexpott, @trigger_error message is already there in core/tests/Drupal/FunctionalTests/AssertLegacyTrait as mentioned by @munish.kumar also. Deleting deprecation message from the core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php file also. Kindly review a new patch.

Status: Needs review » Needs work

The last submitted patch, 13: 3139442-13.patch, failed testing. View results

mohrerao’s picture

Status: Needs work » Needs review

The failures are because of usage of AssertLegacyTrait::constructFieldXpath internally by other AssertLegacyTrait methods. This should pass once Remove the usage of deprecated methods in tests lands.

mondrake’s picture

Status: Needs review » Needs work
mondrake’s picture

Status: Needs work » Postponed

Actually, postponed based on #15.

mondrake’s picture

Status: Postponed » Needs review
StatusFileSize
new11.23 KB
new12.47 KB

Added deprecation test. We need to start unravel the dependencies between the file related assert methods and this seems a good starting point.

mondrake’s picture

StatusFileSize
new12.47 KB
new11.24 KB

Sorry.

Status: Needs review » Needs work

The last submitted patch, 19: 3139442-19.patch, failed testing. View results

mondrake’s picture

StatusFileSize
new890 bytes
new12.57 KB

Fixing failure of the deprecation test.

mondrake’s picture

Status: Needs work » Needs review
mondrake’s picture

StatusFileSize
new871 bytes
new12.81 KB
jungle’s picture

Status: Needs review » Reviewed & tested by the community

@mondrake, thanks!

  1. $ git grep constructFieldXpath | grep -v AssertContentTrait
    core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php:  protected function constructFieldXpath($attribute, $value) {
    core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php:    @trigger_error('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', E_USER_DEPRECATED);
    core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php:   * @covers ::constructFieldXpath
    core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php:   * @expectedDeprecation 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
    core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php:    $this->assertSame('qux', $this->constructFieldXpath('foo', ['bar']));
    
    $ git grep constructFieldXpath | grep -v AssertContentTrait | grep -v AssertLegacyTrait
    [No output]
    

    All occurrences of AssertLegacyTrait::constructFieldXpath() were replaced.

  2. +++ b/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php
    @@ -224,6 +225,18 @@ public function testPass() {
    +   * @covers ::constructFieldXpath
    +   * @expectedDeprecation 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
    ...
    +  public function testConstructFieldXpath() {
    

    The legacy/deprecated one gets tested.

  3. +++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
    @@ -142,7 +142,6 @@ public static function getSkippedDeprecations() {
    -      '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',
    

    The deprecated message gets removed from getSkippedDeprecations()

  4. +++ b/core/modules/comment/tests/src/Functional/Views/WizardTest.php
    @@ -61,17 +61,13 @@ public function testCommentWizard() {
    +    $actual_options = [];
    +    foreach ($items as $item) {
    +      $actual_options[] = $item->getValue();
    +    }
    +    $this->assertEquals($expected_options, $actual_options);
    

    Prefer using array_map

     $this->assertEquals($expected_options, array_map(function ($item) {
          return $item->getValue();
        }, $items));
    

    But it does not matter here.

  5. No CS violations

In all, it's RTBC to me.

jungle’s picture

Actually, the check in #24.1 is unnecessary, if there are leftovers, the testing won't pass once the deprecation message gets removed from getSkippedDeprecations().

  • catch committed c532b2f on 9.1.x
    Issue #3139442 by mondrake, munish.kumar, Hardik_Patel_12, jungle,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed c532b2f and pushed to 9.1.x. Thanks!

Status: Fixed » Closed (fixed)

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