public function test_findMessages_should_apply_templates_to_flattened_messages() { $stringMax256 = v::string()->length(5, 256); $alnumDot = v::alnum('.'); $stringMin8 = v::string()->length(8, null); $v = v::allOf(v::attribute('first_name', $stringMax256)->setName('First Name'), v::attribute('last_name', $stringMax256)->setName('Last Name'), v::attribute('desired_login', $alnumDot)->setName('Desired Login'), v::attribute('password', $stringMin8)->setName('Password'), v::attribute('password_confirmation', $stringMin8)->setName('Password Confirmation'), v::attribute('stay_signedin', v::notEmpty())->setName('Stay signed in'), v::attribute('enable_webhistory', v::notEmpty())->setName('Enabled Web History'), v::attribute('security_question', $stringMax256)->setName('Security Question'))->setName('Validation Form'); try { $v->assert((object) array('first_name' => 'fiif', 'last_name' => null, 'desired_login' => null, 'password' => null, 'password_confirmation' => null, 'stay_signedin' => null, 'enable_webhistory' => null, 'security_question' => null)); } catch (ValidationException $e) { $messages = $e->findMessages(array('allOf' => 'Invalid {{name}}', 'first_name.length' => 'Invalid length for {{name}} {{input}}')); $this->assertEquals($messages['allOf'], 'Invalid Validation Form'); $this->assertEquals($messages['first_name_length'], 'Invalid length for "fiif" fiif'); } }
public function __construct($data) { parent::__construct(); $this->data = $data; $this->fields = array('firstname' => array('value' => $this->data['firstname'], 'validators' => array('notEmpty'), 'errors' => array('Firstname is empty')), 'email' => array('value' => $this->data['email'], 'validators' => array('email', 'notEmpty'), 'errors' => array('Email is not valid', 'Email is empty')), 'url' => array('value' => $this->data['url'], 'validators' => array('notEmpty', 'url'), 'errors' => array('Url is empty', 'Url is not valid')), 'cv' => array('value' => $_FILES['cv'], 'validators' => function () { return v::exists()->validate($_FILES['cv']["tmp_name"]); }, 'errors' => array('File is empty')), 'content' => array('value' => $this->data['content'], 'validators' => function ($value) { return v::when(v::int(), v::positive(), v::notEmpty())->validate($value); }, 'errors' => array('content is not valid')), 'int' => array('value' => $this->data['int'], 'validators' => function ($value) { return v::allOf(v::int(), v::positive(), v::notEmpty())->validate($value); }, 'errors' => array('int is not valid')), 'uppercase' => array('value' => '', 'validators' => function ($value) { return v::string()->uppercase()->validate($value); }, 'errors' => array('uppercase is not valid'))); }