|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace App\Tests\Functional; |
| 6 | + |
| 7 | +use App\Tests\FunctionalTester; |
| 8 | + |
| 9 | +final class FormCest |
| 10 | +{ |
| 11 | + public function dontSeeFormErrors(FunctionalTester $I) |
| 12 | + { |
| 13 | + $I->amOnPage('/register'); |
| 14 | + $I->submitSymfonyForm('registration_form', [ |
| 15 | + |
| 16 | + '[plainPassword]' => '123456', |
| 17 | + '[agreeTerms]' => true |
| 18 | + ]); |
| 19 | + $I->dontSeeFormErrors(); |
| 20 | + } |
| 21 | + |
| 22 | + public function seeFormErrorMessage(FunctionalTester $I) |
| 23 | + { |
| 24 | + $I->amOnPage('/register'); |
| 25 | + $I->submitSymfonyForm('registration_form', [ |
| 26 | + |
| 27 | + '[plainPassword]' => '123456', |
| 28 | + '[agreeTerms]' => true |
| 29 | + ]); |
| 30 | + $I->seeFormErrorMessage('email'); |
| 31 | + $I->seeFormErrorMessage('email', 'There is already an account with this email'); |
| 32 | + } |
| 33 | + |
| 34 | + public function seeFormErrorMessages(FunctionalTester $I) |
| 35 | + { |
| 36 | + $I->amOnPage('/register'); |
| 37 | + $I->submitSymfonyForm('registration_form', [ |
| 38 | + |
| 39 | + '[plainPassword]' => '123', |
| 40 | + '[agreeTerms]' => true |
| 41 | + ]); |
| 42 | + |
| 43 | + // Only with the names of the fields |
| 44 | + $I->seeFormErrorMessages(['email', 'plainPassword']); |
| 45 | + |
| 46 | + // With field names and error messages |
| 47 | + $I->seeFormErrorMessages([ |
| 48 | + // Full Message |
| 49 | + 'email' => 'There is already an account with this email', |
| 50 | + // Part of a message |
| 51 | + 'plainPassword' => 'at least 6 characters' |
| 52 | + ]); |
| 53 | + } |
| 54 | + |
| 55 | + public function seeFormHasErrors(FunctionalTester $I) |
| 56 | + { |
| 57 | + $I->amOnPage('/register'); |
| 58 | + $I->submitSymfonyForm('registration_form', [ |
| 59 | + |
| 60 | + '[plainPassword]' => '123456', |
| 61 | + '[agreeTerms]' => true |
| 62 | + ]); |
| 63 | + //There is already an account with this email |
| 64 | + $I->seeFormHasErrors(); |
| 65 | + } |
| 66 | +} |
0 commit comments