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.
follow up for #2809535: Convert AJAX part of \Drupal\system\Tests\Ajax\MultiFormTest to JavascriptTestBase
There is a version of assertNoDuplicateIds
on AssertContentTrait but this is meant for Kernel tests. We need a version to use for functional tests.
The version here \Drupal\Tests\file\Functional\FileFieldDisplayTest::assertNoDuplicateIds
might be a good start.
Existing implementations should then use the method on the trait
Comment | File | Size | Author |
---|---|---|---|
#25 | 3000762-25.patch | 8.99 KB | Krzysztof Domański |
#25 | interdiff-21-25.txt | 1.43 KB | Krzysztof Domański |
#21 | 3000762-21.patch | 9.03 KB | Krzysztof Domański |
#21 | interdiff-20-21.txt | 2.34 KB | Krzysztof Domański |
#20 | 3000762-20.patch | 9.1 KB | Hardik_Patel_12 |
Comments
Comment #2
ApacheEx CreditAttribution: ApacheEx commentedComment #3
nnevillComment #4
nnevillComment #5
Lendude@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.Comment #6
ApacheEx CreditAttribution: ApacheEx at Drupal Ukraine Community commented@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
.Comment #7
Lendude@ApacheEx thanks as always!
Comment #8
alexpott@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.
Comment #9
Lendude@alexpott yeah that makes sense! Moved it and renamed it.
Comment #10
ApacheEx CreditAttribution: ApacheEx at Drupal Ukraine Community commentedThis is even better version.
Looks good to me. All remarks were addressed.
Comment #11
alexpottUnused.
Let's use sprintf() to add the ID to the message.
Comment #15
saurabh.tripathi.cs CreditAttribution: saurabh.tripathi.cs as a volunteer and at Acquia for Acquia commentedIf. 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
Comment #16
saurabh.tripathi.cs CreditAttribution: saurabh.tripathi.cs as a volunteer and at Acquia for Acquia commentedIf we need a patch that has both changes. of. earlier patch #6 and #11 Use, this. patch.
Comment #18
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 commentedSolving failed test cases. Kindly review a new patch.
Comment #19
LendudeMassive amount of unrelated changes introduced in #16 lets remove all those please.
Comment #20
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 commentedRemoving unrelated changes introduced in #16 , and creating patch that has both changes as mentioned at #9 and #11. Kindly review new patch.
Comment #21
Krzysztof Domański1. I added a Change Record. The pageContainsNoDuplicateId assert was added to WebAssert.
2. Addressed #11.2 and added a test for it.
+ $this->expectExceptionMessage('The page contains a duplicate HTML ID "page-element".');
3. I removed an unnecessary assert. It does nothing.
- $this->assert(TRUE, $message);
Comment #23
Krzysztof DomańskiUnrelated random test failure.
Comment #25
Krzysztof DomańskiFixed coding standards.
Comment #26
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 commentedI 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.
Comment #27
Krzysztof DomańskiComment #28
Krzysztof DomańskiThere will be two the same asserts, but with a different name,
assertNoDuplicateIds
for kernel andpageContainsNoDuplicateId
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 = []) {
Comment #29
catchCommitted 3c4c7a4 and pushed to 9.1.x. Thanks!
Comment #31
catchNot 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
Comment #32
Krzysztof DomańskiBackport 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.