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
Comment #1
ricovandevin commentedI'll have a look at this issue now.
Comment #2
ricovandevin commentedThis patch should fix the problem. It does not include any tests.
Comment #3
arla commentedWhere did that second parameter come from? :)
Comment #4
ricovandevin commentedWell... 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.
Comment #5
arla commentedNice. 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.
Comment #6
alexpottMissing help text that is added by a user needs testing.
Comment #7
firfin commentedGonna try writing a test.
Comment #8
ricovandevin commentedMaybe we should decouple bug fixing and writing tests. In my opinion a missing test is a separate issue. Isn't it?
Comment #9
arla commentedI 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.
Comment #10
ricovandevin commentedI'll contact firfin about the status of the test.
Comment #11
ricovandevin commentedNo reaction from firfin. I'll try to write a test.
Comment #12
tibbsa commentedNo, 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.
Comment #13
ricovandevin commentedI'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.
Comment #14
ricovandevin commentedI'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.
Comment #15
arla commentedYeah, 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.
Not used?
Missing {@inheritdoc} comment.
Pasted from somewhere else? Should match the actual test :)
Comment #16
ricovandevin commentedI'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.
Comment #17
ricovandevin commentedMaybe the patch will be reviewed sooner when I remove the assignment.
Comment #18
tibbsa commentedI'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.
Comment #19
tibbsa commentedAhem. Diff'd and submitted from one revision too early, before I fixed up the comments.
Comment #20
ricovandevin commentedIn my opinion the suggested changes are fair. Little remark about coding standards:
I don't think there should be spaces after the method names.
I'll try to test the re-factored patch later today.
Comment #21
tibbsa commentedYou'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.
Comment #22
ricovandevin commentedThe re-factored patch is working. When the spaces mentioned in comment #20 are removed we can make the patch RTBC.
Comment #23
tibbsa commentedSetting to review to get the testbot on board for a final check before RTBC, but the changes in this patch are minimal.
Comment #24
arla commentedI'm going to be picky...
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.
Comment #25
tibbsa commentedThe 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):
Comment #26
arla commentedThere 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.
Comment #27
ricovandevin commentedHope this one satisfies everybody! :)
Comment #29
ricovandevin commentedOk... I did that previous one to quickly...
Comment #30
ricovandevin commentedComment #31
tibbsa commentedLooks good to me.
Comment #32
ricovandevin commentedIf 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.
Comment #33
tibbsa commentedComment #34
alexpottThis could be just
$type = NodeType::load($node->getType());- no need for the extra variable here.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.
Comment #35
tibbsa commentedRevised patch attached.
Comment #36
ricovandevin commentedPatch is working as expected. Changes as suggested by alexpott are included.
Comment #37
alexpottThis 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!