This issue is for a new student in MD Systems, don't do it if it wasn't assigned to you

Problem/Motivation

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):

Proposed resolution

Write Tests and fix it.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

nick.james created an issue. See original summary.

nick.james’s picture

StatusFileSize
new3.07 KB
miro_dietiker’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: diff-breadcrumb-2718381-D8.patch, failed testing.

miro_dietiker’s picture

The 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:

+++ b/src/Controller/NodeRevisionController.php
@@ -42,24 +42,20 @@ class NodeRevisionController extends EntityComparisonBase {
-  public function compareNodeRevisions(NodeInterface $node, $left_vid, $right_vid, $filter) {
+  public function compareNodeRevisions(NodeInterface $node, $left_vid, $right_vid) {
..
+    $filter = \Drupal::request()->query->get('query');

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.

MatejZmitko’s picture

Assigned: Unassigned » MatejZmitko

As 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.

Bambell’s picture

@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.

jonathanshaw’s picture

I suggest postponing the fix part of the patch until after #2759627: Remove redundant NodeRevisionController is addressed.

johnchque’s picture

Version: 8.x-1.0-alpha2 » 8.x-1.x-dev
Issue summary: View changes
StatusFileSize
new31.9 KB
new31.61 KB

Let's explain the issue better. Bug reports go always to the dev version.

johnchque’s picture

Issue summary: View changes
MatejZmitko’s picture

StatusFileSize
new697 bytes
Bambell’s picture

As 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.

johnchque’s picture

Status: Needs work » Needs review

Always set the issue as needs review after upload a patch.

Status: Needs review » Needs work

The last submitted patch, 11: 2718381-11.patch, failed testing.

MatejZmitko’s picture

Status: Needs work » Needs review
StatusFileSize
new1.63 KB

Status: Needs review » Needs work

The last submitted patch, 15: 2718381-12.patch, failed testing.

Bambell’s picture

Status: Needs work » Needs review

Hi @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 $nid1 is 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 :

// Make sure only two revisions available.
$this->assertEqual(count($rows), 2);

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.

Bambell’s picture

Status: Needs review » Needs work
MatejZmitko’s picture

Status: Needs work » Needs review
StatusFileSize
new1.24 KB

Status: Needs review » Needs work

The last submitted patch, 19: 2717381-19.patch, failed testing.

Bambell’s picture

Hi @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 ;-).

MatejZmitko’s picture

StatusFileSize
new1.23 KB
MatejZmitko’s picture

Status: Needs work » Needs review
Bambell’s picture

Status: Needs review » Needs work
  1. +++ b/src/Tests/DiffRevisionTest.php
    @@ -78,6 +80,16 @@ class DiffRevisionTest extends WebTestBase {
    +    $admin = $home + array('admin' => t('Administration'));
    

    As per documentation, assertBreadcrumb takes 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 > Bar

    With Foo linking to path foo and Bar linking to path foo/bar.

    The associative array passed to assertBreadcrumb would take the following form :

    [
      'foo' => 'Foo',
      'foo/bar' => 'Bar'
    ]

    In that specific case, I'm not seeing Administration in the breadcrumb.

    Also, I understand that your code was copied from elsewhere, which is fine, but please construct your $trail array as I've shown above. The shortened [] array syntax should be used in place of array().

  2. +++ b/src/Tests/DiffRevisionTest.php
    @@ -78,6 +80,16 @@ class DiffRevisionTest extends WebTestBase {
    +    $this->assertBreadcrumb("node/$nid1/revisions/view/1/2?query=raw", $trail);
    +    $this->assertBreadcrumb("node/$nid1/revisions/view/1/2?query=raw-plain", $trail);
    

    This is not going to work; the query parameter will be ignored. Please enable clean URLs on your Drupal installation.

MatejZmitko’s picture

Status: Needs work » Needs review
StatusFileSize
new1.17 KB

I have modified my $trail array according to suggestions above and also edited function assertBreadcrumb().

Bambell’s picture

Hi @MatejZmitko. Nice progress. Here are some feedbacks :

  1. +++ b/src/Tests/DiffRevisionTest.php
    @@ -78,6 +80,14 @@ class DiffRevisionTest extends WebTestBase {
    +    $trail = [ 'home' => 'Home',
    +        "home/$nid1" => "$nid1",
    +        "home/$nid1/revisions" => 'Revisions'
    

    Those urls look wrong. When you mouse over each breadcrumb element, does the url you see contains "home"?

  2. +++ b/src/Tests/DiffRevisionTest.php
    @@ -78,6 +80,14 @@ class DiffRevisionTest extends WebTestBase {
    +    $this->assertBreadcrumb("node/$nid1/revisions/view/1/2raw-plain", $trail);
    +    $this->assertBreadcrumb("node/$nid1/revisions/view/1/2raw", $trail);
    

    A forward slash is missing between the second revision id and "raw" or "raw-plain". Also, are you expecting both assertions to pass?

Bambell’s picture

Status: Needs review » Needs work

[...] and also edited function assertBreadcrumb()

Did 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 calls assertBreadcrumbParts() and then loops over $parts provided by getBreadcrumbParts(). 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 $parts if 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.

MatejZmitko’s picture

Hello @Bambell. Thanks for the feedback, I am going to look into it and have in mind your advises.

MatejZmitko’s picture

Status: Needs work » Needs review
StatusFileSize
new1.2 KB

I'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?

Bambell’s picture

StatusFileSize
new4.52 KB
new1.45 KB
new1.45 KB
new1.44 KB

As mentioned in #24, the $trail elements' 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-plain was indeed expected.

Status: Needs review » Needs work

The last submitted patch, 30: incorrect_breadcrumb-2718381-30-test-only.patch, failed testing.

johnchque’s picture

Status: Needs work » Reviewed & tested by the community

Looks good.

johnchque’s picture

Status: Reviewed & tested by the community » Needs work

Sorry, my bad. We still need to find a way to have a better patch.

brenk28’s picture

StatusFileSize
new5.13 KB

Commit 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.

brenk28’s picture

Status: Needs work » Needs review
miro_dietiker’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

If 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.

+++ b/src/Controller/GenericRevisionController.php
@@ -95,26 +105,19 @@ class GenericRevisionController extends ControllerBase {
-  public function compareEntityRevisions(RouteMatchInterface $route_match, EntityInterface $left_revision, EntityInterface $right_revision, $filter) {
+  public function compareEntityRevisions(RouteMatchInterface $route_match, EntityInterface $left_revision, EntityInterface $right_revision) {

The behavior of this method varies based on the filter. Why remove it from the signature?

johnchque’s picture

It varies yes, it will even more with the new layout plugin system. Should we then add a breadcrumb builder?

miro_dietiker’s picture

Hm, 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.

miro_dietiker’s picture

Status: Needs work » Postponed

Postponing for now to avoid conflicts.

johnchque’s picture

Status: Postponed » Active

After testing a bit I think this breadcrumb builder can be removed.

johnchque’s picture

Assigned: MatejZmitko » johnchque
Status: Active » Needs review
StatusFileSize
new4.31 KB

Let's see if this passes tests.

miro_dietiker’s picture

Status: Needs review » Fixed
Issue tags: -Needs tests

Aaand committed, keeping everyone attributed for all the hard work and discussions. :-)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.