Problem/Motivation

The page listing all tests ( /admin/config/development/testing ) has duplicated id's in the HTML sent, which is against W3C spec. I do not know of any existing problems caused by this violation, but they are possible as the return of the function document.getElementById is undefined by spec when more than one id is present (currently I think all browsers return the first instance on the page). So this could cause problems for the JavaScript behaviors of the page. This was discovered by the unique assertion in AttributeNamedId in #2444003: Optimize Drupal\Core\Template\Attribute.

This occurs because we have test groups with different capitalization cases. The first example on the page is "Action", which is out of the Drupal\system\Tests\Action namespace, and "action" which is from the action module at Drupal\action. So having the collision is natural - the keys don't collide when the modules are pulled because PHP keys are case sensitive.

CSS identifiers however are not case sensitive and so when the code prior to this patch creates the group_class name it uses strtolower. This creates the id collision and the bug.

Proposed resolution

The output of $group_class is never user visible - it's a reference used by JavaScript only - so there is no reason to build it using strtolower(preg_replace()) in the first place. Therefore I set an increment variable before the for/each which builds the array of modules, insuring all modules will have a unique id. This is also has the advantage of being less computationally expensive than the regex.

Remaining tasks

Final reviews

User interface changes

None

API changes

None

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug
Issue priority Major - one of the goals of 8 is to be have fully valid output HTML. This bug prevents this.
Unfrozen changes Unfrozen because it only changes the HTML markup of the offending page.

Comments

joelpittet’s picture

Status: Needs review » Needs work

@Aki Tendo thanks for the report. Could you explain a bit more what the problems JS is having or which IDs are duplicating? Maybe we should fix the collisions instead of masking them?

Here's a quick review on the patch:

  1. +++ b/core/modules/simpletest/src/Form/SimpletestTestForm.php
    @@ -105,6 +105,9 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    +    // Insure no id collisions
    

    Replace "Insure" with "Ensure" and sentence needs to end in a period.

  2. +++ b/core/modules/simpletest/src/Form/SimpletestTestForm.php
    @@ -112,7 +115,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    +      $group_class = 'module-' . strtolower(trim(preg_replace("/[^\w\d]/", "-", $group))) . '-' . strval($i++);
    

    There should be no need to cast this to a string, it will implicitly cast it through the concatenation.
    Example:
    http://3v4l.org/6XaB5

    And in general core mostly casts with (string) instead of the function from a cursory search as I haven't seen that function used much. 4 times strval() vs 402 for (string), so if you think it needs an explicit cast let's use (string).

Aki Tendo’s picture

Issue summary: View changes

Expanded both the problem explanation and the reason the solution is the way it is as requested in IRC with Joel.

Aki Tendo’s picture

Issue summary: View changes
Aki Tendo’s picture

Status: Needs work » Needs review
StatusFileSize
new1.12 KB

Changes above applied. Also, since $group_class is never end user visible, just drop the whole strtolower(preg_replace()) operation in favor of just using $i to keep each module group section unique.

Aki Tendo’s picture

StatusFileSize
new1.12 KB

Forgot to add the period. This patch marked do not test since it is otherwise identical to #4 with the only change occurring in comment text.

Aki Tendo’s picture

Issue summary: View changes

Issue updated and properly formatted. Since the last patch passes it should be safe to just do away with the regex entirely.

joelpittet’s picture

Status: Needs review » Needs work

Wow there is a bunch of cleanup on that test, so many duplicate names because of Titlecase or lower case group names.

The names were kinda useful before as a "group class", but useless as pointed out in the issue summary as an #id.

Since I very highly doubt anybody is going to go out of their way to style test groups differently in an admin theme. I see no problem with doing the $i increment identifier. Though it would make much more sense if the variable was changed to $group_id, or something because it's no longer a CSS class or Test PHP class.

Aki Tendo’s picture

Status: Needs work » Needs review
StatusFileSize
new2.43 KB

Change applied. Forgoing uploading an interdiff since the main patch is so small anyway.

alexpott’s picture

What are the duplicate IDs?

Aki Tendo’s picture

Probably over 100 - examples: module_action, module_block, module_config, module_datetime, module_field, module_file, module_image, etc. Basically any system test that also has tests in a core module. The culprit is the strtolower() call. While we could remove it, that would only solve the problem for Java Script -- CSS would still be affected since it is case insensitive. Also, having uppercase characters in id's violates code standards.

Aki Tendo’s picture

StatusFileSize
new1.3 KB

As an alternative to an incrementor prefix the group as a module if its label is all lower case (which modules are supposed to be and all the core modules will be), otherwise prefix as 'core'

alexpott’s picture

mile23’s picture

Solution in #2301481-20: Mark test groups as belonging to modules in UI adds ' module' to module groups, maybe solving this issue, though it would be great to have a test.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.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.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.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.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Aki Tendo’s picture

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.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.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.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.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.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.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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.

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

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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.

quietone’s picture

Project: Drupal core » SimpleTest
Version: 8.9.x-dev » 8.x-3.x-dev
Component: simpletest.module » Code

Triaging issues in simpletest.module as part of the Bug Smash Initiative to determine if they should be in the Simpletest Project or core.

This looks like it belongs in the Simpletest project.