|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use App\Repository\UserRepository; |
|
6
|
|
|
use Doctrine\ORM\EntityManager; |
|
7
|
|
|
use Symfony\Bundle\FrameworkBundle\KernelBrowser; |
|
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
9
|
|
|
|
|
10
|
|
|
class RegistrationControllerTest extends WebTestCase |
|
11
|
|
|
{ |
|
12
|
|
|
private KernelBrowser $client; |
|
13
|
|
|
private UserRepository $userRepository; |
|
14
|
|
|
|
|
15
|
|
|
protected function setUp(): void |
|
16
|
|
|
{ |
|
17
|
|
|
$this->client = static::createClient(); |
|
18
|
|
|
|
|
19
|
|
|
// Ensure we have a clean database |
|
20
|
|
|
$container = static::getContainer(); |
|
21
|
|
|
|
|
22
|
|
|
/** @var EntityManager $em */ |
|
23
|
|
|
$em = $container->get('doctrine')->getManager(); |
|
24
|
|
|
$this->userRepository = $container->get(UserRepository::class); |
|
25
|
|
|
|
|
26
|
|
|
foreach ($this->userRepository->findAll() as $user) { |
|
27
|
|
|
$em->remove($user); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
$em->flush(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testRegister(): void |
|
34
|
|
|
{ |
|
35
|
|
|
// Register a new user |
|
36
|
|
|
$this->client->request('GET', '/register'); |
|
37
|
|
|
self::assertResponseIsSuccessful(); |
|
38
|
|
|
self::assertPageTitleContains('Register'); |
|
39
|
|
|
|
|
40
|
|
|
$this->client->submitForm('Register', [ |
|
41
|
|
|
'registration_form[email]' => '[email protected]', |
|
42
|
|
|
'registration_form[plainPassword]' => 'password', |
|
43
|
|
|
'registration_form[agreeTerms]' => true, |
|
44
|
|
|
]); |
|
45
|
|
|
|
|
46
|
|
|
// Ensure the response redirects after submitting the form, the user exists, and is not verified |
|
47
|
|
|
// self::assertResponseRedirects('/'); @TODO: set the appropriate path that the user is redirected to. |
|
48
|
|
|
self::assertCount(1, $this->userRepository->findAll()); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|