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.
Problem/Motivation
#2416987: Fix UI regression in the menu link form, in an effort to remove a fieldset style for menu links add/edit form (which uses the link widget always with link text (disabled),
broke using the link widget elsewhere.
Steps to reproduce
- Install Drupal
- Add a Link field - with an "Help text" and "Allow link text" set to "Disabled" - to any content type
- Create a node of this content type
Expected result: the "Help text" is shown under the link field
Current result: the "Help text" is not shown
Cases
- menu link
- shortcut
- link widget used in content types (or other things that have fields):
- cardinality 1, link text disabled, internal url only
- cardinality 1, link text disabled, external url only
- cardinality 1, link text disabled, internal and external url
- cardinality 1, link text enabled, internal url only
- cardinality 1, link text enabled, external url only
- cardinality >1, link text enabled, internal and external url
- cardinality >1, link text disabled, internal url only
- cardinality >1, link text disabled, external url only
- cardinality >1, link text disabled, internal and external url
- cardinality >1, link text enabled, internal url only
- cardinality >1, link text enabled, external url only
- cardinality >1, link text enabled, internal and external url
Proposed resolution
Add tests.- Make link widget handle all the cases. (please read #2416987: Fix UI regression in the menu link form)
Remaining tasks
Task | Novice task? | Contributor instructions | Complete? |
---|---|---|---|
Create a patch | Instructions | Done | |
Reroll the patch if it no longer applies. | Instructions | Done | |
Update the issue summary | Instructions | Done | |
Add automated tests | Instructions | Done | |
Update the patch to incorporate feedback from reviews (include an interdiff) | Instructions | To Do. See: | |
Manually test the patch | Novice | Instructions | Done |
Add steps to reproduce the issue | Novice | Instructions | Done |
Embed before and after screenshots in the issue summary | Novice | Instructions | Done |
Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards | Instructions |
User interface changes
Before
After
API changes
Comment | File | Size | Author |
---|---|---|---|
#124 | 2421001-124.patch | 13.65 KB | gnuget |
#124 | interdiff-2421001-120-124.txt | 858 bytes | gnuget |
#120 | 2421001-120.patch | 13.42 KB | DuaelFr |
#120 | interdiff.2421001.118.120.txt | 1.28 KB | DuaelFr |
#118 | interdiff.txt | 687 bytes | pfrenssen |
Comments
Comment #1
YesCT CreditAttribution: YesCT commentedthis will not apply, but is the patch from #43 from the other issue.
it did the approach "use logic based on cardinality and link text being disabled or enabled" (the bit about fixing the short cut page title will have a separate issue).
Comment #3
YesCT CreditAttribution: YesCT commentednext step is to strip out all the unrelated stuff from that patch.
Comment #4
amateescu CreditAttribution: amateescu commentedWhat was wrong with the patch from #2416987-61: Fix UI regression in the menu link form?
Comment #5
YesCT CreditAttribution: YesCT commentedtaking the fieldset off made the help text that used to show, not show.
(we traded a task that removed a boarder for a bug that made helptext not show)
Comment #6
mgiffordMostly testing out the credit link on a patch I've already contributed.
Comment #7
amateescu CreditAttribution: amateescu commented@YesCT, in #4 I linked to a specific comment from [#9580553], which is comment #61 from that issue :)
Comment #8
YesCT CreditAttribution: YesCT commented#2421021: Missing help text for external url only for link widget went in, now we can expand those tests for all the cases here.
Comment #9
kerby70 CreditAttribution: kerby70 at Blink Reaction (now part of FFW) commentedCorrecting non standard tag 'Need tests' to 'Needs tests'
Comment #10
idebr CreditAttribution: idebr commentedThe patch from #6 includes changes that are out of scope for this issue. Per YesCT in #2:
User facing strings of an example url should no longer use drupal.org, see #2418209: Replace user facing strings that use drupal.org as example of an external url.
Comment #11
YesCT CreditAttribution: YesCT commentedI'm going to start on this.
Comment #12
YesCT CreditAttribution: YesCT commentedFor menu link,
it used to be labeled "Link path"
#2416987: Fix UI regression in the menu link form changed the label to just be "Link".
So far, this changes it to be "Link (URL)"
since the premise is to use the label from the field, and also use the label from the widget.
--
I did not use a const for the optional/required/disabled link text. could not find a const on the interface.
--
used random machine name for the help text. there might be a better way.
--
I'm having trouble setting the description and the link text setting in the field form....
uploading this for now. If anyone has ideas, let me know. I'll continue to work on this some more now though also.
Comment #14
YesCT CreditAttribution: YesCT commentedthere are many permutations...
might be nice to add in tests for the field label, and the url label. but I'm done (for today).
[edit: hm. made interdiff wrong as it is exactly the same size as patch)
Comment #16
YesCT CreditAttribution: YesCT commentedThe fails in #14
Are:
1.
Raw "q1aT6RQm" found Other LinkFieldUITest.php 275 Drupal\link\Tests\LinkFieldUITest->testFieldUI()
Raw "hw9dscwI" found Other LinkFieldUITest.php 306 Drupal\link\Tests\LinkFieldUITest->testFieldUI()
Raw "kKFeJtau" found Other LinkFieldUITest.php 338 Drupal\link\Tests\LinkFieldUITest->testFieldUI()
All three when the link text is disabled, the field help text (description) is missing.
2.
MenuLinkContentFormTest.php 46
ShortcutLinksTest.php 61
The field help text (description) from the base field definitions:
core/modules/menu_link_content/src/Entity/MenuLinkContent.php
298: ->setDescription(t('The location this menu link points to.'))
core/modules/shortcut/src/Entity/Shortcut.php
151: ->setDescription(t('The location this shortcut points to.'))
We should either show them (which this patch does). Or take them out (... throwing an error if they are try and set).
Comment #17
YesCT CreditAttribution: YesCT commented1. I'm not sure if we want to test *where* the description is (with xpath selectors).
2. I'm also not sure how to organize the tests.
3. The combination of link text optional is not tested with cardinality greater than 1.
4. Some of the comments are cut and paste and need to be corrected.
5. In this issue, I think we might want to NOT append the (URL) to the label for the field.
6. In fact, I think we might want to change the label there to Link location and not URL.
Since the thing that is typed there is not always (not often) a url... for example... people might type part of a title of a node, or an internal path.
Changing the label on the default link widget would be a separate issue.
#2461361: Change link widget URL field label to Link location, since what people put in the field does not have to be (usually will not be) a URL
Comment #18
eiriksmI ran into this issue while building a Drupal 8 site. Had me wondering for a while :)
Tested the patch and it does not apply anymore. So here is a reroll, which also include these changes:
- Refactor all cases of testing for help texts into a loop (maybe address your concern #2). This also addresses concern #3 and #4.
Now, the code changes in this patch addresses the mentioned regression, but I was wondering about another thing (potentially another issue i guess):
- Why do we hide the description for internal links (and instead rely on the "helpful" prefix)? The help text that in the case of external/internal states that "Start typing the title of a piece of content" and this also applies when the setting is set to "only internal", only no-one gets this helpful hint. In fact, adding the prefix kind of makes you think that the input is required to be a internal URL, when it can in fact be the title of a node.
Thoughts?
Comment #19
eiriksmSetting to needs review.
Comment #21
eiriksmYes, that was expected :)
Comment #22
DuaelFrI don't understand why this patch is so complicated.
The following cases seems to already be handled by default :
- cardinality > 1, all cases
- cardinality = 1, title enabled, all cases
We just need to handle
- cardinality = 1, title disabled, all cases
Please find attached a simple solution that fixes the issue (without tests, sorry).
The side effect of this fix is that, in the Menu UI, the MenuLinkContent 'link' base field description ('The location this menu link points to.') is appended to the field description. This leads to that help text displayed on the field : 'Start typing the title of a piece of content to select it. You can also enter an internal path such as /node/add or an external URL such as http://example.com. Enter to link to the front page.
The location this menu link points to.'
I think that the appended information improves the usability of the field so it might not be considered as a problem.
Let's see what the testbot have to say about that patch an discuss my tiny solution.
Comment #24
DuaelFrBetter handling of empty descriptions (fixes tests)
Comment #25
eiriksmLooks fine to me. Fixes the bug.
Can we add some quick tests, though? You can still base it on the "test-only" patch in #18 I guess.
Comment #26
dawehnerIt would be great to have some quick comment why we have this logic here.
Comment #27
StryKaizerAttached you can find a test only, which should fail, and a test + patch.
Test is the code from #18, added 1 verbose command to see which variant is being tested.
Patch is taken from #24, added comment as asked in #26
Comment #29
DuaelFrThanks @StryKaizer for your work!
Tests pass.
Coding standards are OK.
And finally, labels are where they're supposed to be \o/
Before
After
Comment #30
alexpottThere does not seem to be any test for this. Since adding html together is one of losing safeness with need to confirm that we're not introducing an escaping bug here.
Comment #31
eiriksmI might misunderstand your comment, but this should cover the case you are asking for, no?
Granted, we do not test _not_ adding a custom description, so here is a quick patch adding that as well. Since you mention " Since adding html together is one of losing safeness with need to confirm that we're not introducing an escaping bug here." do you want to add an assertion that we are not seeing the
tag as text also? (for the record, it does not introduce an escaping bug, i just tested manually)
Comment #32
thorandre CreditAttribution: thorandre as a volunteer and commentedManually tested. Looking good.
Comment #33
thorandre CreditAttribution: thorandre as a volunteer and commentedComment #34
thorandre CreditAttribution: thorandre as a volunteer and commentedComment #35
thorandre CreditAttribution: thorandre as a volunteer and commentedComment #36
eiriksmRe-read the comment in #30 and I think I might have misunderstood the concern, so I'll just add a quick test for that. Also, want to replace the random data in there (see #2571183: Deprecate random() usage in tests to avoid random test failures for more info)
Comment #37
eiriksm- Replaced some random data.
- Fixed some lines that were 81 characters :p
- Added html in the descriptions, to test this does not get escaped (hope that was what you were after, @alexpott?)
Comment #38
DuaelFrI made a new round of manual testing and that still looks good!
Thank you @eiriksm.
Comment #39
yoroy CreditAttribution: yoroy as a volunteer commentedTested on simplytest with a link field on the article content type and editing a shortcut link.
Link field:
Shortcut:
Whenn I compare that shortcut screen with a Drupal 8 install without the patch the description "The location this shortcut points to." is not shown in the latter.
I *think* this is rtbc.
Committers want to look at #30, #31 and #37
Comment #40
catchWhy the
<br />
tag?Also it's not clear to me whether the test covers the case where the uri description and field description are concatenated.
Comment #41
mgiffordSeems to have been added in #31.
Comment #42
eiriksmTo first comment on the <br>, it was first introduced in #22. I guess the reason was not explicitly defined, but I assume the main point is that we want to differentiate between "core help text" and "user entered help text". As an example, look at this image:
If the text "Here is my link help text" would be just after the "core help text", that would appear strange. In my opinion, anyway.
Would it be preferable if we added these in different render arrays, making them paragraphs instead of concatenating them with a <br>? Or was your point that you would prefer it to not be there, and instead be concatenated with no markup between?
Now, regarding test coverage for the above mentioned. It is not really tested that the concatenated text is on the page. It is, however, tested that both the user entered and the "core help text" is on the page. Although I guess an extra assertion would not hurt. :)
Let's just first decide how to proceed with the "<br> problem". Any thoughts from anyone there? Keep it? Remove it? Change it?
Comment #43
DuaelFr@eiriksm You're totally right. I introduced that
<br>
because I thought it was less confusing than without.I don't know at all if it's better than paragraphs but I'm afraid that paragraphs default style would make it bad looking.
Comment #44
mgiffordSo do we style the
<p>
, add documentation to the<br>
or just set it back to RTBC?I'm for adding a comment in the PHP to explain why this was added.
Comment #45
DuaelFrI'm not de the right guy to write comments.
I can put it in the code and make the patch file but I'm not confident enough in english to write it :)
Comment #46
eiriksmOK, here is an updated patch.
- Added a comment in both the test and the widget why we add the BR tag.
- Fixed a typo.
- Simplified the test code a little.
- Added assertions for when the BR tag should be added.
Comment #47
swentel CreditAttribution: swentel as a volunteer commentedtypo: cardinality
Looks good to me other than that.
Comment #48
eiriksmoops. Oh well, typo fixed.
Comment #49
mohit_aghera CreditAttribution: mohit_aghera as a volunteer and at Axelerant commentedI tested #48 on simplytest.
Things are appearing fine. Screenshots are attached.
Comment #50
alexpottThis is concatenating markup which will lose safe-ness. This works because #description is XSS admin filtered. Not sure what is the right thing to do here. Setting back to needs review to get more people than just me thinking about this.
Comment #51
eiriksmHow about this? An inline template for the description?
Comment #52
mohit_aghera CreditAttribution: mohit_aghera as a volunteer and at Axelerant commentedLooks good by testing on simplytest.me
Moving it to RTBC
Comment #53
DuaelFr+1 RTBC for the online template, good idea @eiriksm
Comment #54
catchIs the br tag necessary? Why not just a space?
Comment #55
mohit_aghera CreditAttribution: mohit_aghera as a volunteer and at Axelerant commented@catch
As per me it will look good and add some more user friendliness.
For ex: See 2421001-51-1.png in #52
In Link 3 field, if we don't separate link description in new line it will be hard to identify link description and link help text. Same holds true for this snapshot as well.
Comment #56
catch@mohit that's what I'm saying though. If the description and help text are actually semantically different, then they should not be within the same HTML tag. The
<br >
tag is not visible to screen readers for example.Comment #57
mohit_aghera CreditAttribution: mohit_aghera as a volunteer and at Axelerant commented@catch
How about moving both to separate div like
https://api.drupal.org/api/drupal/core%21modules%21block%21src%21Control...
Comment #58
DuaelFr<div>
are not read by screen readers. Most of the time, they don't vocalize<p>
either (and they would need an extra layer of theming to avoid too big margins at this place).The best option would be to add visually hidden labels to these elements but I'm not sure we can find something really relevant.
I also think we should put the user defined description first because screen readers users often skip content they already know. So, if that starts with the exact same words as everywhere else on the website, they'll tend to skip it entirely and miss the user entered part.
Comment #59
joelpittetNice work on getting tests going for this and resolving the regression.
Toying with link.module component vs maybe form api as this doesn't really touch the menu system. Please correct this if it's wrong.
I'm reviewing this to see if I can't get this back to RTBC.
I'd prefer to move this markup to the template(as always).
Why do we add the description to the
uri
? Was it the only thing to add it to? Maybe there is a more appropriate place for this?This may be harder but it would be nice to get this variable into the template to make it easier to theme. Even if a break tag is the solution, it will make it much easier to override.(I hope)
Ping me on irc #drupal-contribute if you have any questions.
Comment #61
xjmThe core committers (@xjm, @alexpott, @catch, @effulgentsia, @Cottser) and theme maintainers (@lauriii, @joelpittet) discussed this issue today and agreed that this issue does not need to be major priority. However, we did accidentally remove the ability to add this text to these fields, and that can be considered a bug.
The screenshots in the summary explain the problem, but this issue would be easier to understand with specific steps to reproduce in the summary. (I see the issue has test coverage already in the patch, although I did not review the changes thoroughly.)
@joelpittet also noted that using an inline template and joining two strings with a
<br />
tag are non-ideal (though the inline template is at least not introducing any escaping bugs, so it is an improvement over earlier patches for that reason.) If possible, we should use actual templates for markup, and/or more semantic markup. (For example, maybe it should be an unordered list?) It's worth considering whether this is the best way to ensure both description texts are available.We should consider whether the issue might be better targeted for 8.2.x, because it is making a user-facing change and adding new UI text. (Some module could already be altering to add text back in addition, and this patch could result in that text being repeated twice, for example.) I've moved it to 8.2.x for now.
Finally, it looks like the feedback from @DuaelFr, @catch, and @joelpittet all still needs to be addressed as well.
Thanks everyone for your work so far on this bug!
Comment #62
xjmPer #61, let's add the specific steps to reproduce to the summary.
Comment #63
DuaelFrAdded steps to reproduce and improved remaining tasks.
Comment #64
DuaelFrComment #65
DuaelFrHere is a new patch where I choosed to use an item_list to show both descriptions.
To anwser @joelpittet in #59.1: no, we sadly don't have any better option. In the case we are talking about, the only element we have is that 'uri' element. That's only when we get both uri and text that we have a surrounding container.
Comment #67
YesCT CreditAttribution: YesCT commented#65 uses a render array.
a template would be better.
but since this is in a field widget, which is already using a render array, the change to template would be out of scope and a separate issue.
I discussed test changed with @DuaelFr (at dev days)
and I think that asserting the strings are there is sufficient,
and we should NOT test if the html is br or ul, that would be a test of the list generator, or an accessibility testing layer, or in a theme test.
Since the order of the strings was agreed to be important though,
if there is a somewhat easy way of testing the order (maybe an existing assert method) it could be worth doing in this issue,
if it is difficult and complex xpath things are needed, maybe we can go on without a test of the order.
Comment #68
DuaelFr@YesCT thanks for the review :)
I wasn't able to find any usefull existing assertion to test strings order.
This new patch removes the part where we try to test the html structure of that description.
Comment #69
YesCT CreditAttribution: YesCT commenteduploading a testsonly patch so we can check the tests fail appropriately
(and the same whole patch, so that retests will also retest the whole patch and not just the testonly one, which will fail and change the status to needs work confusingly)
Comment #71
DuaelFrGreen! \o/
Comment #72
YesCT CreditAttribution: YesCT commentedcan improve the grammar here a bit. (and explain why it might be skipped...? or we could assume people would git blame and come here and read the comments on the issue. ;)
If the usual system message is first, screen reader users might skip it and not notice the more likely custom help text. Put the user description first to avoid screen reader users skipping it.
Or just
Put the user description first to avoid screen reader users skipping it.
oh! I love these loops and this test set up!
In general this looks great!
Comment #75
pfrenssenPatch doesn't apply any more.
Assigning to me. I'll first make a patch with a straight reroll to latest 8.4.x, and then a second one to address the remarks from #72.
Comment #76
pfrenssenStraight reroll.
Comment #77
pfrenssenSetting to needs review for the bot. The tests have been ported to BrowserTestBase in the meantime so there might be subtle changes causing failures now.
Leaving assigned to me to review + address remarks from #65.
Comment #79
pfrenssenWe can use
[]
instead ofarray()
to make this line more hipster.Let's remove the debugging cruft.
Relogging and creating content types are expensive operations. Since these actions are done in the inner loop of the test a lot of time is spent doing this. A bit later in the loop a new test user is also created and logged in for every iteration.
I think we can save a lot of cycles if we only log in with the admin user once to create the test fields, and then relog once as the test user to verify the expected output.
I also think creating one single content type with multiple fields would be sufficient. If we give the fields unique machine names we can check that the expected messages are associated with the expected fields.
Comment #80
jofitz CreditAttribution: jofitz at ComputerMinds commented(and removed Needs Re-roll tag)
Comment #81
pfrenssenGreat improvement in speed!
From 1.59 minutes to 1.03 minutes, it's almost twice as fast!
We can probably shave off some more seconds if we create the fields using the field API instead of through the interface. Since we are not actually testing the field UI there's no need to use the UI for this.
I think we can keep this part of the test if we only look inside the field container for checking the absence of the text, instead of checking the entire response page.
Comment #82
pfrenssenUsed the field API to create the test fields. I also restored the tests for the absence of non-configured help texts by using XPath to pinpoint exact fields in the document.
The test runs again almost twice as fast, now down to 31 seconds from the original 1 minute 59 seconds!
Comment #83
pfrenssenAnd here is the patch :D
Comment #85
pfrenssenRerolled against latest HEAD.
Comment #86
peterhebert CreditAttribution: peterhebert commentedHaving the description appear after the link text field is a bit confusing IMHO. It is confusing because it appears like it's describing the link text as opposed to the URL itself. I would suggest that it appear after the URL field, before the drupal-supplied text about the requirements (internal/external link). Here is a mock-up of what I'm suggesting:
Comment #87
geertvd CreditAttribution: geertvd at Geert van Dort commentedReroll
Comment #88
rogierbom CreditAttribution: rogierbom at Synetic commentedComment #89
John Cook CreditAttribution: John Cook at Creode commentedI've checked used the reproduction instructions to test geertvd's patch from comment #87.
Before:
After:
The help text has been added to the field's "help" area.
I'll go through the other variants in the summary before changing the status.
Comment #90
John Cook CreditAttribution: John Cook at Creode commentedOK. I've run through the the variants mentioned in the summary. Get ready for a load of screenshots.
Cardinality: 1
Link text: disabled
Url type: internal
Cardinality: 1
Link text: disabled
Url type: external
Cardinality: 1
Link text: disabled
Url type: both
Cardinality: 1
Link text: required
Url type: internal
Cardinality: 1
Link text: required
Url type: external
Cardinality: 1
Link text: required
Url type: both
Cardinality: Unlimited
Link text: disabled
Url type: internal
Cardinality: Unlimited
Link text: disabled
Url type: external
Cardinality: Unlimited
Link text: disabled
Url type: both
Cardinality: Unlimited
Link text: required
Url type: internal
Cardinality: Unlimited
Link text: required
Url type: external
Cardinality: Unlimited
Link text: required
Url type: both
Comment #91
John Cook CreditAttribution: John Cook at Creode commentedThe help text is now displayed on menu and shortcut link fields as well as link fields where the cardinality is 1 and the link text option is disabled.
It appears that the problem doesn't exist on other setting combinations on link field.
I've also looked at the code. All appears to be OK.
I've now changed the status to RTBC.
Comment #92
idebr CreditAttribution: idebr commentedClosed #2839940: Help Text does not override Link text 'This must be ...' as a duplicate issue.
Comment #93
cilefen CreditAttribution: cilefen at Institute for Advanced Study commentedI skeptically tested with an unordered list within the help text, but that actually looks ok.
Comment #94
Leo Pitt CreditAttribution: Leo Pitt commentedClosing duplicate.
Comment #96
star-szrMinor but this comment is a bit cryptic/terse to me, can this be expanded upon, please?
(leaving at RTBC)
Edit: Also minor, there is one coding standards violation, missing space after foreach: https://www.drupal.org/pift-ci-job/728472
Comment #98
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer and at Annertech commentedThat comment isn't particularly relevant to screen readers IMO - I think it's more accurate to say the custom help text is the most relevant part for everyone.
The link URL input has an
aria-describedby
attribute, which points to thediv.class
wrapper around the entire list of descriptions. That is, the list constitutes a single description as far as assistive tech is concerned.This patch addresses #96 by:
Comment #99
joelpittetReturning to RTBC glory
Comment #100
joelpittetPutting back to 8.4.x due to it being a bug fix.
Comment #101
gnuget#97 no longer applies because #2864088: Convert web tests to browser tests for shortcut module was commited, so I just rerolled the patch.
Comment #102
xjmI finally had a chance to sit down and review this patch. I was a bit hesitant about the proposed resolution, but after more than a month I've not thought of a better way to do this, and it definitely resolves the issue. The presentation to the user is also fine; it was just the bit of mucking with the semantics of the element that gave me pause. And @andrewmacpherson has already reviewed and it sounds like we are okay on the accessibility front now.
The very thorough manual testing demonstrates how well the fix works; thank you so much for providing the screenshots.
There's one thing I think we need to change with the tests (which are really thorough which is great to see).
So, this sort of thing is what data providers are made for. The good news is that LinkFieldUITest is already a BTB test, so we can use one! So I think we can refactor the test to use a data provider (really they're the first thing that got me excited about PHPUnit a couple years ago), and then we are good to go.
This isn't actually a string change -- the strings are already defined -- it's just a small UI change and a change to a render array. Typically those changes are minor-only, so the branch change in #99 isn't really correct.
However, since it's a clear UX and a11y bugfix with the only disruption being to the link element's render array, I feel comfortable backporting this during the release candidate phase if needed.
Very sorry for the long wait time; I know this one didn't get the feedback it deserved during the alpha and beta phases.
Comment #103
xjmComment #104
gnugetOk, new patch using a Data Provider, but I have doubts:
Using the data provider executes the whole test per test_case, making it way slower than before, In my computer it was ~15 seconds with the previous patch and now it takes ~4 minutes, is this expected and ok?
It seems that the data providers are executed before to include all the files, so it fails whenever I use a constant and that is why in my patch I didn't use them in the data provider, this makes me wonder if this is ok or is there a good way to use constants in a Data Provider?
- David
Comment #105
Sinan Erdem CreditAttribution: Sinan Erdem commentedI have tested the patch (cleared cache etc) but the problem with it is both the default help text and manually entered help text are visible now. Attaching screenshots.
Comment #106
DuaelFr@Sinan ErdemThank you for your review!
The thing is that showing the default help text is needed because we cannot ask the site builder to know what this text is and to include its content in they own help text. What you are describing is precisely what we are trying to introduce with this patch, so it's perfectly working ;)
Comment #107
Sinan Erdem CreditAttribution: Sinan Erdem commentedI didnt know that, sorry.
Anyway, IMO, the help text should be easily overridable, because this default help text aims mostly site builders. Normal users would need better, site-specific descriptions. In my case, I want to write that "The link should resemble https://www.linkedin.com/in/YOURNAME" which already contains the information that the link is external.
Comment #108
Lendude@gnuget yeah setup() is run for each item in the dataprovider, so doing this in a BTB test takes a HUGE hit on speed. So unless you need a fresh install for each item, it's probably better not to use it.
But I agree with xjm that it's a great pattern to use, but how about we sorta follow that pattern but skip the setup? Patch does something like that.
Comment #109
gnugetThanks for your help, Lendude.
I just restored the constants in this patch and removed an unused variable.
Comment #110
pfrenssenI agree it's not a good idea to use data providers in functional tests due to the enormous slowdown they cause. In unit tests this is not a problem, and also not in kernel tests if there is only little data to test, but if we are doing functional tests with a lot of data we shouldn't use them. Adding multiple minutes to every single test run on the bot is a poor tradeoff for the luxury of being able to use this new feature.
It is an accepted pattern in core to run multiple slow tests in a single setup without data providers to speed up the test runs, see for example
EntityTranslationTest
andMenuRouterTest
.Comment #111
pfrenssenReviewed the patch, this is getting very close to being perfect again, found some nitpicks:
Maybe move this property underneath the
$adminUser
property to keep them together.This call to
$this->drupalLogin()
is not needed, at the start of the test the user is already logged in.Very minor remark, I would move this up a few lines so it sits underneath the other user that is created.
This
yield
is very cool!This documentation is incomplete. The descriptions are missing, as well as the type hint of the second argument.
I would rewrite this "no matter what" to "regardless of"
Comment #112
gnugetNew patch, this should address all the points mentioned in #111
I just have a doubt about the
$link_type
type hint, that argument is an hexadecimal number (see LinkItemInterface) but accord with the Drupal's documentationBut a hexadecimal number is not a primitive type accord with the php's documentation.
And I think is not a PHP built-in type nor a PHP class... so I'm not so sure what put there, for now, I put int, I can change it if necessary.
patch attached.
Thanks for the reviews!
Comment #113
pfrenssenPatch looks perfect now, thanks for the quick fix!
That's completely correct!
An integer is any "whole" number without a fraction. It doesn't matter in which numeric system it has been defined. When a variable is assigned an integer (or a boolean) PHP stores it internally as a "long" data type, inside a "zval" object. It doesn't matter whether the original value was decimal, hexadecimal, binary or octal. In the end it's just a number that is stored in 64 bits of memory.
Here is how you can see how PHP handles hexadecimal values:
If you are interested in how PHP deals with numbers I can highly recommend this blog post: Internal value representation in PHP 7.
Comment #114
xjmBummer about the test run time. I thought browser tests were significantly faster than web tests... oh well.
Comment #115
xjmSo, the
randomMachineName()
exists in HEAD. However, we're now adding anassertNoSomething()
. That's a combination that can cause random test failures when the random-thing matches the assert-no-thing.In this case, none of the texts we're asserting the absence of are eight characters long, so I think it's okay for this to go in as-is, and I don't want to delay this issue further since I already did so with the data provider distraction. However, for future reference, we should be avoid random usage because of the risk of random failures. Edit: That's discussed in #2571183: Deprecate random() usage in tests to avoid random test failures. However, another concern related to that...
This is a whole lot of abstraction, plus an xpath, plus coupling the test to CSS and markup that may change in the future. It's also fragile... presumably these texts should exist nowhere on the page, but if we change the markup and use the negative assertions so specifically tied to xpath, they will give false positives if/when the markup changes in the future.
It looks like this was added in #82 by @pfrenssen:
But that's not clear to me why it merits all the extra code nor the risk of false positives in the future.
This issue does not need further manual testing unless the solution also changes; all the recent changes are only to automated tests. :) Thanks!
Comment #116
pfrenssenI think testing both the presence and absence of the different messages is worthwhile since we have options to show them or not. If we only test if they are present when they should then we might have a bug in the future where the wrong messages are showing up and we won't know about it.
I agree fully on the random naming, but matching on the field wrappers is fine I think. The base field templates are not likely to change in core because it would break the custom theming and JS of all websites that use forms. The Form system itself uses XPath and the "edit-" prefix in their tests to identify fields and field wrappers, so we should be pretty OK. See for example the tests in
\Drupal\Tests\system\Functional\Form\ElementTest
, they are very similar.Would you be OK if we hardcode unique field names in the test instead of using random names? I think this would also mitigate the risk of tests breaking due to collisions with CSS IDs that may be added in the markup in the future.
Comment #117
pfrenssenUpdated the patch to use predictable machine names, to reduce the chance of random failures. Also updated the XPath call to use an argument for the dynamic part.
Comment #118
pfrenssenI just had a final look at the interdiff and I noticed that we are testing if the field is contained in a <div> element. I somehow missed this before. This is brittle and likely to change to a more specific HTML tag in the future. We should only check the ID.
Comment #119
gnugetThis looks RTBC to me.
Does it need something else?
Thanks for your help pfrenssen.
Comment #120
DuaelFrThe patch from #118 looks RTBC'able to me. After an extensive review, I have two nitpicks, fixed in the attached patch, though:
As @xjm told above, we should not use random strings to avoid random failures. As I had to work on the patch anyway (see below), I changed this to a predictable string.
$test_case
is never ever set so I removed this dead code to avoid confusion.If the bot goes green again, one should mark this issue RTBC, I think.
Comment #121
gnugetThanks!
Comment #122
Gábor HojtsyComment #123
Gábor HojtsyReviewed the patch and even more so the discussion above, which was plentiful to say the least. This issue is a whos-who of Drupal :) All the concerns raised recently have been resolved and this approach had signoff and positive feedback from subsystem maintainers above as well.
I found this little issue with the latest changes though:
This seems to be a refactoring artifact, the method does have a $label argument and the method is invoked on multiple test cases. So this was meant to be $label apparently.
Comment #124
gnugetThanks a lot, Gábor.
New patch attached.
Comment #125
Lendude@Gábor Hojtsy nice catch!
Feedback has been addressed, back to RTBC.
Comment #127
Gábor HojtsyI did not identify this before, failed as I wanted to commit it. Fixed before commit.
Thanks all for working on this and trying different approaches!
Comment #131
botanic_spark CreditAttribution: botanic_spark at Develomon for FFW commented@Gábor Hojtsy Why is this reverted on 8.4?