I am using the CommentTestTrait within my own module's tests. In one of my tests I utilize the addDefaultCommentField function with a newly created comment type that is NOT "comment".
Steps to Reproduce (within a test case)
- Create a new comment type entity (same as createCommentType in Comment base test class)
- Use drupalCreateContentType to create a new node bundle
- Use "AddDefaultCommentField" passing in the default field name "comment" and the new type id for $comment_type_id from step 1
- Use drupalCreateNode to create a new node of the new node bundle from step 2
- Use drupalGet to access the node's page
Expected Behavior
The form id for the comment form shown should be "comment_{comment_type_id}_form" where {comment_type_id} is the id of the comment created in step 1.
Actual Behavior
The form id for the comment form is "comment_comment_form"
Alternate Steps
In step 3 above, pass the $comment_type_id as the default field name and then the expected behavior occurs. This doesn't seem right, however, because when I do these steps manually through the Drupal interface, I see that the comment form id is based on the comment type id, not on the field name of the comments within the node.
Comments
Comment #12
catchThe docs are fairly clear what happens here, you have to pass a field name explicitly if you want something else. Marking as 'works as designed'. The UI is a bit different because it's trying to namespace things, the test trait doesn't do as much for you, but that's because it's for tests.
https://api.drupal.org/api/drupal/core%21modules%21comment%21src%21Tests...