public function buildValidator(Event $event, Validator $validator, $name)
 {
     if ($this->_config['fields']) {
         $validator->provider('fileupload', 'WoodyAttachments\\Model\\Validation\\FileUploadValidator');
         foreach ($this->_config['fields'] as $field => $fieldOptions) {
             $options = array_merge($this->_config['defaultFieldOptions'], $fieldOptions);
             if (isset($options['numberOfFiles'])) {
                 //$field .= '.';
             }
             if ($options['required']) {
                 $validator->notEmpty($field, __d('WoodyAttachments', 'This filed is required'), $options['required']);
             } else {
                 $validator->allowEmpty($field, true);
             }
             $validator->add($field, ['mime' => ['rule' => ['mimeType', $options['allowedFileTypes']], 'message' => __d('WoodyAttachments', 'One of the files is not allowed file type.'), 'provider' => 'fileupload', 'on' => function ($context) use($options, $field) {
                 return !empty($options['allowedFileTypes']) && !empty($context['data'][$field][0]['tmp_name']) || !empty($options['allowedFileTypes']) && !empty($context['data'][$field]['tmp_name']);
             }], 'size' => ['rule' => ['fileSize', '<', $options['fileSize']], 'message' => __d('WoodyAttachments', 'One of the files is too large.'), 'provider' => 'fileupload', 'on' => function ($context) use($options, $field) {
                 return !is_null($options['fileSize']) && !empty($context['data'][$field][0]['tmp_name']) || !is_null($options['fileSize']) && !empty($context['data'][$field]['tmp_name']);
             }], 'error' => ['rule' => ['uploadErrorCheck'], 'message' => __d('WoodyAttachments', 'Upload error.'), 'provider' => 'fileupload', 'on' => function ($context) use($options, $field) {
                 return !empty($context['data'][$field][0]['tmp_name']) || !empty($context['data'][$field]['tmp_name']);
             }]]);
             unset($options);
         }
         return $validator;
     }
     throw new \BadFunctionCallException(__d('WoodyAttachments', 'You must specify fields field in WoodyAttachmentsUploadBehavior!'));
 }
 /**
  * Default validation rules.
  *
  * @param \Cake\Validation\Validator $validator Validator instance.
  * @return \Cake\Validation\Validator
  */
 public function validationImage(Validator $validator)
 {
     $validator->requirePresence('upload', 'create')->notEmpty('upload');
     $validator->add('upload', 'extnesion_check', ['rule' => ['extension'], 'message' => 'Image must be jpg, png or gif.'])->add('upload', 'file_size', ['rule' => ['fileSize', '<', '500Kb'], 'message' => 'Image is not correct dimensions.'])->add('upload', 'mimeType', ['rule' => ['mimeType', ['image/gif', 'image/png', 'image/jpg', 'image/jpeg']], 'message' => 'Image must be jpg, png or gif.']);
     $validator->provider('proffer', 'Proffer\\Model\\Validation\\ProfferRules')->add('upload', 'proffer', ['rule' => ['dimensions', ['min' => ['w' => 1, 'h' => 1], 'max' => ['w' => 1920, 'h' => 1920]]], 'message' => 'Image is not correct dimensions.', 'provider' => 'proffer']);
     return $validator;
 }
 /**
  * Validates the internal properties using a validator object and returns any
  * validation errors found.
  *
  * @param \Cake\Validation\Validator $validator The validator to use when validating the entity.
  * @return array
  */
 public function validate(Validator $validator)
 {
     $data = $this->_properties;
     $new = $this->isNew();
     $validator->provider('entity', $this);
     $this->errors($validator->errors($data, $new === null ? true : $new));
     return $this->_errors;
 }
Example #4
0
 /**
  * test minLength validation.
  *
  * @return void
  */
 public function testMinLength()
 {
     $validator = new Validator();
     $validator->provider('purifier', 'App\\Model\\Validation\\PurifierValidator')->add('biography', 'minLength', ['rule' => ['purifierMinLength', 10], 'provider' => 'purifier', 'message' => 'You fail']);
     $expected = ['biography' => ['minLength' => 'You fail']];
     $this->assertEquals($expected, $validator->errors(['biography' => 'LessThan9']));
     $this->assertEmpty($validator->errors(['biography' => 'more than 10 characteres']));
 }
 /**
  * test maxDimension with success validation.
  *
  * @return void
  */
 public function testMaxDimensionSuccess()
 {
     $file = ['name' => 'avatar.png', 'tmp_name' => TEST_WWW_ROOT . 'img/avatar.png', 'error' => UPLOAD_ERR_OK, 'type' => 'image/png', 'size' => 201];
     $expected = ['avatar_file' => ['maxDimension' => 'You fail']];
     $this->assertEquals($expected, $this->validator->errors(['avatar_file' => $file]));
     $validator = new Validator();
     $validator->provider('upload', 'App\\Model\\Validation\\UploadValidator')->add('avatar_file', 'maxDimension', ['rule' => ['maxDimension', 160, 160], 'provider' => 'upload', 'message' => 'You fail']);
     $this->assertEmpty($validator->errors(['avatar_file' => $file]));
 }
Example #6
0
 /**
  * Account validation rules.
  *
  * @param \Cake\Validation\Validator $validator The Validator instance.
  *
  * @return \Cake\Validation\Validator
  */
 public function validationAccount(Validator $validator)
 {
     return $validator->provider('upload', 'App\\Model\\Validation\\UploadValidator')->provider('purifier', 'App\\Model\\Validation\\PurifierValidator')->allowEmpty('first_name')->add('first_name', 'maxLength', ['rule' => ['maxLength', 100], 'message' => __("Your First Name can not contain more than {0} characters.", 100)])->allowEmpty('last_name')->add('last_name', 'maxLength', ['rule' => ['maxLength', 100], 'message' => __("Your Last Name can not contain more than {0} characters.", 100)])->allowEmpty('avatar_file')->add('avatar_file', ['mimeType' => ['rule' => ['mimeType', ['image/jpeg', 'image/png']], 'message' => __("The mimeType is not allowed."), 'on' => function ($context) {
         return !empty($context['data']['avatar_file']['name']);
     }], 'fileExtension' => ['rule' => ['extension', ['jpg', 'jpeg', 'png']], 'message' => __("The extensions allowed are {0}.", '.jpg, .jpeg and .png'), 'on' => function ($context) {
         return !empty($context['data']['avatar_file']['name']);
     }], 'fileSize' => ['rule' => ['fileSize', '<', '500KB'], 'message' => __("The file exceeded the max allowed size of {0}", '500KB'), 'on' => function ($context) {
         return !empty($context['data']['avatar_file']['name']);
     }], 'maxDimension' => ['rule' => ['maxDimension', 230, 230], 'provider' => 'upload', 'message' => __("The file exceeded the max allowed dimension. Max height : {0} Max width : {1}", 230, 230)]])->allowEmpty('facebook')->add('facebook', 'maxLength', ['rule' => ['maxLength', 200], 'message' => __("Your Facebook can not contain more than {0} characters.", 200)])->allowEmpty('twitter')->add('twitter', 'maxLength', ['rule' => ['maxLength', 200], 'message' => __("Your Twitter can not contain more than {0} characters.", 200)])->allowEmpty('biography')->add('biography', ['purifierMaxLength' => ['rule' => ['purifierMaxLength', 3000], 'provider' => 'purifier', 'message' => __('Your biography can not contain more than {0} characters.', 3000)]])->allowEmpty('signature')->add('signature', ['purifierMaxLength' => ['rule' => ['purifierMaxLength', 300], 'provider' => 'purifier', 'message' => __('Your biography can not contain more than {0} characters.', 300)]]);
 }
Example #7
0
 /**
  * Create validation rules.
  *
  * @param \Cake\Validation\Validator $validator Instance of the validator.
  *
  * @return \Cake\Validation\Validator
  */
 public function validationCreate(Validator $validator)
 {
     $validator->provider('upload', 'App\\Model\\Validation\\UploadValidator')->notEmpty('name', __("You must select a name."))->add('name', 'minLength', ['rule' => ['minLength', 5], 'message' => __("Please, {0} characters minimum for the name.", 5)])->allowEmpty('picture_file')->add('picture_file', ['mimeType' => ['rule' => ['mimeType', ['image/jpeg', 'image/png']], 'message' => __("The mimeType is not allowed."), 'on' => function ($context) {
         return !empty($context['data']['picture_file']['name']);
     }], 'fileExtension' => ['rule' => ['extension', ['jpg', 'jpeg', 'png']], 'message' => __("The extension allowed are {0}.", '.jpg, .jpeg and .png'), 'on' => function ($context) {
         return !empty($context['data']['picture_file']['name']);
     }], 'fileSize' => ['rule' => ['fileSize', '<', '500KB'], 'message' => __("The file exceeded the max allowed size of {0}", '500KB'), 'on' => function ($context) {
         return !empty($context['data']['picture_file']['name']);
     }], 'maxDimension' => ['rule' => ['maxDimension', 130, 130], 'provider' => 'upload', 'message' => __("The file exceeded the max allowed dimension. Max height : {0} Max width : {1}", 130, 130)]])->notEmpty('type', __("You must select a type."))->add('type', 'inList', ['rule' => ['inList', ['comments', 'registration']], 'message' => __("This type is not allowed. Allowed types : {0}", implode(", ", ['comments', 'registration']))])->notEmpty('rule', __("You must select a rule."))->add('rule', 'numeric', ['rule' => 'numeric']);
     return $validator;
 }
Example #8
0
 /**
  * Test the usage of the plugin inside a Validator
  *
  * @return void
  */
 public function testLocalizedProviderIntegration()
 {
     $validator = new Validator();
     $validator->provider('fr', 'Cake\\Localized\\Validation\\FrValidation');
     $validator->add('phoneField', 'myCustomRuleNameForPhone', ['rule' => 'phone', 'provider' => 'fr', 'message' => 'Numéro invalide']);
     $validator->add('postalField', 'myCustomRuleNameForPostal', ['rule' => 'postal', 'provider' => 'fr']);
     $this->assertCount(2, $validator);
     $this->assertEmpty($validator->errors(['phoneField' => '05 24 22 72 27', 'postalField' => '93000']));
     $errors = $validator->errors(['phoneField' => '924.227.227', 'postalField' => '0000']);
     $expected = ['phoneField' => ['myCustomRuleNameForPhone' => 'Numéro invalide'], 'postalField' => ['myCustomRuleNameForPostal' => 'The provided value is invalid']];
     $this->assertEquals($expected, $errors);
 }
Example #9
0
 /**
  * Default validation rules.
  *
  * @param \Cake\Validation\Validator $validator Validator instance.
  * @return \Cake\Validation\Validator
  */
 public function validationDefault(Validator $validator)
 {
     $validator->provider('proffer', 'Proffer\\Model\\Validation\\ProfferRules');
     $validator->add('id', 'valid', ['rule' => 'numeric'])->allowEmpty('id', 'create');
     $validator->add('email', 'valid', ['rule' => 'email'])->requirePresence('email', 'create')->notEmpty('email')->add('email', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
     $validator->requirePresence('username', 'create')->notEmpty('username')->add('username', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
     $validator->requirePresence('password', 'create')->notEmpty('password');
     $validator->requirePresence('first_name', 'create')->notEmpty('first_name');
     $validator->requirePresence('last_name', 'create')->notEmpty('last_name');
     $validator->add('avatar', 'proffer', ['rule' => ['dimensions', ['min' => ['w' => 32, 'h' => 32], 'max' => ['w' => 1024, 'h' => 1024]]], 'message' => 'Avatar image is not in correct dimensions.', 'provider' => 'proffer'])->allowEmpty('avatar');
     return $validator;
 }
Example #10
0
 /**
  * Default validation rules.
  *
  * @param \Cake\Validation\Validator $validator Validator instance.
  * @return \Cake\Validation\Validator
  */
 public function validationDefault(Validator $validator)
 {
     $validator->add('id', 'valid', ['rule' => 'numeric'])->allowEmpty('id', 'create');
     $validator->add('is_primary', 'valid', ['rule' => 'boolean'])->requirePresence('is_primary', 'create')->notEmpty('is_primary');
     $validator->requirePresence('filename', 'create')->notEmpty('filename');
     $validator->provider('upload', \Josegonzalez\Upload\Validation\DefaultValidation::class);
     $fileUploaded = function ($context) {
         return !empty($context['data']['filename']) && $context['data']['filename']['error'] == UPLOAD_ERR_OK;
     };
     $fileUploaded = true;
     $validator->add('filename', 'isValidExtension', ['rule' => ['extension', ['jpg', 'jpeg', 'gif', 'png']], 'message' => 'Sorry, your images need to have a filetype of .jpg, .png, or .gif', 'on' => $fileUploaded, 'last' => true])->add('filename', 'fileUnderPhpSizeLimit', ['rule' => 'isUnderPhpSizeLimit', 'message' => 'Sorry, this image exceeds the maximum filesize', 'provider' => 'upload', 'on' => $fileUploaded, 'last' => true])->add('filename', 'fileCompletedUpload', ['rule' => 'isCompletedUpload', 'message' => 'This file could not be uploaded completely', 'provider' => 'upload', 'on' => $fileUploaded, 'last' => true])->add('filename', 'fileFileUpload', ['rule' => 'isFileUpload', 'message' => 'No file was uploaded', 'provider' => 'upload', 'last' => true])->add('filename', 'fileSuccessfulWrite', ['rule' => 'isSuccessfulWrite', 'message' => 'There was an error saving the uploaded file', 'provider' => 'upload', 'on' => $fileUploaded, 'last' => true])->add('filename', 'fileAboveMinHeight', ['rule' => ['isAboveMinHeight', 200], 'message' => 'This image should at least be 200px high', 'provider' => 'upload', 'on' => $fileUploaded])->add('filename', 'fileAboveMinWidth', ['rule' => ['isAboveMinWidth', 200], 'message' => 'This image should at least be 200px wide', 'provider' => 'upload', 'on' => $fileUploaded]);
     return $validator;
 }
Example #11
0
 /**
  * Default validation rules.
  *
  * @param \Cake\Validation\Validator $validator Validator instance.
  * @return \Cake\Validation\Validator
  */
 public function validationDefault(Validator $validator)
 {
     $validator->add('id', 'valid', ['rule' => 'numeric'])->allowEmpty('id', 'create');
     // $validator
     //     ->add('user_id', 'valid', ['rule' => 'numeric'])
     //     ->allowEmpty('user_id');
     $validator->requirePresence('gender_id', 'create')->notEmpty('gender_id');
     $validator->requirePresence('first_name', 'create')->notEmpty('first_name');
     $validator->requirePresence('last_name', 'create')->notEmpty('last_name');
     $validator->add('birth', 'valid', ['rule' => ['date', 'dmy']])->requirePresence('birth', 'create')->notEmpty('birth');
     $validator->requirePresence('phone1', 'create')->notEmpty('phone1');
     $validator->allowEmpty('phone2');
     $validator->provider('br', BrValidation::class);
     $validator->add('uid', 'idVerification', ['rule' => 'personId', 'provider' => 'br'])->allowEmpty('uid');
     return $validator;
 }
Example #12
0
 /**
  * Default validation rules.
  *
  * @param \Cake\Validation\Validator $validator Validator instance.
  * @return \Cake\Validation\Validator
  */
 public function validationDefault(Validator $validator)
 {
     $validator->provider('extra', new \App\Model\Validation\ExtraValidator());
     $validator->add('id', 'valid', ['rule' => 'numeric'])->allowEmpty('id', 'create');
     $validator->add('codigo_banco', 'valid', ['rule' => 'numeric'])->allowEmpty('codigo_banco');
     $validator->allowEmpty('nome');
     $validator->allowEmpty('agencia');
     $validator->allowEmpty('conta_corrente');
     $validator->add('sequencial_arquivo', 'valid', ['rule' => 'numeric'])->allowEmpty('sequencial_arquivo');
     $validator->allowEmpty('caminho_arquivo');
     $validator->allowEmpty('sacador_avalista');
     $validator->add('cnpj_sacador', 'valid', ['provider' => 'extra', 'rule' => 'moeda', 'message' => __('CNPJ Informado esta invalido')])->allowEmpty('cnpj_sacador');
     $validator->allowEmpty('contrato');
     $validator->allowEmpty('carteira');
     $validator->allowEmpty('convenio');
     return $validator;
 }
Example #13
0
 /**
  * Tests the validateUnique method with scope
  *
  * @return void
  */
 public function testValidateUniqueScope()
 {
     $table = TableRegistry::get('Users');
     $validator = new Validator();
     $validator->add('username', 'unique', ['rule' => ['validateUnique', ['derp' => 'erp', 'scope' => 'id']], 'provider' => 'table']);
     $validator->provider('table', $table);
     $data = ['username' => 'larry', 'id' => 3];
     $this->assertNotEmpty($validator->errors($data));
     $data = ['username' => 'larry', 'id' => 1];
     $this->assertEmpty($validator->errors($data));
     $data = ['username' => 'jose'];
     $this->assertEmpty($validator->errors($data));
 }
Example #14
0
 /**
  * Adds a nested validator.
  *
  * Nesting validators allows you to define validators for array
  * types. For example, nested validators are ideal when you want to validate many
  * similar sub-documents or complex array types.
  *
  * This method assumes that the sub-document has a 1:N relationship with the parent.
  *
  * The providers of the parent validator will be synced into the nested validator, when
  * errors are checked. This ensures that any validation rule providers connected
  * in the parent will have the same values in the nested validator when rules are evaluated.
  *
  * @param string $field The root field for the nested validator.
  * @param \Cake\Validation\Validator $validator The nested validator.
  * @return $this
  */
 public function addNestedMany($field, Validator $validator)
 {
     $field = $this->field($field);
     $field->add(static::NESTED, ['rule' => function ($value, $context) use($validator) {
         if (!is_array($value)) {
             return false;
         }
         foreach ($this->providers() as $provider) {
             $validator->provider($provider, $this->provider($provider));
         }
         $errors = [];
         foreach ($value as $i => $row) {
             if (!is_array($row)) {
                 return false;
             }
             $check = $validator->errors($row, $context['newRecord']);
             if (!empty($check)) {
                 $errors[$i] = $check;
             }
         }
         return empty($errors) ? true : $errors;
     }]);
     return $this;
 }
 /**
  * Default validation rules.
  *
  * @param \Cake\Validation\Validator $validator Validator instance.
  * @return \Cake\Validation\Validator
  */
 public function validationCreate(Validator $validator)
 {
     $validator->provider('purifier', 'App\\Model\\Validation\\PurifierValidator')->notEmpty('message', __d('conversations', 'You must specify a message for your response.'))->add('message', ['purifierMinLength' => ['rule' => ['purifierMinLength', 5], 'provider' => 'purifier', 'message' => __d('conversations', 'Your message must contain at least {0} characters.', 5)]]);
     return $validator;
 }
Example #16
0
 /**
  * バリデーター初期化イベント
  *
  * @access public
  * @author sakuragawa
  */
 public function buildValidator(Event $event, Validator $validator, $name)
 {
     // ここで自作をしたproviderを追加してあげます。
     $validator->provider('default', 'Apollon\\Validation\\ApollonValidation');
     return $validator;
 }
Example #17
0
 /**
  * Default validation rules.
  *
  * @param \Cake\Validation\Validator $validator Validator instance.
  * @return \Cake\Validation\Validator
  */
 public function validationDefault(Validator $validator)
 {
     $validator->provider('proffer', 'Proffer\\Model\\Validation\\ProfferRules')->add('image', 'filesize', ['rule' => ['filesize', 300000], 'message' => 'File is larger than the maximum filesize 300 KB.', 'provider' => 'proffer'])->add('image', 'extension', ['rule' => ['extension', ['jpg', 'jpeg', 'png', 'gif']], 'message' => 'File does not have a jpg, png, and gif extension.', 'provider' => 'proffer']);
     return $validator;
 }
 /**
  * Validates the confirm_password field.
  *
  * Override it as needed to change the rules for only that field.
  *
  * @return void
  */
 public function validationConfirmPassword(Validator $validator)
 {
     $validator->provider('userBehavior', $this);
     $validator->add($this->_field('passwordCheck'), ['notBlank' => ['rule' => 'notBlank', 'message' => __d('user_tools', 'A password is required.')], 'minLength' => ['rule' => ['minLength', 6], 'message' => __d('user_tools', 'The password must have at least 6 characters.')], 'confirmPassword' => ['rule' => ['compareFields', 'password'], 'message' => __d('user_tools', 'The passwords don\'t match!'), 'provider' => 'userBehavior']]);
     return $validator;
 }
 /**
  * Test debugInfo helper method.
  *
  * @return void
  */
 public function testDebugInfo()
 {
     $validator = new Validator();
     $validator->provider('test', $this);
     $validator->add('title', 'not-empty', ['rule' => 'notEmpty']);
     $validator->requirePresence('body');
     $validator->allowEmpty('published');
     $result = $validator->__debugInfo();
     $expected = ['_providers' => ['test'], '_fields' => ['title' => ['isPresenceRequired' => false, 'isEmptyAllowed' => false, 'rules' => ['not-empty']], 'body' => ['isPresenceRequired' => true, 'isEmptyAllowed' => false, 'rules' => []], 'published' => ['isPresenceRequired' => false, 'isEmptyAllowed' => true, 'rules' => []]], '_presenceMessages' => [], '_allowEmptyMessages' => [], '_useI18n' => true];
     $this->assertEquals($expected, $result);
 }
 /**
  * Overwrite Cake\Validation\ValidatorAwareTrait
  *
  * Returns the default validator object. Subclasses can override this function
  * to add a default validation set to the validator object.
  *
  * @param \Cake\Validation\Validator $validator The validator that can be modified to
  * add some rules to it.
  * @return \Cake\Validation\Validator
  */
 public function validationDefault(Validator $validator)
 {
     $validator->provider('default', new Validation());
     return $validator;
 }
Example #21
0
 /**
  * User register
  *
  * @return \Cake\Network\Response|void
  */
 public function register()
 {
     $this->set('title', __d('users', 'Register'));
     /** @var $usersTable UsersTable */
     $usersTable = TableRegistry::get('Pie/Users.Users');
     /** @var User $user */
     $user = $usersTable->newEntity();
     if ($this->request->is(['post', 'put'])) {
         $validator = new Validator();
         $validator->provider('table', $usersTable)->add('email', ['uniqueEmail' => ['rule' => 'validateUnique', 'message' => __d('users', 'This email has been taken.'), 'provider' => 'table'], 'validEmail' => ['rule' => 'email', 'message' => __d('users', 'Please enter a valid email address.')]])->add('password', ['minLengthPassword' => ['rule' => ['minLength', 8], 'message' => __d('users', 'Minimum length of password is 8 characters.')]])->add('confirm_password', ['equalToPassword' => ['rule' => ['compareWith', 'password'], 'message' => __d('users', 'Entered passwords do not match.')]]);
         $errors = $validator->errors($this->request->data);
         $user->errors($errors);
         if (empty($errors)) {
             $detailsData = [];
             $emailData = [];
             $user->set('username', $this->request->data('username'))->set('email', $this->request->data('email'))->set('password', PasswordHasherFactory::build(Configure::read('pie.users.passwordHasher'))->hash($this->request->data('password')))->set('status', 0);
             if ('email' === Configure::read('pie.users.activationStrategy')) {
                 $activationKey = Security::hash(microtime(true), 'sha256', true);
                 $activationUrl = Router::url(['_full' => true, 'plugin' => 'Pie/Users', 'controller' => 'Users', 'action' => 'verify', $activationKey]);
                 $emailData['activationKey'] = $activationKey;
                 $emailData['activationUrl'] = $activationUrl;
                 $detailsData[] = new UserDetail(['key' => 'activation_key', 'value' => $activationKey]);
             }
             if (!empty($this->request->data('details')) && is_array($this->request->data('details'))) {
                 foreach ($this->request->data('details') as $detailKey => $detailValue) {
                     $detailsData[] = new UserDetail(['key' => $detailKey, 'value' => $detailValue]);
                 }
             }
             $user->set('details', $detailsData);
             if ($usersTable->save($user)) {
                 $this->getMailer('Pie/Users.User')->set($emailData)->send('welcome', [$user]);
                 $this->Flash->set(__d('users', 'Congratulations, You are successfully registered'), ['element' => 'success']);
                 return $this->redirect('/');
             }
         }
         $this->Flash->set(__d('users', 'The user could not be saved. Please, try again.'), ['element' => 'error']);
     }
     $this->set('user', $user);
 }
Example #22
0
 /**
  * Validation rules for the submitted fields of this form.
  *
  * @param Validator $validator The validator to customize.
  * @return $this
  */
 protected function _buildValidator(Validator $validator)
 {
     $validator->provider('googleRecaptcha', 'Wasabi\\Core\\Model\\Validation\\GoogleRecaptchaValidationProvider');
     return $validator->notEmpty('name', __d('wasabi_core', 'Please enter your name.'))->notEmpty('email', __d('wasabi_core', 'Please enter your email address.'))->add('email', 'email', ['rule' => 'email', 'message' => __d('wasabi_core', 'Please enter a valid email address.')])->notEmpty('subject', __d('wasabi_core', 'Please enter a subject for your contact request.'))->notEmpty('message', __d('wasabi_core', 'Please provide a message for your contact request.'))->notEmpty('g-recaptcha-response', __d('wasabi_core', 'Please confirm you are human.'))->add('g-recaptcha-response', 'googleRecaptcha', ['rule' => 'googleRecaptcha', 'message' => __d('wasabi_core', 'Please confirm you are human.'), 'provider' => 'googleRecaptcha']);
 }
Example #23
0
 /**
  * Tests that it is possible to pass extra arguments to the validation function
  * and it still gets the providers as last argument
  *
  * @return void
  */
 public function testMethodsWithExtraArguments()
 {
     $validator = new Validator();
     $validator->add('title', 'cool', ['rule' => ['isCool', 'and', 'awesome'], 'provider' => 'thing']);
     $thing = $this->getMock('\\stdClass', ['isCool']);
     $thing->expects($this->once())->method('isCool')->will($this->returnCallback(function ($data, $a, $b, $context) use($thing) {
         $this->assertEquals('bar', $data);
         $this->assertEquals('and', $a);
         $this->assertEquals('awesome', $b);
         $expected = ['default' => new \Cake\Validation\RulesProvider(), 'thing' => $thing];
         $expected = ['newRecord' => true, 'providers' => $expected, 'data' => ['email' => '!', 'title' => 'bar'], 'field' => 'title'];
         $this->assertEquals($expected, $context);
         return "That ain't cool, yo";
     }));
     $validator->provider('thing', $thing);
     $errors = $validator->errors(['email' => '!', 'title' => 'bar']);
     $expected = ['title' => ['cool' => "That ain't cool, yo"]];
     $this->assertEquals($expected, $errors);
 }
Example #24
0
 /**
  * Create validation rules.
  *
  * @param \Cake\Validation\Validator $validator Validator instance.
  *
  * @return \Cake\Validation\Validator
  */
 public function validationCreate(Validator $validator)
 {
     $validator->provider('purifier', 'App\\Model\\Validation\\PurifierValidator')->notEmpty('title', __('You must set a title for your thread.'))->add('title', ['lengthBetween' => ['rule' => ['lengthBetween', 5, 150], 'message' => __("The title must be between {0} and {1} characters.", 5, 150)]])->notEmpty('message', __('You must specify a message for your thread.'))->add('message', ['purifierMinLength' => ['rule' => ['purifierMinLength', 10], 'provider' => 'purifier', 'message' => __('Your message must contain at least {0} characters.', 10)]]);
     return $validator;
 }