| 1 | <?php |
||
| 7 | class ValidatorTest extends \PHPUnit_Framework_TestCase |
||
| 8 | { |
||
| 9 | public function testValidate() |
||
| 10 | { |
||
| 11 | $validator = new Validator(); |
||
| 12 | $validator->add('RestService[email]', ['rule' => 'required | email'], '[email protected]'); |
||
| 13 | $validator->add('RestService[website]', ['rule' => 'url', 'defaultValue' => 'http://example.com'], ''); |
||
| 14 | $validator->isValid(); |
||
| 15 | |||
| 16 | $this->assertEquals( |
||
| 17 | [ |
||
| 18 | 'RestService[email]' => 'required | email', |
||
| 19 | 'RestService[website]' => 'url', |
||
| 20 | ], |
||
| 21 | $validator->getRules() |
||
| 22 | ); |
||
| 23 | |||
| 24 | $this->assertEquals( |
||
| 25 | [ |
||
| 26 | 'RestService[email]' => '[email protected]', |
||
| 27 | 'RestService[website]' => 'http://example.com', |
||
| 28 | ], |
||
| 29 | $validator->getDatas() |
||
| 30 | ); |
||
| 31 | } |
||
| 32 | |||
| 33 | public function testValidateWithInput() |
||
| 34 | { |
||
| 35 | $validator = new Validator(); |
||
| 36 | $validator->add('RestService[email]', ['rule' => 'required | email', 'defaultValue' => '[email protected]'], ''); |
||
| 37 | $validator->add('RestService[website]', ['rule' => 'url', 'defaultValue' => 'http://example.com'], ''); |
||
| 38 | $validator->validate([ |
||
| 39 | 'RestService' => [ |
||
| 40 | 'email' => '[email protected]', |
||
| 41 | 'website' => '', |
||
| 42 | ], |
||
| 43 | ]); |
||
| 44 | |||
| 45 | $this->assertEquals( |
||
| 46 | [ |
||
| 47 | 'RestService[email]' => 'required | email', |
||
| 48 | 'RestService[website]' => 'url', |
||
| 49 | ], |
||
| 50 | $validator->getRules() |
||
| 51 | ); |
||
| 52 | |||
| 53 | $this->assertEquals( |
||
| 54 | [ |
||
| 55 | 'RestService' => [ |
||
| 56 | 'email' => '[email protected]', |
||
| 57 | 'website' => '', |
||
| 58 | ], |
||
| 59 | ], |
||
| 60 | $validator->getDatas() |
||
| 61 | ); |
||
| 62 | } |
||
| 63 | } |
||
| 64 |