Problem/Motivation
The test class in core\modules\user\tests\src\Kernel\UserInstallTest.php uses a regular database query instead of using an entity query.
Proposed resolution
Replace the regular database query with an entity query and then use user storage to load the user entities. Use the loaded user entities in the assertions.
Info for novices:
The entity query for loading the user ids: $user_ids = \Drupal::entityQuery('user')->sort('uid')->execute();
The user entities are loaded with: $users = \Drupal::entityTypeManager()->getStorage('user')->loadMultiple($user_ids);
Remaining tasks
TBD
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
TBD
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 3151520-10.patch | 1.85 KB | adityasingh |
| #7 | interdiff_3-7.txt | 1.45 KB | adityasingh |
| #7 | 3151520-7.patch | 1.85 KB | adityasingh |
Comments
Comment #2
pavnish commentedWorking on it
Comment #3
pavnish commented@daffie Hi
Database query with an entity query in UserInstallTest for user has been changes as suggested.
I am also ran the testcase in my local it's working fine.
Please review this patch.
Thanks
Pavnish
Comment #4
daffie commentedLooks good to me.
Comment #5
alexpottassertNotEmpty() also let's use the uuid() method since we have a User object...
Let's take the opportunity to use assertEquals as assertEqual() is deprecated and hardcode test assumptions because it make things easier to read.
As above...
Comment #6
adityasingh commentedI'm working on it.
Comment #7
adityasingh commentedHi @alexpott
Made changes as you suggested please review.
Comment #8
daffie commentedAll changes look good. Just one nitpick:
Nitpick: Remove the extra space on the end of the line.
Comment #9
adityasingh commentedComment #10
adityasingh commentedHi @daffie
Space issue is fixed please review.
Comment #11
daffie commentedAll points of @alexpott are addressed.
Back to RTBC.
Comment #12
alexpottAs a test-only change backported to 8.9.x to keep tests aligned - I ran on 8.9.x locally before committing.
Committed and pushed 5ded531763 to 9.1.x and da1bddfb40 to 9.0.x and 243e291028 to 8.9.x. Thanks!
Fixed unused use on commit.
Comment #16
adityasingh commentedThanks