Needs work
Project:
Drupal core
Version:
11.x-dev
Component:
phpunit
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
24 Jul 2026 at 19:18 UTC
Updated:
26 Jul 2026 at 01:42 UTC
Jump to comment: Most recent
#3586832: Allow kernel test classes to define their own routes added the ability to kernel test classes to define their own routes. The test for that functionality involves generating a random string value in the test class and assigning to a class property, then using that property to set the content in the route response. Since the random string generated is not sanitized, the sanitized rendered string will not match the original.
Assert the escaped value string exists in the response.
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
godotislateComment #4
godotislateComment #5
godotislateComment #6
godotislateComment #7
nitinkumar_7 commentedI have tested and reviewed MR !16436 locally.
### Review Summary
- **Root Cause:** In `KernelTestHttpRequestTest::testKernelTestRoute()`, `$this->testMarkup` is populated using `$this->randomString()`, which can produce HTML special characters (`<`, `>`, `&`, `'`, `"`). Because Drupal automatically escapes raw text rendered in responses, `pageTextContains()` intermittently failed whenever special characters were present.
- **Verification:** Changing the assertion to `$this->assertSession()->assertEscaped($this->testMarkup)` correctly verifies that raw random strings with special characters are safely HTML-escaped in the output, resolving the random test failures.
### Local Test Output
Executed `KernelTestHttpRequestTest` locally against MR !16436:
```bash
$ SIMPLETEST_DB=sqlite://localhost/sites/default/files/.ht.sqlite ./vendor/bin/phpunit -c core core/tests/Drupal/KernelTests/KernelTestHttpRequestTest.php
Comment #8
nitinkumar_7 commentedPHPUnit 11.5.55 by Sebastian Bergmann and contributors.
Runtime: PHP 8.3.6
Configuration: /home/gai/Documents/drupal/core/phpunit.xml.dist
... 3 / 3 (100%)
Time: 00:08.875, Memory: 14.00 MB
OK (3 tests, 17 assertions)
The test suite passed completely with 17 assertions. The proposed fix resolves the intermittent failure.
Comment #9
godotislate@nitinkumar_7 if the MR passes review, please set to Reviewed & tested by the community. Otherwise, please set to Needs work and advise of what changes need to be made.
Comment #10
nitinkumar_7 commentedComment #11
longwaveCommitted and pushed e703c4740cd to main and 040541d150b to 11.x. Thanks!
Comment #15
catchThis introduced a new random test failure, see #3613247: [random test failure] KernelTestHttpRequest route testing fails.