Closed (fixed)
Project:
Diff
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
3 May 2016 at 22:26 UTC
Updated:
26 Sep 2016 at 15:44 UTC
Jump to comment: Most recent, Most recent file
This issue is for a new student in MD Systems, don't do it if it wasn't assigned to you
When navigating to a node revision and selecting the Markdown option, the last item in the bread crumbs is incorrect. The last item should not be Diff General Settings.
Standard option (Correct breadcrumb):

Markdown option (Wrong breadcrumb):

Write Tests and fix it.
| Comment | File | Size | Author |
|---|---|---|---|
| #41 | incorrect_breadcrumb-2718381-41.patch | 4.31 KB | johnchque |
| #34 | diff-breadcrumb-2718381-34.patch | 5.13 KB | brenk28 |
| #30 | incorrect_breadcrumb-2718381-30-test-only.patch | 1.44 KB | Bambell |
| #30 | incorrect_breadcrumb-2718381-30.patch | 4.52 KB | Bambell |
| #9 | Screenshot from 2016-07-05 16:05:16.png | 31.61 KB | johnchque |
Comments
Comment #2
nick.james commentedComment #3
miro_dietikerComment #5
miro_dietikerThe original route looks strange: It allows an argument to cover any filter to then later limit it to two hardcoded values...
However, IMHO the proposed code here makes it worse:
Now suddenly, the code drops a clean filter context that was injected in the API and the code accesses the request object from deeply inside a method that wouldn't have that context anymore.
I think it's important to extract the filter from the query early in the controller and pass it into the methods.
Comment #6
MatejZmitko commentedAs a first step I am going to review a patch, which have been uploaded and verify if the issue has been fixed. Afterwards, I will write a test to cover the case of reproducing a bug further on.
Comment #7
Bambell commented@MatejZmitko, you do not have to review the patch nor understand it, only write a test to cover that case. The test should expose the bug and should pass after the patch is applied.
Comment #8
jonathanshawI suggest postponing the fix part of the patch until after #2759627: Remove redundant NodeRevisionController is addressed.
Comment #9
johnchqueLet's explain the issue better. Bug reports go always to the dev version.
Comment #10
johnchqueComment #11
MatejZmitko commentedComment #12
Bambell commentedAs a work in progress patch, that's heading in the right direction. You are still missing the most important part though : the assertion of the content of the breadcrumb. You also shouldn't have to create a new node / revision. Several revisions are created throughout this test function and deleted to verify that the functionality to delete revisions works properly. It would be better to take advantage of the work that was already done and insert the test somewhere in the function where there is already more than 1 revision.
Comment #13
johnchqueAlways set the issue as needs review after upload a patch.
Comment #15
MatejZmitko commentedComment #17
Bambell commentedHi @MatejZmitko. Looking good. One thing that's currently holding you back and causing your test to fail is that
assertBreadcrumb()is not defined in the current scope of the test function. If you want to use it, you will first need to add this line under the namespace declaration :use Drupal\system\Tests\Menu\AssertBreadcrumbTrait;and this one inside the test class :
use AssertBreadcrumbTrait;You can find an example for this in
Drupal\taxonomy\Tests\TermTranslationTest, for instance.Another thing is that
$nid1is a node id, not a revision id, so that's going to be a problem, here :$this->assertBreadcrumb("node/$nid1/revisions/view/$nid1/$nid1", $trail);The last 2
$nid1's should be revision ids. One thing you can do is to position your test right after the assertion to verify that there are 2 revisions :At this point, the revisions ids are necessarily going to be 1 and 2, since no revision was previously created, so you can hardcode those values in the url.
Comment #18
Bambell commentedComment #19
MatejZmitko commentedComment #21
Bambell commentedHi @MatejZmitko. That's getting close. Now that your test is inserted in the middle of the test function, you should pay close attention not to break tests that will follow yours. In that specific case, the very next line following your code is :
$this->drupalPostForm(NULL, NULL, t('Compare'));As you can see on the tests result page, this is failing, because the "Compare" button that this test was expecting is no longer present. I'll let you figure out why ;-).
Comment #22
MatejZmitko commentedComment #23
MatejZmitko commentedComment #24
Bambell commentedAs per documentation,
assertBreadcrumbtakes an associative array whose elements are keyed by the path of one of the breadcrumb elements and the value is the text of the breadcrumb element. For example, let the following breadcrumb :Foor > BarWith
Foolinking to pathfooandBarlinking to pathfoo/bar.The associative array passed to
assertBreadcrumbwould take the following form :In that specific case, I'm not seeing
Administrationin the breadcrumb.Also, I understand that your code was copied from elsewhere, which is fine, but please construct your
$trailarray as I've shown above. The shortened[]array syntax should be used in place ofarray().This is not going to work; the query parameter will be ignored. Please enable clean URLs on your Drupal installation.
Comment #25
MatejZmitko commentedI have modified my $trail array according to suggestions above and also edited function assertBreadcrumb().
Comment #26
Bambell commentedHi @MatejZmitko. Nice progress. Here are some feedbacks :
Those urls look wrong. When you mouse over each breadcrumb element, does the url you see contains "home"?
A forward slash is missing between the second revision id and "raw" or "raw-plain". Also, are you expecting both assertions to pass?
Comment #27
Bambell commentedDid you edit
Drupal\system\Tests\Menu\AssertBreadcrumbTrait::assertBreadcrumb? This is provided by Core and shouldn't be changed when working on a contributed module such as Diff.assertBreadcrumb()is a bit sneaky. If you look at the implementation, it callsassertBreadcrumbParts()and then loops over$partsprovided bygetBreadcrumbParts(). The assertion is done after the loop, but the only way it can fail is if something goes wrong inside that loop. However,getBreadcrumbParts()won't return any$partsif a breadcrumb isn't found on the page you provide. Thus, as far as I can tell,assertBreadcrumb()will always succeed if you provide a wrong url or if there's no breadcrumb on that page.Comment #28
MatejZmitko commentedHello @Bambell. Thanks for the feedback, I am going to look into it and have in mind your advises.
Comment #29
MatejZmitko commentedI've modified URLs of the $trail array, but assertbreadcrumb() still does not work properly for me. Is that a problem with the button accessibility or the function itself?
Comment #30
Bambell commentedAs mentioned in #24, the
$trailelements' key is the path to the element and the value is the text displayed in the breadcrumb."node/$nid1" => "$nid1",The path is correct, however the text displayed in the breadcrumb isn't the node id, but rather the node label.
There are still also some indentation problems and it would have been interesting to add an assertion to verify that a breadcrumb actually exists on the page, since
assertBreadcrumb()doesn't do so, as I mentioned earlier.Other than that, the patch is correct.
The reason why the assertions were not failing is because the breadcrumb doesn't exist on the page. It has to be first placed using :
$this->drupalPlaceBlock('system_breadcrumb_block');It was possible to notice that the breadcrumb wasn't present by looking at the page rendered during the test. After the test has finished running, from the testing UI, you can click on the tested class (in that case,
Drupal\diff\Tests\DiffRevisionTest) to display detailed test results and clicking on "Verbose message" will show the page visited during the test.I was also wrong to say that specifying the query parameter in the url used for the assertion was wrong. Normally this is filtered, but not after applying #2 patch, so following the initial directives, a url containing
?query=raw-plainwas indeed expected.Comment #32
johnchqueLooks good.
Comment #33
johnchqueSorry, my bad. We still need to find a way to have a better patch.
Comment #34
brenk28 commentedCommit 42b6660 produces:
Warning: array_pop() expects parameter 1 to be array, object given in Drupal\diff\DiffBreadcrumbBuilder->build() (line 29 of diff/src/DiffBreadcrumbBuilder.php).
when comparing revisions and switching to markdown, so taking another stab at this.
Comment #35
brenk28 commentedComment #36
miro_dietikerIf there is a bug, even a fatal error, tests are the most important part.
I'm still not convinced we should switch away from the route argument to a query and no one provided a valid answer until now to my question.
The behavior of this method varies based on the filter. Why remove it from the signature?
Comment #37
johnchqueIt varies yes, it will even more with the new layout plugin system. Should we then add a breadcrumb builder?
Comment #38
miro_dietikerHm, this already overlaps a lot with writing the plugin thing.
I guess we will set this to duplicate once it the plugin is in (and fixes the issue also) to avoid all the conflicts.
Berdir proposed that this is fine and thus avoid having an own breadcrumb builder.
Comment #39
miro_dietikerPostponing for now to avoid conflicts.
Comment #40
johnchqueAfter testing a bit I think this breadcrumb builder can be removed.
Comment #41
johnchqueLet's see if this passes tests.
Comment #42
miro_dietikerAaand committed, keeping everyone attributed for all the hard work and discussions. :-)