| Conditions | 3 |
| Paths | 1 |
| Total Lines | 36 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 48 | public function testEmailVirtualDbValidation() { |
||
| 49 | $form = new Form(); |
||
| 50 | |||
| 51 | $existEmailList = [ |
||
| 52 | '[email protected]', |
||
| 53 | '[email protected]', |
||
| 54 | ]; |
||
| 55 | |||
| 56 | $callBackValidator = (new CallBackValidator(function ($value) use ($existEmailList) { |
||
| 57 | if (empty($value)) { |
||
| 58 | return true; |
||
| 59 | } |
||
| 60 | if (in_array($value, $existEmailList)) { |
||
| 61 | return false; |
||
| 62 | } |
||
| 63 | return true; |
||
| 64 | }))->setErrorMessage('Email already exist!'); |
||
| 65 | |||
| 66 | $input = $form->input('email'); |
||
| 67 | $input->addValidator($callBackValidator); |
||
| 68 | |||
| 69 | $form->setData([ |
||
| 70 | $form->getUid() => 1, |
||
| 71 | 'email' => '[email protected]', |
||
| 72 | ]); |
||
| 73 | |||
| 74 | $this->assertFalse($form->isValid()); |
||
| 75 | $this->assertEquals('Email already exist!', $callBackValidator->getFirstError()); |
||
| 76 | |||
| 77 | $form->setData([ |
||
| 78 | $form->getUid() => 1, |
||
| 79 | 'email' => '[email protected]', |
||
| 80 | ]); |
||
| 81 | |||
| 82 | $this->assertTrue($form->isValid()); |
||
| 83 | } |
||
| 84 | } |
||
| 85 |