Пример #1
0
 /**
  * Creates a custom validation method.
  *
  * @param Event $event Event which fired validation.
  * @param Validator $validator Validation logic.
  * @param string $name Name of validator.
  */
 public function buildValidatorEventHandler(Event $event, Validator $validator, $name)
 {
     $validator->allowEmpty('address')->add('address', 'length', ['rule' => ['lengthBetween', 2, 255], 'message' => 'Addresses must be between 2 and 255 characters in length']);
     $validator->allowEmpty('city')->add('city', 'length', ['rule' => ['lengthBetween', 2, 255], 'message' => 'Cities must be between 2 and 255 characters in length']);
     $validator->allowEmpty('state')->add('state', 'length', ['rule' => ['lengthBetween', 2, 2], 'message' => 'States must consist of two letters'])->add('state', 'uppercase', ['rule' => ['custom', '/^[A-Z]{1,500}$/']])->add('state', 'validStateCode', ['rule' => ['inList', StatesEnumeration::getStatesArray()]]);
     $validator->allowEmpty('zipcode')->add('zipcode', 'length', ['rule' => ['lengthBetween', 5, 10], 'message' => 'Zipcodes must be between 5 and 10 characters long']);
     return $validator;
 }
 /**
  * Checks that each state code and name can be acquired using getStatesArray
  *
  * @dataProvider getStatesArrayContainsEachStateDataProvider
  *
  * @param type $name Full name of the state.
  * @param type $abbreviation State abbreviated name.
  */
 public function testGetStatesArrayContainsEachState($name, $abbreviation)
 {
     $states = StatesEnumeration::getStatesArray();
     $result = in_array($abbreviation, $states) && array_key_exists($name, $states);
     $this->assertTrue($result);
 }