/
RegistrationWebTest.php
78 lines (61 loc) 路 2.6 KB
/
RegistrationWebTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/*
* This file is part of the NucleosProfileBundle package.
*
* (c) Christian Gripp <mail@core23.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nucleos\ProfileBundle\Tests\Functional\Action;
use Nucleos\ProfileBundle\Action\CheckRegistrationMailAction;
use Nucleos\ProfileBundle\Action\ConfirmRegistrationAction;
use Nucleos\ProfileBundle\Action\RegistrationAction;
use Nucleos\ProfileBundle\Action\RegistrationConfirmedAction;
use Nucleos\ProfileBundle\Tests\App\Entity\TestUser;
use Nucleos\ProfileBundle\Tests\Functional\DoctrineSetupTrait;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
#[CoversClass(RegistrationAction::class)]
#[CoversClass(ConfirmRegistrationAction::class)]
#[CoversClass(CheckRegistrationMailAction::class)]
#[CoversClass(RegistrationConfirmedAction::class)]
class RegistrationWebTest extends WebTestCase
{
use DoctrineSetupTrait;
#[Test]
public function execute(): void
{
$client = self::createClient();
$this->performRegister($client);
$user = $this->getEntityManager()->getRepository(TestUser::class)->findOneBy([
'username' => 'new_username',
]);
self::assertNotNull($user);
self::assertFalse($user->isEnabled());
self::assertNotNull($user->getConfirmationToken());
$this->performConfirm($client, $user);
}
private function performRegister(KernelBrowser $client): void
{
$client->request('GET', '/register/');
self::assertResponseIsSuccessful();
$client->submitForm('registration_form[save]', [
'registration_form[username]' => 'new_username',
'registration_form[email]' => 'new@example.com',
'registration_form[plainPassword][first]' => 'super_secret_password',
'registration_form[plainPassword][second]' => 'super_secret_password',
]);
self::assertResponseRedirects('/register/check-email');
}
private function performConfirm(KernelBrowser $client, TestUser $user): void
{
$client->request('GET', sprintf('/register/confirm/%s', $user->getConfirmationToken()));
self::assertResponseRedirects('/register/confirmed');
$user = $this->getEntityManager()->find(TestUser::class, $user->getId());
self::assertTrue($user->isEnabled());
self::assertNull($user->getConfirmationToken());
}
}