Closed (fixed)
Project:
Drupal core
Version:
8.7.x-dev
Component:
user.module
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
1 Dec 2017 at 11:01 UTC
Updated:
7 Nov 2019 at 19:58 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
wim leersI already made a similar set of changes at #2927758: Update DbLogResourceTest to use the ResourceTestBase base class instead of the deprecated RESTTestBase, a novice should be able to look at the changes there and create a green patch for this one. Tagging.
Comment #3
wim leersComment #4
justinlevi commentedI'll give this a shot.
Comment #5
justinlevi commentedComment #6
wim leersThank you! 😀
Comment #7
justinlevi commented@wim-leers, I'm trying to work through rewriting this test but running into some issues with how to structure my first request.
I'm unclear how to structure the request body and where to go to find out. Can you point me to any API Documentation or examples? I'm extending ResourceTestBase and getting the first `testRegisterUser` function to fail, so trying to get to green...
Any direction is greatly appreciated.
Comment #8
xjmThanks @justinlevi for looking into this!
It would help to post a patch instead of posting the code in the comment (even if you know the patch isn't quite working yet). This will help for two reasons:
Comment #9
wim leersGood question —
\Drupal\user\Tests\RestRegisterUserTest::createSerializedUser()in the existing test is generating the request body.Comment #10
justinlevi commentedI had a few issues going on that was leading to the error above, mainly that the email address wasn't be created in the body correctly using this syntax:
"mail" => [["value" => "$name@example.com"]],and that I wasn't sending the password due to an oversight on my part.
I also noticed that the previous tests had a couple of redundant tests??
As an example:
And
I don't know if I'm missing something, but I've gone ahead and removed those in my attached patch.
I also don't yet understand how to properly `assertMailString` as I've tried to include the AssertMailTrait as it was included in WebTestBase, but now that we're using ResourceTestBase which inherits from BrowserTestBase, we no longer have access to that method.
Any suggestions on how to handle mail tests using ResourceTestBase?
Comment #11
justinlevi commentedAlright, I may have reached a point where I need some additional direction/help. Please see the attached patch.
Note that all tests pass except for the ones that check email. I am not sure why this is. I've tried to include the `AssertMailTrait` in the same way that \Drupal\Tests\user\Functional\UserAdminTest and \Drupal\Tests\simpletest\Functional\MailCaptureTest use that trait.
I can even confirm that including the `testNotificationEmailAddress` method runs as expected in this test class. I've narrowed the issue down to the difference between
$this->drupalPostForm('user/register', $edit, t('Create new account'));and
Seems that Posting the form at user/register is doing something differently than making a POST request via the user.register route, at least in the way I'm attempting to do so here.
Any help is appreciated.
Comment #12
justinlevi commentedUpdating with PHPCS coding standard fixes.
Comment #13
justinlevi commentedugh - forgot to grant permissions to the anonymous user in this last refactoring.
Comment #14
justinlevi commentedHmm... I can verify that
docroot/core/lib/Drupal/Core/Mail/Plugin/Mail/TestMailCollector.php
Drupal\Core\Mail\Plugin\Mail\TestMailCollector
`\Drupal::state()->set('system.test_mail_collector', $captured_emails);` is in fact getting saved in the test key_value database table.
At least when it originates from UserRegistrationResource > sendEmailNotifications
No idea why AsserMailString > getMails is not returning any emails then??
Comment #15
justinlevi commentedComment #16
justinlevi commentedApologies for the barrage of messages.
Could it be that we're somehow using the wrong state or context due to a sub request triggered from ResourceTestBase->request() and this new context no longer has access to the original Drupal state object??
Just shooting in the dark.
I've created a screen capture video demonstrating the issue here:
http://justinleviwinter.s3.amazonaws.com/container-state-different-from-...
Comment #17
justinlevi commentedThe last patch uploaded has all test passing locally. I implemented a really really awful workaround to go to the key_value table directly and pull out the stored emails from 'system.test_mail_collector'. Would love some help as far as how to actually get the TestMailCollector plugin to work correctly here.
Comment #18
ivan berezhnov commentedComment #20
ziomizar commentedComment #21
ziomizar commentedThis issue can be marked as duplicated of #2887869: Convert web tests to browser tests for user module part-2 ?
Comment #22
ziomizar commentedComment #24
dawehnerShouldn't we remove
\Drupal\user\Tests\RestRegisterUserTest::testRegisterUsernow?Comment #25
dawehnerComment #27
johnny_aroza commented@dawehner looks like its been already removed
Comment #28
wim leers#27: I don't see #17 removing the old file (
\Drupal\user\Tests\RestRegisterUserTest)?Comment #29
pritishkumar commentedI have updated the patch to remove the file mentioned in #24.
I hope this it's correct.
Thanks
Comment #30
pritishkumar commentedChanging the Status.
Comment #31
borisson_I think this looks good, but because this is a removal + addition of a file instead of the file being moved - this is hard to review. Using
git diff -Mgit might find this change as a move.Since this is a change of the base-class I'm not sure if that is going to help to make it easier to review this though. Git might be confused about this because there is too much change in the file.
In any case, this looks good.
Comment #32
dawehnerI'm confused, why can't we use the
AssertMailTrait?Comment #33
wim leersPer #32.
Comment #34
lendudeThe AssertMailTrait wasn't working because of some caching/container sync issue it looks like. Adding ->resetAll() fixes this. Bit heavy handed, but *shrug*
Comment #35
wim leersIt was quite confusing to review this because the order in which the various cases are tested has changed. I did manually verify that there is still the same set of tests cases, just in a different order. I can see how this moving things around would make things easier given the very different base test class.
Comment #36
alexpottCrediting @Wim Leers and @dawehner for code review comments.
Committed and pushed 478177541c to 8.7.x and c0465bbfc2 to 8.6.x. Thanks!
Backported to 8.6.x after running the test locally. Having the same test coverage in both branches is a good thing.
Fixed coding standards on commit.