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

Assigned: Unassigned » jungle

On this.

jungle’s picture

Status: Active » Needs review
FileSize
148.71 KB
mondrake’s picture

Status: Needs review » Needs work
jungle’s picture

Status: Needs work » Needs review
FileSize
148.71 KB
729 bytes

Thanks @mondrake!

Status: Needs review » Needs work

The last submitted patch, 6: 3139418-6.patch, failed testing. View results

jungle’s picture

1) Drupal\Tests\field\Kernel\String\StringFormatterTest::testStringFormatter
Error: Call to undefined method Drupal\Tests\field\Kernel\String\StringFormatterTest::assertSession()

One error is from calls replaced to \Drupal\KernelTests\AssertContentTrait::assertLinkByHref()

Worthy a new issue to continue.

jungle’s picture

mondrake’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests
FileSize
3.36 KB
145.35 KB

Rerolled, removed changes to Kernel tests not relevant here, removed the BrowserTestBaseTest deprecation test - we will need a specific one instead.

mondrake’s picture

Rerolled and added new deprecation tests.

jungle’s picture

Status: Needs review » Needs work

Patch failed to apply :)

mondrake’s picture

Status: Needs work » Needs review
FileSize
146.47 KB
jungle’s picture

  1. $ git grep assertLinkByHref\(
    core/modules/field/tests/src/Kernel/String/StringFormatterTest.php:    $this->assertLinkByHref($entity->toUrl()->toString());
    core/modules/field/tests/src/Kernel/String/StringFormatterTest.php:    $this->assertLinkByHref($entity->toUrl('revision')->toString());
    core/modules/field/tests/src/Kernel/String/StringFormatterTest.php:    $this->assertLinkByHref($entity->toUrl('revision')->toString());
    core/modules/field/tests/src/Kernel/String/StringFormatterTest.php:    $this->assertLinkByHref('/entity_test_rev/' . $entity_new_revision->id() . '/revision/' . $entity_new_revision->getRevisionId() . '/view');
    core/modules/field/tests/src/Kernel/String/StringFormatterTest.php:    $this->assertLinkByHref($entity->toUrl('canonical')->toString());
    core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php:  protected function assertLinkByHref($href, $index = 0) {
    core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php:    @trigger_error('AssertLegacyTrait::assertLinkByHref() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->linkByHrefExists() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED);
    core/tests/Drupal/KernelTests/AssertContentTrait.php:  protected function assertLinkByHref($href, $index = 0, $message = '', $group = 'Other') {
    core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php:   * @expectedDeprecation AssertLegacyTrait::assertLinkByHref() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->linkByHrefExists() instead. See https://www.drupal.org/node/3129738
    core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php:    $this->assertLinkByHref('boo', 0);
    
    
    $ git grep assertLinkByHref\( | grep -v StringFormatterTest | grep -v AssertLegacyTrait | grep -v AssertContentTrait
    

    All occurrences were replaced

  2. +++ b/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php
    @@ -236,6 +236,30 @@ public function testPass() {
    +   * @covers ::assertLinkByHref
    +   * @expectedDeprecation AssertLegacyTrait::assertLinkByHref() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->linkByHrefExists() instead. See https://www.drupal.org/node/3129738
    ...
    +  public function testAssertLinkByHref() {
    ...
    +   * @covers ::assertNoLinkByHref
    +   * @expectedDeprecation AssertLegacyTrait::assertNoLinkByHref() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->linkByHrefNotExists() instead. See https://www.drupal.org/node/3129738
    ...
    +  public function testAssertNoLinkByHref() {
    

    The two deprecated ones get tested.

  3. +++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
    @@ -135,8 +135,6 @@ public static function getSkippedDeprecations() {
    -      'AssertLegacyTrait::assertLinkByHref() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->linkByHrefExists() instead. See https://www.drupal.org/node/3129738',
    -      'AssertLegacyTrait::assertNoLinkByHref() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->linkByHrefNotExists() instead. See https://www.drupal.org/node/3129738',
    

    Deprecation messages removed from getSkippedDeprecations().

If no CS violations and testing passes, this is RTBC to me. Cycling back later.

jungle’s picture

Hi @mondrake, why you aborted the CI runs? On purpose or by mistake? Aborting one of them makes sense to me, but both the MySQL one and the SQLite one got aborted. Re-queued.

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

jungle’s picture

It took about 110 mins. Aborted by CI itself?

mondrake’s picture

#16 yes DrupalCI gets stuck with this patch, during the Unit tests run. No idea why.

mondrake’s picture

Rerolled patch from #10 that was passing last. Rawdiff from #13 so we can see what else was added there that is blocking DrupalCI.

mondrake’s picture

So the deprecation test added in #11 is probably the culprit, I can’t understand why though.

mondrake’s picture

+++ b/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php
@@ -236,6 +236,30 @@ public function testPass() {
+  public function testAssertNoLinkByHref() {
+    $this->webAssert
+      ->linkByHrefNotExists('boo')
+      ->shouldBeCalled();
+
+    $this->testAssertNoLinkByHref('boo');
+  }

The problem was the test method calling itself and recursing endlessly. Strange that DrupalCI does not fail.

Fixed here.

longwave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests
Related issues: +#2031223: Add linkByHrefExistsExact and linkByHrefNotExistsExact for matching links by href exactly

Tests were added, so removing tag.

All BrowserTestBase calls to assert[No]LinkByHref() were removed so this is RTBC.

When grepping for calls I found an interesting reference in core/modules/contact/tests/src/Functional/ContactSitewideTest.php:

    // User form could not be changed or deleted.
    // Cannot use ::assertNoLinkByHref as it does partial url matching and with
    // field_ui enabled admin/structure/contact/manage/personal/fields exists.
    // @todo: See https://www.drupal.org/node/2031223 for the above.
    $edit_link = $this->xpath('//a[@href=:href]', [
      ':href' => Url::fromRoute('entity.contact_form.edit_form', ['contact_form' => 'personal'])->toString(),
    ]);
    $this->assertTrue(empty($edit_link), new FormattableMarkup('No link containing href %href found.',
      ['%href' => 'admin/structure/contact/manage/personal']
    ));

This is still true in WebAssert as it builds an XPath query //a[contains(@href, :href)]. This is out of scope to fix completely here but should we update the comment? Also getting this on @mondrake's radar as exact URL matching is something we have improved elsewhere recently.

mondrake’s picture

Rerolled.

mondrake’s picture

Assigned: jungle » Unassigned
Status: Reviewed & tested by the community » Needs work
mondrake’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
146.68 KB
492 bytes

Wrong reroll in #22.

mondrake’s picture

...and in #24, too.

mondrake’s picture

FileSize
146.89 KB

... and needing a reroll already

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 472b190 and pushed to 9.1.x. Thanks!

  • alexpott committed 472b190 on 9.1.x
    Issue #3139418 by mondrake, jungle, longwave: Replace usages of...

Status: Fixed » Closed (fixed)

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