public function testFormValidator()
{
$this->specify("Form validators don't work", function () {
//First element
$telephone = new Text("telephone");
$telephone->addValidator(new PresenceOf(array('message' => 'The telephone is required')));
expect($telephone->getValidators())->count(1);
$telephone->addValidators(array(new StringLength(array('min' => 5, 'messageMinimum' => 'The telephone is too short')), new Regex(array('pattern' => '/\\+44 [0-9]+ [0-9]+/', 'message' => 'The telephone has an invalid format'))));
expect($telephone->getValidators())->count(3);
//Second element
$address = new Text('address');
$address->addValidator(new PresenceOf(array('message' => 'The address is required')));
expect($address->getValidators())->count(1);
$form = new Form();
$form->add($telephone);
$form->add($address);
expect($form->isValid([]))->false();
$expectedMessages = Group::__set_state(array('_messages' => array(0 => Message::__set_state(array('_type' => 'PresenceOf', '_message' => 'The telephone is required', '_field' => 'telephone', '_code' => 0)), 1 => Message::__set_state(array('_type' => 'TooShort', '_message' => 'The telephone is too short', '_field' => 'telephone', '_code' => 0)), 2 => Message::__set_state(array('_type' => 'Regex', '_message' => 'The telephone has an invalid format', '_field' => 'telephone', '_code' => 0)), 3 => Message::__set_state(array('_type' => 'PresenceOf', '_message' => 'The address is required', '_field' => 'address', '_code' => 0)))));
expect($form->getMessages())->equals($expectedMessages);
expect($form->isValid(array('telephone' => '12345', 'address' => 'hello')))->false();
$expectedMessages = Group::__set_state(array('_messages' => array(0 => Message::__set_state(array('_type' => 'Regex', '_message' => 'The telephone has an invalid format', '_field' => 'telephone', '_code' => 0)))));
expect($form->getMessages())->equals($expectedMessages);
expect($form->isValid(array('telephone' => '+44 124 82122', 'address' => 'hello')))->true();
});
}