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
WebTestBase::setUp()
installs Drupal through the interactive installer, and creates a fake user object for uid 1 and makes that available as$this->root_user
, but the object does not contain a uid.- The lack of a uid breaks
WebTestBase::drupalCreateNode()
, which tries to use the uid of the currently logged in user (which may be $this->root_user).
Proposed solution
- Just add a ::$uid property with value 1 there.
- No need to (re)load the entire entity of uid 1 (performance). It's OK if
$this->root_user
is a mock stdClass object. - No need for adding tests for this.
Comment | File | Size | Author |
---|---|---|---|
drupal8.test-root-user-uid.0.patch | 617 bytes | sun | |
Comments
Comment #1
sunRan the second time into this in another current feature request #1751210: Convert URL alias form element into a field and field widget, so let's move forward here.
Comment #2
tim.plunkettI'll +1 the RTBC, because sun shouldn't have himself ;)
I haven't hit this yet, but I've been using $this->root_user more, and this would have been annoying had I hit it.
Comment #3
Dries CreditAttribution: Dries commentedCommitted to 8.x. Thanks.