Problem/Motivation
TipPluginTextTest is using the \Drupal\Component\Utility\Random::word() function to generate strings and expecting uniqueness - however that method does not guarantee that.
See https://www.drupal.org/pift-ci-job/962303
Proposed resolution
Use randomManchineName instead as that guarantees uniqueness.
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 2972531-7.patch | 1.05 KB | alexpott |
| #4 | 2972531-4-test-drive.patch | 2.09 KB | Anonymous (not verified) |
| #4 | 2972531-4.patch | 2.25 KB | Anonymous (not verified) |
| #4 | 2972531-4-data-provider-test-only.patch | 1.11 KB | Anonymous (not verified) |
| #2 | 2972531-2.patch | 834 bytes | alexpott |
Comments
Comment #2
alexpottComment #4
Anonymous (not verified) commentedHah, it is surprising that
$this->randomMachineName()returns string with upper cases too.Also it is suprising that static names not works with dataprovider. Maybe I just do not know this mechanism, I used to think that the one iteration should not affect the other, but some kind of caching is obviously happening. Sure, it is out of scope.
Comment #5
Anonymous (not verified) commentedNow we lose the guarantee that this is a unique name :(
Because
Random::name()is case sensitive when checking for uniqueness.Comment #6
alexpottMachine names can have uppercase. So I'm not sure about that. The only reason I used the machine name version is because of the unique guarantee.
Comment #7
alexpottThe reason we have this test is because of an incorrect static that was removed in #2918643: TipPluginText's ariaId is not unique.. So hardcoding the strings is fine. Also we should actually run this test in a separate process because of the static in
\Drupal\Component\Utility\Html::getUniqueId()- using run-tests.sh every test is run in a separate process but if you use the vanilla PHPUnit runner you have no such guarantee.Comment #8
Anonymous (not verified) commentedWow, I did not know that! Last time I experienced this effect when I realized that we can create field without "field_". Thank you for the wisdom, @alexpott!
#7 looks very solid!
Comment #10
alexpottHmm... I'm wrong. By default a machine name can only contain lowercase.
'replace_pattern' => '[^a-z0-9_]+',from\Drupal\Core\Render\Element\MachineName::processMachineName(). @vaplas the change in #4 is definitely worth pursing in a different issue as I think the random machine name generated should conform to our default regex.Comment #11
alexpottCommitted and pushed df75450932 to 8.6.x and 59f1eae853 to 8.5.x. Thanks!
Committed myself because random fails are annoying and this is test only code.
Comment #14
Anonymous (not verified) commentedDone #2972573: randomMachineName() should conform to processMachineName() pattern