Working on tests for #2422353: Comment module should check that comment body field exists Ifound that this assertion is wring because path for reply is wrong
Also messages needs fix too

-    $this->drupalGet('comment/reply/entity_test/comment/' . $new_entity->id());
-    $this->assertNoFieldByName('subject[0][value]', '', 'Subject field found.');
-    $this->assertNoFieldByName('comment_body[0][value]', '', 'Comment field found.');
+    $this->drupalGet('comment/reply/entity_test/' . $new_entity->id() . '/comment');
+    $this->assertResponse(200);
+    $this->assertNoFieldByName('subject[0][value]', '', 'Subject field not found.');
+    $this->assertNoFieldByName('comment_body[0][value]', '', 'Comment field not found.');

The problem here that this page exposes 3 comment forms, so this assertions should use needed form only

Here a screenshot of the below step $this->drupalGet('comment/reply/entity_test/comment/' . $new_entity->id()); in the current codebase:

Current verbose screenshot

Actual reply with 3 comment forms:

Comments

andypost’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 1.patch, failed testing.

nlisgo’s picture

Issue summary: View changes
StatusFileSize
new83.65 KB
nlisgo’s picture

Status: Needs work » Needs review
StatusFileSize
new808 bytes
new1005 bytes

As the subject and comment body fields are appearing either this is a bug or the appearance of these fields is expected behaviour. Perhaps the messages did not need fixing but the assertions did.

andypost’s picture

Status: Needs review » Needs work

@nlisgo Yes, that I exactly talking about! if you take #3 screenshot after patching you still see the 2 comment forms

The test should make sure that comments hidden when field settings changed to hidden ($this->assertFieldChecked('edit-field-foobar-0-status-2'); before the changed hunk)

But the page we are using have 3 comment fields, so patch should remove unneeded fields to test properly that comments and form are hidden

nlisgo’s picture

OK, I think I know what the expected behaviour is now. I will adjust the patch accordingly.

nlisgo’s picture

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

I expect this to fail but would appreciate feedback on the adjustment to the tests that I believe now check the expected behaviour.

There are indeed 3 comment fields for the entity_test entity. The first comment field is of the default comment type and the other comment fields are of the type foobar.

The field settings for the first comment field have been changed to set the comment status to closed.

When a new entity is created of entity_type and we visit the entity manage screen we expect the first comments status to be set to closed.

When we visit the entity page we should not expect to see an add comment form for the first comment field.

Status: Needs review » Needs work

The last submitted patch, 7: commentnonnodetest-2458323-7.patch, failed testing.

nlisgo’s picture

Status: Needs work » Needs review
StatusFileSize
new2.76 KB
new2.71 KB

I added some tests initially for debugging purposes but they are a welcome addition IMO. Basically I wanted to the visit the /entity_test/add screen and see if the comment fields open and closed state was as expected and then create an entity by submitting the form and then visiting the new entity page. These additional tests pass.

There seems to be an issue when trying to create the entity programmatically. I have not been able to recreate this issue outside of the test suite.

Status: Needs review » Needs work

The last submitted patch, 9: commentnonnodetest-2458323-9.patch, failed testing.

nlisgo’s picture

I'm fairly sure that the tests cover the expected behaviour now. Please offer any feedback, however.

I will shift my attention to trying to find out what is going on when the entity is created programmatically here.

The result is that the default value for the comments form status is ignored.

+++ b/core/modules/comment/src/Tests/CommentNonNodeTest.php
@@ -426,18 +426,42 @@ function testCommentFunctionality() {
     $random_label = $this->randomMachineName();
     $data = array('bundle' => 'entity_test', 'name' => $random_label);
     $new_entity = entity_create('entity_test', $data);
     $new_entity->save();
andypost’s picture

Assigned: Unassigned » larowlan
Issue summary: View changes
StatusFileSize
new32.17 KB

@nlisgo test looks great, otoh having 3 comment forms on reply is UX fail.

@larowlan Here's how it looks now (with fixed path)

Do we need to file new issue - do not display other comment forms on comment reply route? Or just re-purpose current?

larowlan’s picture

Assigned: larowlan » Unassigned

Yeah on the reply route we can be smart about this.
We already remove the formatter for the active field to prevent recursion, we should do it for all fields.

nlisgo’s picture

I'm not sure if the discussion about whether we should allow multiple comments fields to be attached or displayed on a single entity belongs here. I'm pretty sure that even if I refactored the tests to only output one comments field form I could reproduce the bug.

Let's take on addressing this bug as the priority and we can open a separate issue if you desire.

nlisgo’s picture

I can confirm that the bug is still present with one comment field.

andypost’s picture

Issue tags: +Usability

@nlisgo When I filed the issue, I thought that need to fix path in drupalGet() for reply form, then discovered that there's 3 comment forms. I think better to re-purpose the issue to fix display of 3 comment forms on reply page, that hunk of test looks like was for that.
I'm going to to grep the code in https://www.drupal.org/sandbox/larowlan/1790736 where we originally introduced this test

EDIT can't find origin of that test, but foobar was added in #2228763: Create a comment-type config entity and use that as comment bundles, require selection in field settings form

EDIT2

git co comment-fieldapi5
git log core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php

this 2 commits introduces that and both from @larowlan

commit 21ead113bd8fbc963809b27e0d08258dbda9a6f0
Author: Lee Rowlands <lee.rowlands@pv>
Date:   Thu Sep 26 08:04:11 2013 +1000

    Fix fails

commit a4a6317aed6685ac9c6e22a898cc7f7995baf717
Author: Lee Rowlands <lee.rowlands@pv>
Date:   Thu Sep 26 07:24:29 2013 +1000

    Moves tests to use entity_test_render
larowlan’s picture

Yes, lets focus on the incorrect url here

nlisgo’s picture

The url appears correct now.

+++ b/core/modules/comment/src/Tests/CommentNonNodeTest.php
@@ -426,18 +426,42 @@ function testCommentFunctionality() {
+    $this->drupalGet('comment/reply/entity_test/' . $new_entity->id() . '/comment');

The url for the reply form is correct now, I believe.

Is the problem that you would not expect to see other comment reply forms (foobar and barfoo) at this url?

The commented entity appears below the comment form, are we to hide all comment fields in the commented entity?

andypost’s picture

Thinking a bit more about, suppose we just need to check that form absent for comment field that we set to closed.
And then in new issue we extend this test to make sure no other forms here

andypost’s picture

Issue tags: +Needs reroll
bfr’s picture

Issue tags: -Needs reroll

The patch applies just fine, no need to reroll.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Version: 8.9.x-dev » 9.4.x-dev
Status: Needs work » Closed (outdated)
Issue tags: +Bug Smash Initiative

@andypost, Thanks for that patch.

It appears that this was fixed as part of #2422353: Comment module should check that comment body field exists.

Therefore, closing as outdated. If this is incorrect reopen the issue, by setting the status to 'Active', and add a comment explaining what still needs to be done.

Thanks!

andypost’s picture

@quietone thank you for triaging