Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
shortcut.module
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
31 Jan 2014 at 12:45 UTC
Updated:
29 Jul 2014 at 23:20 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
kartagisComment #2
nnevillFor some reason parameter name is empty here:
$name = $request->query->get('name');Comment #3
swentel commentedComment #4
dawehnerMaybe we should add a test here?
Comment #5
swentel commentedYeah, probably, just wan't sure if this was the 'right' way.
Comment #6
jhodgdonThis is actually a critical bug.
What is actually happening is that when you click the "add to shortcuts" contextual link, a link item is added to your Shortcuts, but it is added with an empty link title. This makes the shortcut completely unusable -- the link "shows" in the Shortcuts bar but as it has no link title, there is nothing to click.
Therefore this is a critical or at least major issue, because the normal UI for adding shortcuts (via contextual links) is totally broken.
I just ran into this today on a new install of the latest DEV code. It is still an issue. I saw it a few days ago too, but it wasn't present a week or two ago, so I think it is a recent regression.
The patch in #3 does fix the issue, when tested manually. However, I have marked this "needs work" because it definitely needs a test (and how in the world did there not manage to be a test for this in the testing suite already? It seems like pretty basic behavior of the Shortcut module?).
Comment #7
benjy commentedI also came across this issue and had the same fix. Attached is the fix + a test.
I also fixed an indent issue.
Comment #9
kartagisThe patch from #3 seems to work for me.
Comment #10
jhodgdonThe test doesn't really test the behavior fully. It's certainly better than nothing, and it does fail without the patch, but it doesn't really test the fundamental behavior from a user perspective.
I would like to see a functional test that clicks on that "add shortcut" link, then goes to a different page and verifies that the shortcut link is actually displayed. Shouldn't be too hard... and it would prevent other regressions from breaking the real expected beahvior.
Comment #11
jhodgdonComment #12
chrischinchilla commentedWorking on this at DrupalSouth code sprint…
Comment #13
chrischinchilla commentedI think this is is, the first test I've written for Drupal 8, so may not be best practises etc…
Comment #14
benjy commentedSetting to NR for the testbot, not sure about the patch in #13 since it doesn't actually include the fix.
Comment #16
jhodgdonThanks for the test in #13! The patch didn't apply, so the test didn't run...
It doesn't look quite right to me though:
- Is that really the link title of the link that is clicked to add a shortcut? When I look at the HTML source of the Structure admin page, it looks like the content inside the A link is:
Which, sadly, is unlikely to be very easy to click using clickLink().
Which means probably what we'd need to do is an xpath query. Looking at what clickLink() does:
So probably what we could do is an xpath... The link is in:
So maybe it would be an xpath on 'div.add-shortcut a' (I am not up on xpath syntax but that is what it would be for a CSS selector, maybe someone can turn that into a working test?)
- I think the test would be more convincing if after adding the shortcut, you did a drupalGet to go to a different page, such as maybe admin/config, and make sure the shortcut is still visible there.
Comment #17
chakrapani commentedWorking on this..
Comment #18
chakrapani commentedHere we go. Adding both PASS and FAIL patches with and without the Fix respectively.
interdiff(7-18) is same for both PASS and FAIL.
Made the following changes:
Comment #19
chakrapani commentedSorry, there was one white space in the earlier patches(#18). Adding the latest ones removing the white space.
Comment #24
chakrapani commentedforgot to include 'Drupal\Component\Utility\String' Re-rolling again from #19.
Ran the tests locally this time..and passed. Lets see what the test bot has to say.
Comment #25
jhodgdonWell, the "Fail" test didn't fail. There must be something wrong with the test, because what it is supposed to be testing fails when you do it manually.
Comment #26
chakrapani commentedjhoddon, Yes it is probably because of the following which checks for the Structure link. But there will be another Structure link which is part of Admin links(Manage toolbar section):
$this->assertLink('Structure', 0, 'Added Shortcut found on page');
I will add a specific test to check the presence of the Structure (added shortcut) in the shortcuts toolbar.
Comment #27
jhodgdonYes, I just came to the same conclusion about why the test is passing.
An even easier solution would be to make the shortcut from a different page that is not shown in the Manage menu, such as the Cron settings page or something like that.
Comment #28
chakrapani commentedYes, I was thinking about the same as well. But, If we can write a test which is foolproof irrespective of other links on the page that would be great.
In case that's not possible, I'll go with the alternative.
Comment #29
jhodgdonOn the other hand, a very clear test that doesn't require a lot of work to read the code and understand is also good. If you have to have a lot of logic to detect that the correct link is there, the test code becomes harder to understand.
Comment #30
chakrapani commentedjhodgdon, fair enough :)
Made the following changes to the test:
Comment #32
chakrapani commentedSetting to Needs Review as the FAIL patch was meant to FAIL.
Comment #33
jhodgdonExcellent work!
- I looked at the test results and agree the FAIL patch failed on the expected line, so it reproduces the bug.
- The PASS test passed.
- I had previously manually tested the code patch and it worked fine.
- The code in the test and patch seems clean to me and is well-commented.
Let's get this in!
Comment #34
star-szrCouple minor things that can be fixed up before commit.
theme_enable() is deprecated.
Missing a space after the //
Comment #35
chakrapani commentedCottser, thanks for the comments, I will make the changes..
Comment #36
chakrapani commentedHere we go..made the changes suggested in #34
interdiff is same for both PASS and FAIL patches.
Comment #37
jhodgdonLooks right. Assuming the testbot still agrees on the FAIL/PASS, this should be back to RTBC. Thanks Cottser for noticing those issues!
Comment #40
star-szrC'mon testbot!
Comment #41
webchickWoah, what? :) Do we actually need to replicate clickLink() in its entirety? We already asserted two lines above this that the link exists. So all the conditionals to check if it exists or not seem like wasted processing. We also don't need to assert that a link was clicked; if $this->drupalGet($url_target); succeeds, then the link was clicked.
In either case, though, we should definitely add a comment there explaining why we do not clickLink and be done. #16 was a difficult easter egg to find.
Comment #42
xjmThanks @chakrapani! In addition to @webchick's feedback, here are a couple minor things I noticed.
Some weird capitalization here.
This function is deprecated. https://api.drupal.org/api/drupal/core%21includes%21theme.inc/function/t...
Is there a reason we're still using it here?
This comment is also wrapping too early. :)
Missing space between the // and "Test" here.
Comment #43
star-szrI think #42 is reviewing an older version of the patch, at least 2 and 4 have been fixed as far as I can tell - see my review in #34 (@xjm taught me well!)
Comment #44
xjmWhoops, yep, @Cottser is correct -- #2 and 4 from my comment have already been fixed. :) Sorry for the noise!
Comment #45
longwaveIt is not difficult to use clickLink() here - the XPath normalize-space() function strips tags and whitespace so we can just search for the text inside the link.
The attached patch takes a slightly simpler approach, using clickLink(), and improving testShortcutQuickLink() to actually test the link functionality (previously it only checked that the "Remove" link appeared on the page).
edit: patch has wrong filename because xjm posted while I was preparing it :)
Comment #46
jhodgdonThis changed one important thing about the previous test: it would be more convincing to go to a different page in order to verify that the shortcut link was actually created, and then after removing it, again go that different page to verify it is gone.
Also, since you created a new test here, uploading a test-only patch so we can verify that it actually fails (and in the right places) without the patch would be helpful.
Comment #47
longwaveI am not sure I see the benefit in this, I think testing that the shortcut appears or disappears from the page immediately is better, as this is the expected behaviour - for example, there could be a caching issue that means it doesn't appear until the second page load. However, the attached patches now test both the immediate page and a different one.
Comment #49
star-szrComment #50
jhodgdonLooks good. Thanks for indulging me. The reason I prefer to verify on a separate page is that there could be a link in the current page with the same name, and assertLink('Cron') is not very specific. Previous test versions above suffered from a similar problem, because they added the link on the Structure page, and assertLink('Structure') exists due to the Tools menu.
So. I think this is ready to go. The tests on the FAIL patch failed in the right places (in addition to some unrelated testbot problems that we can just ignore), and the PASS patch passed. Also, the patch itself had been manually tested previously. Thanks!
Comment #51
longwave@jhodgdon: The new tests mitigate against that scenario somewhat by explicitly using assertNoLink to test the link is gone immediately after removing it, but I guess having both tests can't hurt.
Comment #52
webchickOk, awesome. The test is much easier to follow now. Let's get this sucker in!
Committed and pushed to 8.x. Thanks!