Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Lendude created an issue. See original summary.

ApacheEx’s picture

Issue tags: +LutskGCW19
nnevill’s picture

nnevill’s picture

Status: Active » Needs review
Lendude’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

@nnevill nice!

We should add a test for this to \Drupal\FunctionalTests\BrowserTestBaseTest I think, one scenario that passes and more importantly one that fails, so we have conformation that this actually detects duplicate IDs.

ApacheEx’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
4.41 KB
8.38 KB

@nnevill if you don't mind I'll help you with #5

1) I guess we don't need to check if there are any HTML IDs here assertNoDuplicateIds. So, I removed this check (like in KernelTests)
2) I've added tests (positon + negative) for assertNoDuplicateIds.

Lendude’s picture

Status: Needs review » Reviewed & tested by the community

@ApacheEx thanks as always!

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

@Lendude should this not go in \Drupal\Tests\WebAssert? And be accessed in tests via $this->assertSession()-> assertNoDuplicateIds() - maybe the method name needs to change.

Lendude’s picture

@alexpott yeah that makes sense! Moved it and renamed it.

ApacheEx’s picture

Status: Needs review » Reviewed & tested by the community

This is even better version.
Looks good to me. All remarks were addressed.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
    @@ -8,6 +8,7 @@
    +use PHPUnit\Framework\AssertionFailedError;
    
    +++ b/core/tests/Drupal/Tests/BrowserTestBase.php
    @@ -7,6 +7,7 @@
    +use Drupal\Component\Render\FormattableMarkup;
    

    Unused.

  2. +++ b/core/tests/Drupal/Tests/WebAssert.php
    @@ -597,4 +597,26 @@ public function pageTextContainsOnce($text) {
    +        throw new ExpectationException($message, $this->session->getDriver());
    

    Let's use sprintf() to add the ID to the message.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

saurabh.tripathi.cs’s picture

FileSize
778 bytes

If. Allow tests to compare MarkupInterface objects via assertEquals() has already been taken care of in 9.x than adding patch only for point mentioned in: #11

saurabh.tripathi.cs’s picture

Status: Needs work » Needs review
FileSize
46.05 KB

If we need a patch that has both changes. of. earlier patch #6 and #11 Use, this. patch.

Status: Needs review » Needs work

The last submitted patch, 16: addsprintf-3000762-16.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Hardik_Patel_12’s picture

Status: Needs work » Needs review
FileSize
45.82 KB
725 bytes

Solving failed test cases. Kindly review a new patch.

Lendude’s picture

Status: Needs review » Needs work

Massive amount of unrelated changes introduced in #16 lets remove all those please.

Hardik_Patel_12’s picture

Status: Needs work » Needs review
FileSize
9.1 KB

Removing unrelated changes introduced in #16 , and creating patch that has both changes as mentioned at #9 and #11. Kindly review new patch.

Krzysztof Domański’s picture

1. I added a Change Record. The pageContainsNoDuplicateId assert was added to WebAssert.

2. Addressed #11.2 and added a test for it.

-        throw new ExpectationException(sprintf($message), $this->session->getDriver());
+        throw new ExpectationException(sprintf('The page contains a duplicate HTML ID "%s".', $id), $this->session->getDriver());

+ $this->expectExceptionMessage('The page contains a duplicate HTML ID "page-element".');

3. I removed an unnecessary assert. It does nothing.
- $this->assert(TRUE, $message);

Status: Needs review » Needs work

The last submitted patch, 21: 3000762-21.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Krzysztof Domański’s picture

Status: Needs work » Needs review

Unrelated random test failure.

Status: Needs review » Needs work

The last submitted patch, 21: 3000762-21.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Krzysztof Domański’s picture

Status: Needs work » Needs review
FileSize
1.43 KB
8.99 KB

Fixed coding standards.

Hardik_Patel_12’s picture

Status: Needs review » Reviewed & tested by the community

I think all unrelated changes introduced in #16 is removed now , and rename from testAssertNoDuplicateIds to testPageContainsNoDuplicateId make sense also coding standards is proper now . So moving to RTBC.

Krzysztof Domański’s picture

Krzysztof Domański’s picture

There will be two the same asserts, but with a different name, assertNoDuplicateIds for kernel and pageContainsNoDuplicateId for functional... They should be standardized.

https://git.drupalcode.org/project/drupal/-/blob/9.0.x/core/tests/Drupal...
protected function assertNoDuplicateIds($message = '', $group = 'Other', $ids_to_skip = []) {

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 3c4c7a4 and pushed to 9.1.x. Thanks!

  • catch committed efc85b5 on 9.1.x
    Issue #3000762 by Krzysztof Domański, Hardik_Patel_12, saurabh.tripathi....
catch’s picture

Not moving to 8.9/9.0 for backport. This is nice to have, but the patch doesn't result in a lot of test divergence so I think it's fine to just add it in 9.1.x

Krzysztof Domański’s picture

Backport to 8.9/9.0 is not necessary, but it is helpful for another issue. See #2894747-37: Views hardcodes exposed filter block form ID's which breaks AJAX when the same form is shown multiple times on one page. Instead of adding another method to core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php, we could use the new method from WebAssert.

Status: Fixed » Closed (fixed)

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