Problem/Motivation

node_help() does this:

$type = $node->getType();
return (!empty($type->help) ? Xss::filterAdmin($type->help) : '');

$node->getType() returns the name of the node type, as a string. The next line assumes $type is a NodeType object. As a result, no help text is displayed.

Note that the default node types (article and page) don't have any help text by default, so to make the problem visible you have to add one (on admin/structure/types/manage/article)

Proposed resolution

Do NodeType::load($type) or so.

Also, does it make sense to test the presence of the help text? I cannot find any test like that in Core...

Remaining tasks

Fix and perhaps add test coverage.

User interface changes

The help text will be visible again :D

API changes

None

Comments

ricovandevin’s picture

Assigned: Unassigned » ricovandevin

I'll have a look at this issue now.

ricovandevin’s picture

Assigned: ricovandevin » Unassigned
Status: Active » Needs review
StatusFileSize
new573 bytes

This patch should fix the problem. It does not include any tests.

arla’s picture

Status: Needs review » Needs work
+++ b/core/modules/node/node.module
@@ -121,7 +121,8 @@ function node_help($route_name, RouteMatchInterface $route_match) {
+      $type = NodeType::load($type_name, 'type');

Where did that second parameter come from? :)

ricovandevin’s picture

Status: Needs work » Needs review
StatusFileSize
new565 bytes

Well... I'm a bit confused. The first time I tested without the second parameter it resulted in an exception. Then I added that parameter (since in some other frameworks the second parameter of a class load function selects the field that is used for selection) and it worked. :-)

I've now retested without the second parameter and it works well now. The source of the exception must have been something else.

arla’s picture

Status: Needs review » Reviewed & tested by the community

Nice. I think it's okay for me to RTBC for such a small fix.

And, about testing with WebTestBase, I realised that you would to enable the help and block modules, plus a theme, and it seems like it's just not worth it.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Missing help text that is added by a user needs testing.

firfin’s picture

Assigned: Unassigned » firfin

Gonna try writing a test.

ricovandevin’s picture

Maybe we should decouple bug fixing and writing tests. In my opinion a missing test is a separate issue. Isn't it?

arla’s picture

I don't think including a test in this issue is a problem. From what I have seen, coupling tests with features/fixes is just what we want to do.

ricovandevin’s picture

I'll contact firfin about the status of the test.

ricovandevin’s picture

Assigned: firfin » ricovandevin

No reaction from firfin. I'll try to write a test.

tibbsa’s picture

No, tests should not be separate issues. While we're not quite doing test-driven development here, generally it is best and easiest to write the test when you're fully "up" on exactly what is supposed to happen here. If someone else writes the test later, months down the road perhaps, they may not realize that the code is not in fact doing what it is supposed to be doing, and basically write a test to confirm that the broken code continues to be broken.

ricovandevin’s picture

StatusFileSize
new2.61 KB

I've written a test but it keeps failing. I guess the problem is that the help text is not added to the content type that is created by the test. Anybody a clue about how to do this in a test?

In the patch the fix and the test I've written.

ricovandevin’s picture

I've done some more research and I've found that the help is in fact added to the content type config. So now my guess is that the problem is in activating the Bartik theme.

arla’s picture

Yeah, when I run the test, the Bartik theme does not seem to be active. I think you also have to add the Help block to the theme.

  1. +++ b/core/modules/node/src/Tests/NodeShowHelpTextTest.php
    @@ -0,0 +1,82 @@
    +  /**
    +   * An associative array of settings for themes.
    +   *
    +   * @var array
    +   */
    +  protected $themes;
    

    Not used?

  2. +++ b/core/modules/node/src/Tests/NodeShowHelpTextTest.php
    @@ -0,0 +1,82 @@
    +  protected function setUp() {
    

    Missing {@inheritdoc} comment.

  3. +++ b/core/modules/node/src/Tests/NodeShowHelpTextTest.php
    @@ -0,0 +1,82 @@
    +   * Logs in users, creates dblog events, and tests dblog functionality.
    

    Pasted from somewhere else? Should match the actual test :)

ricovandevin’s picture

Status: Needs work » Needs review
StatusFileSize
new2.67 KB

I've changed the test to use the standard profile instead of the testing profile and now it is working. But because it uses that standard profile it is quite slow so I don't know whether I've taken the best approach.

I've tried to enable Bartik in the test with the testing profile (installed it and set it as default) but the forms where still showing in the Classy theme. Since the test with the standard profile is working I leave it this way for the moment. If there are any suggestions to improve the test I'm happy to hear and learn.

ricovandevin’s picture

Assigned: ricovandevin » Unassigned

Maybe the patch will be reviewed sooner when I remove the assignment.

tibbsa’s picture

StatusFileSize
new2.7 KB
new2.78 KB

I've refactored this a bit and made it work using the 'testing' profile. I have only limited experience writing tests for Drupal and so this was a bit of a learning experience, but I believe it works and I believe the refactoring is appropriate. Someone who knows better can tell us otherwise later. ;)

The changes I've suggested include the following.

First, setting up the content type has been moved to setUp() since we're not actually testing 'creation of a node type' or 'creation of a node type with help text' -- only that the help text is ultimately displayed if a block is available to display it. Logically, this is in the nature of 'setup' and not 'testing' as a result. (This necessitated creating the $testType and $testText properties.)

Second, $adminUser need not be a class property as it is never used outside of setUp(). I know that many of the tests set $this->adminUser and $this->webUser, but in many cases there seems to be no point to doing so and I don't think we should continue the practice 'just because', unless someone can tell me a good reason for doing so.

Testbot should be happy with this, but let's see what other reviewers think, too.

tibbsa’s picture

Ahem. Diff'd and submitted from one revision too early, before I fixed up the comments.

ricovandevin’s picture

In my opinion the suggested changes are fair. Little remark about coding standards:

+    $this->drupalLogin ($admin_user);
+    $this->drupalPlaceBlock ('system_help_block');

I don't think there should be spaces after the method names.

I'll try to test the re-factored patch later today.

tibbsa’s picture

You're right on the coding standards issue. I'll wait on fixing that until your testing is complete in case something else needs tweaking besides that ditty.

ricovandevin’s picture

Status: Needs review » Needs work

The re-factored patch is working. When the spaces mentioned in comment #20 are removed we can make the patch RTBC.

tibbsa’s picture

Status: Needs work » Needs review
StatusFileSize
new2.69 KB

Setting to review to get the testbot on board for a final check before RTBC, but the changes in this patch are minimal.

diff --git a/core/modules/node/src/Tests/NodeShowHelpTextTest.php b/core/modules/node/src/Tests/NodeShowHelpTextTest.php
index 8e66543..f33b180 100644
--- a/core/modules/node/src/Tests/NodeShowHelpTextTest.php
+++ b/core/modules/node/src/Tests/NodeShowHelpTextTest.php
@@ -50,8 +50,8 @@ protected function setUp() {
       'bypass node access',
     ));

-    $this->drupalLogin ($admin_user);
-    $this->drupalPlaceBlock ('system_help_block');
+    $this->drupalLogin($admin_user);
+    $this->drupalPlaceBlock('system_help_block');

     $this->testType = 'type';
     $this->testText = t('Help text to find on node forms.');
arla’s picture

Status: Needs review » Needs work

I'm going to be picky...

+++ b/core/modules/node/src/Tests/NodeShowHelpTextTest.php
@@ -0,0 +1,82 @@
+   * Verifies that the 'testing' help text appears on the "node add" and
+   * "node edit" forms for the test content type.

Doc comments should have a brief summary on a single line. If one line is not informative enough, you can put more details after another blank line.

tibbsa’s picture

The class-level description is sufficient to document "what it does" in any event, and duplicating the same for that function isn't likely to add anything IMO. Suggested revision (not submitting a patch in case there is vehement disagreement on this point):

diff --git a/core/modules/node/src/Tests/NodeShowHelpTextTest.php b/core/modules/node/src/Tests/NodeShowHelpTextTest.php
index f33b180..59dc436 100644
--- a/core/modules/node/src/Tests/NodeShowHelpTextTest.php
+++ b/core/modules/node/src/Tests/NodeShowHelpTextTest.php
@@ -10,7 +10,7 @@
 use Drupal\simpletest\WebTestBase;

 /**
- * Verify that a help text is shown on node forms.
+ * Verify that content-type specific help text appears on node add/edit forms.
  *
  * @group node
  */
@@ -63,10 +63,6 @@ protected function setUp() {
     ));
   }

-  /**
-   * Verifies that the 'testing' help text appears on the "node add" and
-   * "node edit" forms for the test content type.
-   */
   public function testNodeShowHelpText() {
arla’s picture

There should still be a comment for the method, but I agree that it is a bit silly to document the class and the method with virtually the same sentence.

How about renaming the class to the more general NodeHelpTest, change the class comment to "Tests help functionality for nodes." and the method comment to "Verifies that help text appears on node add/edit forms." or so.

ricovandevin’s picture

Status: Needs work » Needs review
StatusFileSize
new2.57 KB

Hope this one satisfies everybody! :)

Status: Needs review » Needs work

The last submitted patch, 27: fix-help-node-edit-form-2379595-27.patch, failed testing.

ricovandevin’s picture

StatusFileSize
new2.57 KB

Ok... I did that previous one to quickly...

ricovandevin’s picture

Status: Needs work » Needs review
tibbsa’s picture

Looks good to me.

ricovandevin’s picture

If you are confident that the fix and the test in the patch are working and code and comments are according to the coding standards you can set the issue to RTBC.

tibbsa’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs tests
  1. +++ b/core/modules/node/node.module
    @@ -121,7 +121,8 @@ function node_help($route_name, RouteMatchInterface $route_match) {
    -      $type = $node->getType();
    +      $type_name = $node->getType();
    +      $type = NodeType::load($type_name);
    

    This could be just $type = NodeType::load($node->getType()); - no need for the extra variable here.

  2. +++ b/core/modules/node/src/Tests/NodeHelpTest.php
    @@ -0,0 +1,81 @@
    +    $this->assertText($this->testText, 'Help text is found on node add form.');
    ...
    +    $this->assertText($this->testText, 'Help text is found on node edit form.');
    

    No need to provide the 'Help text is found on node edit form.' message - the default assertion message is actually more useful to a developer when this test fails.

tibbsa’s picture

Status: Needs work » Needs review
StatusFileSize
new2.46 KB

Revised patch attached.

ricovandevin’s picture

Status: Needs review » Reviewed & tested by the community

Patch is working as expected. Changes as suggested by alexpott are included.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed 02c173e and pushed to 8.0.x. Thanks!

  • alexpott committed 02c173e on 8.0.x
    Issue #2379595 by ricovandevin, tibbsa: node_help() broken for node add/...

Status: Fixed » Closed (fixed)

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