- ๐บ๐ธUnited States m.stenta
I ran into this as well, trying to use the following machine name element in a form for specifying a URL subdomain, in which I wanted to only allow alphanumeric and hypens (not underscores), and in which invalid characters should be removed entirely (not replaced with anything):
$form['subdomain'] = [ '#type' => 'machine_name', '#title' => $this->t('Subdomain'), '#machine_name' => [ 'exists' => [$this, 'subdomainExists'], 'label' => $this->t('Subdomain'), 'source' => ['site_name'], 'replace_pattern' => '[^a-z0-9-]+', 'replace' => '', 'error' => $this->t('The subdomain can only contain letters, numbers, and dashes.'), ], ];
I was experiencing the same warning. Applying the patch fixes it. Thanks @Grayle!
- Status changed to Needs work
8 months ago 8:39am 20 August 2024 - ๐ซ๐ทFrance nod_ Lille
Please convert the patch to a MR so that tests can run :)
- Merge request !9263Issue #3092530 by Grayle: Allow empty 'replace' patterns for MachineName render element โ (Open) created by m.stenta
- Status changed to Needs review
8 months ago 12:28pm 20 August 2024 - ๐บ๐ธUnited States m.stenta
Converted patch by @Grayle to a merge request. Back to "Needs review" for tests to run...
- Status changed to Needs work
8 months ago 2:45pm 23 August 2024 - ๐บ๐ธUnited States smustgrave
Can the issue summary be updated, should be using the standard issue template.
Also as a feature request probably need some kind of test coverage to make sure it doesn't break in the future.
- ๐บ๐ธUnited States m.stenta
> as a feature request probably need some kind of test coverage
I actually think this should be a bug report, because the
machine_name
element type already exists, but causes a warning under certain conditions. Updating the title and category to reflect that...Still probably needs tests. And issue summary update.
- ๐บ๐ธUnited States smustgrave
Recommendation for test is to see if there is an existing one you can picky back with hopefully just an additional assertion.
- ๐บ๐ธUnited States m.stenta
Recommendation for test is to see if there is an existing one you can picky back with hopefully just an additional assertion.
Hmm yea - I wonder if this will be tricky, because essentially we need to test to see if a PHP Warning is thrown. The code does "work", and thus a test of the actual functionality will pass, but it's the PHP Warning we are trying to fix.
- ๐บ๐ธUnited States smustgrave
I always lean on the side of test coverage, microsoft re-enforced that
But there is policy for small changes not needing test coverage https://www.drupal.org/about/core/policies/core-change-policies/core-gat... โ . Just a matter of proving the points are hit to not need them.
- Status changed to Needs review
13 days ago 5:11pm 31 March 2025 - ๐บ๐ธUnited States m.stenta
I would argue this is a case where a test isn't needed, and may not be possible... but leave that to others to decide.
there is policy for small changes not needing test coverage https://www.drupal.org/about/core/policies/core-change-policies/core-gat... โ . Just a matter of proving the points are hit to not need them.
Copied and answered the questions below (to the best of my understanding):
An automated test for a bug fix may not be needed if the following are true and if the majority of answers to the questions below is 'Yes'.
- The issue has clear โSteps to reproduceโ in the Issue Summary. โ๏ธ
- The fix is 'trivial' with small, easy to understand changes. โ๏ธ
Questions
- Is the fix is easy to verify by manual testing? YES
- Is the fix in self-contained/@internal code where we expect minimal interaction with contrib? Examples are plugins, controllers etc. YES
- Is the fix achieved without adding new, untested, code paths? YES
- Is an explicit 'regression' test needed? NO
- Does the issue expose a general lack of test coverage for the specific subsystem? If so, is it better to add generic test coverage for that subsystem in a separate issue? NO
- If this fix is committed without test coverage but then later regresses, is the impact likely to be minimal or at least no worse than leaving the bug unfixed? NO
I removed the "Needs Tests" tag, but please restore it if you disagree.
- ๐บ๐ธUnited States smustgrave
Looking at the steps I would assume a test could be written.
- ๐บ๐ธUnited States smustgrave
Moving to NW because the MR is now almost 1000 commits back and still think test coverage is needed.