symfony / panther

A browser testing and web crawling library for PHP and Symfony
MIT License
2.91k stars 213 forks source link

[HELP] Test submitting a form that sends a message. #546

Open abozhinov opened 2 years ago

abozhinov commented 2 years ago

Hi, I have a Reset Password Request feature in my admin panel. I want to make an E2E test but can get the message. Use 'in-memory' transporter but it is always empty because the request is processed by the external web server. I want to fetch the message and read the URL.

public function testSendResetPasswordRequest(): void
{
    $admin = $this->getAdmin();

    $transport = self::getContainer()->get('messenger.transport.async');

    $crawler = $this->client->request(Request::METHOD_GET, '/cms/admin/reset-password/request');
    $form = $crawler->selectButton('Send')->form([
        'username' => $admin->getUserIdentifier(),
    ]);
    $this->client->waitForEnabled('button[type="submit"]');
    $this->client->submit($form);
    $this->assertSelectorWillContain('.noty_body', 'If there is an account with this email you will receive an email with a link to change the password.');

    $this->assertCount(1, $transport->getSent());
}
norkunas commented 2 years ago

I have a same problem..