| 1 | <?php |
||
| 10 | */ |
||
| 11 | class RegexpTest extends \PHPUnit_Framework_TestCase { |
||
| 12 | |||
| 13 | public function testRegexp() { |
||
| 14 | $regexpValidator = new \Fiv\Form\Validator\Regexp(); |
||
| 15 | $regexpValidator->setRegexp('![^\@]+\@[^\@]+!'); |
||
| 16 | |||
| 17 | $form = new Form(); |
||
| 18 | $form->input('email') |
||
| 19 | ->addValidator($regexpValidator); |
||
| 20 | |||
| 21 | $form->handle(new FormData('post', [ |
||
| 22 | $form->getUid() => 1, |
||
| 23 | 'email' => 'test@test', |
||
| 24 | ])); |
||
| 25 | |||
| 26 | $this->assertTrue($form->isValid()); |
||
| 27 | |||
| 28 | $form->handle(new FormData('post', [ |
||
| 29 | $form->getUid() => 1, |
||
| 30 | 'email' => 'test', |
||
| 31 | ])); |
||
| 32 | |||
| 33 | $this->assertFalse($form->isValid()); |
||
| 34 | } |
||
| 35 | } |
||
| 36 |