Problem/Motivation
This is an edge case, but we semi-frequently see random fails in our tests (which check php dblog messages after each scenario) like this:
Error: Call to a member function getDisplayName() on null in Drupal\navigation\Plugin\Block\NavigationUserBlock::buildLinks() (line 65 of ..../web/core/modules/navigation/src/Plugin/Block/NavigationUserBlock.php)
According to the test fail, this happens on 404 request from an image, so fairly delayed. I think what's happening is that the behat test cleanup is already deleting the user before the request gets to that point and then the user essentially vanishes mid-request.
Steps to reproduce
Proposed resolution
A quickfix would be to just check if the user was loaded and if not, return early.
Alternatively, the block could add a context requirement on the current user, which would automatically take care of the cache dependency.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3560876
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3560876-navigationuserblockbuildlinks-doesnt-check
changes, plain diff MR !14829
Comments
Comment #4
berdirThis is an edge case that I don't think is worth testing for, but it happens surprisingly often for us in our behat tests.
I didn't try the plugin context route, plugin contexts didn't really work for me with a custom block in a project, didn't investigate further.
Comment #5
smustgrave commentedChanges seems small enough don't believe need explicit test coverage for.
Comment #9
lauriiiThank you!