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
BrowserTestBase
has its own method for creating users (as well as implementations of the other methods provided by the UserCreationTrait
). The method is incompatible with the one used in WebTestBase
, since it is missing the third parameter that allows the user to be created with an admin role.
Proposed resolution
Remove the separate methods, and use the UserCreationTrait
instead. This will allow the eventual conversion of WebTestBase
without having to rework admin users.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#19 | 2758067-clean-backport.patch | 6.06 KB | xjm |
#12 | 2758067-12.patch | 6.49 KB | Eric_A |
#2 | 2758067-02.patch | 5.99 KB | jhedstrom |
Comments
Comment #2
jhedstromComment #3
pfrenssenGreat job, simplifies the code base and leverages an existing trait.
This is not the most elegant thing, but for BC reasons it's fine to do it like this. We cannot rename this property any more at this point.
Comment #5
jhedstromLooks to be a random fail, back to RTBC.
Comment #7
xjmCould we add
$passRaw
to the testing frameworks and deprecate$pass_raw
? Since our coding standards do say class members should becamelCase
. That could be a followup; not in scope here. Then we could simply remove the old, inconsistently named properties in 9.x.This is also something that might benefit from a followup for method addition/deprecation to later rename these (for both web and browser tests). (Could be part of the same followup.)
I read over the removed code and confirmed it's pretty much pure duplicated code. Diffstats like this make me happy! And it's completely BC as a bonus. Nice work.
Committed c572b92 and pushed to 8.2.x. Thanks!
Removed now-unused use statements on commit:
Comment #8
jhedstromI'm not sure how we'd denote this as deprecated, since the variable on
$account
isn't declared anywhere besides in documentation. However, I did take an initial approach here: #2768765: Deprecate $pass_raw in UserCreationTrait and DrupalLogin documentation.Comment #9
Eric_A CreditAttribution: Eric_A commentedCan we have this in 8.1.x just like we did for the previous BrowserTestBase changes?
The touched files are identical in 8.2.x and 8.1.x (core/tests/Drupal/Tests/BrowserTestBase.php and core/modules/simpletest/src/UserCreationTrait.php)Because everything is identicalgit cherry-pick c572b92 -X theirs
does the job and is as effective as resolving the conflict. (git cherry-pick c572b92
doesn't automatically resolve the "conflict". BrowserTestBase has followed a different route in 8.1.x than in 8.2.x. A couple of the earlier commits weren't cherry-picked but applied separately.)Therefor committing this one with
git cherry-pick c572b92 -X theirs
is preferable to doing a completely separate commit.Comment #10
jhedstrom@Eric_A I think this would qualify for a backport, but since it doesn't apply cleanly, a patch would need to be uploaded here (using the method you describe in #9) to verify that all the tests still pass in 8.1.x.
Comment #12
Eric_A CreditAttribution: Eric_A commentedHere is a patch created after git cherry-picking!
As noted in #9: the touched files are actually identical in 8.1.x.To avoid possible future BrowserTestBase backport problems with git cherry-pick it would certainly help if core committers would actually cherry-pick this one, either with conflict resolution or in this special case with
git cherry-pick c572b92 -X theirs
.Thanks, @jhedstrom for pointing out some stuff.
Comment #13
Eric_A CreditAttribution: Eric_A commentedHmm, guess I missed something earlier when i said the touched files were identical.
8.2.x - 2758067-02.patch:
- $assigned_permissions = Role::load($role->id())->getPermissions();
8.1.x - 2758067-12.patch:
- $assigned_permissions = entity_load('user_role', $role->id())->getPermissions();
The
git cherry-pick c572b92 -X theirs
trick worked out fine here, bit my earlier reasoning doesn't apply.Comment #14
dawehnerWhat happens when an existing subclass uses this trait already. Doesn't that cause some issues? Nope, it doesn't see https://3v4l.org/lsIgN
Given that we continue to work on those tests issues having something more in sync is not a bad idea in the first place.
Comment #15
xjmSo I'm not sure about backporting this change to 8.1.x. If it were production code, I probably would not consider it, despite @dawehner's reassurance about it being non-disruptive above. Our allowed changes policy considers internal refactoring (for which this might qualify) for patch releases at committer discretion only.
Other improvements intended to make the test conversions easier have been going into 8.2.x only, so the branches have already diverged. What is the case for backporting this?
Comment #16
xjmAlso filed: #2773087: [policy, maybe patch] Clarify backport policy for testing framework changes, including new BTB tests
Comment #17
Eric_A CreditAttribution: Eric_A commentedComment #18
Eric_A CreditAttribution: Eric_A commentedAt this moment only the last two changes to BrowserTestBase did not make it into 8.1.x. The
entity_load()
conversion (unrelated to test conversion) was responsible for divergence. But if we backport here that implementation divergence will be moved into a trait, which would be really nice.Comment #19
xjmBased on
git diff 8.2.x -- core/tests/Drupal/Tests/BrowserTestBase.php
as well as feedback from @Eric_A, @dawehner, and @Berdir on #2773087: [policy, maybe patch] Clarify backport policy for testing framework changes, including new BTB tests, I will backport this to 8.1.x. However, none of the suggested cherry-picks or uploaded patches cleanly fixed the use statement issue I previously resolved, so to be on the safe side, here's a clean backport patch so we can ensure tests pass with it.Comment #20
xjmCommitted 4775a28 and pushed to 8.1.x. Thanks!
Comment #22
xjm