Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
In modules/node/src/Tests/NodeTitleTest.php, one of the tests checks if the title is equal to '0'.
$this->assertEqual(current($this->xpath($xpath)), 0, 'Node title is displayed as 0.', 'Node');
This test passes because a title not exist (FALSE), 0 is falsey, and assertEqual considers those to be the same.
$this->assertEqual(FALSE, 0, 'Node title is displayed as 0.', 'Node');
Proposed resolution
Place block title.
$this->drupalPlaceBlock('page_title_block');
Use assertSame() - asserts that two variables have the same type and value.
// Test that 0 appears in the template <h1>.
$this->assertSame($this->xpath('//h1')[0]->getText(), '0');
Remaining tasks
Delete the deprecated code.
Comment | File | Size | Author |
---|---|---|---|
#23 | core_2668416-23.patch | 1.19 KB | Krzysztof Domański |
#20 | 2668416-20.patch | 1.37 KB | Krzysztof Domański |
Comments
Comment #2
wheatpenny CreditAttribution: wheatpenny commentedAttached is an updated test for "0 | Drupal." It currently fails as the H1 does not appear to be created.
Comment #3
wheatpenny CreditAttribution: wheatpenny commentedComment #4
wheatpenny CreditAttribution: wheatpenny commentedComment #5
pwolanin CreditAttribution: pwolanin as a volunteer and at Acquia commentedSo, I think the real problem here is that the H1 is not rendered at all as best I can tell.
I a possible change to the test would be:
And this is showing a bug perhaps in the rendering system to node template?
Comment #12
Krzysztof DomańskiPage title is not rendered now, so test (current($this->xpath($xpath))) treated 0 as FALSE and following assert pass! See attached test-only.
Comment #13
Krzysztof DomańskiUpdated issue summary and fixed coding standards and deprecated code.
Comment #15
Krzysztof DomańskiChanged
assertEqual()
toassertSame()
. Asserts that two variables have the same type and value.Comment #16
Krzysztof DomańskiAdded test-only.
Comment #18
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #19
alexpottNice fix. Testing for things that PHP duck types to false can be tricky.
These changes are out-of-scope. Yes at some point we need to make this change or similar changes. But scope creep makes everyone have to think more to review the issue.
Comment #20
Krzysztof DomańskiComment #21
LendudeThis is also out of scope, it's not needed to fix the problem right?
Test only fix so should be eligible for 8.6.x
Comment #22
Krzysztof DomańskiRight, it's not important in this issue.
Comment #23
Krzysztof DomańskiComment #24
LendudeThis looks good now, all feedback has been addressed, thanks @Krzysztof Domański
Comment #25
alexpottCrediting @wheatpenny for creating the issue and @Lendude and myself for scope management.
Committed and pushed 751b38424c to 8.7.x and 11f66339c1 to 8.6.x. Thanks!