Exemple #1
0
 public function testSetGetMessageLengthLimitation()
 {
     Validator\AbstractValidator::setMessageLength(5);
     $this->assertEquals(5, Validator\AbstractValidator::getMessageLength());
     $valid = new Validator\Between(1, 10);
     $this->assertFalse($valid->isValid(24));
     $message = current($valid->getMessages());
     $this->assertTrue(strlen($message) <= 5);
 }
Exemple #2
0
 /**
  * Ensures that getInclusive() returns expected default value
  *
  * @return void
  */
 public function testGetInclusive()
 {
     $validator = new Validator\Between(array('min' => 1, 'max' => 10));
     $this->assertEquals(true, $validator->getInclusive());
 }
Exemple #3
0
 public function testValidatorBreakChain()
 {
     $data = array('field1' => '150', 'field2' => '150');
     $btw1 = new Validator\Between(1, 100);
     $btw2 = new Validator\Between(1, 125);
     $messageUserDefined = 'Something other than the default message';
     $btw2->setMessage($messageUserDefined, Validator\Between::NOT_BETWEEN);
     $validators = array('field1' => array($btw1, $btw2), 'field2' => array($btw1, $btw2, InputFilter::BREAK_CHAIN => true));
     $input = new InputFilter(null, $validators, $data);
     $this->assertFalse($input->hasMissing(), 'Expected hasMissing() to return false');
     $this->assertTrue($input->hasInvalid(), 'Expected hasInvalid() to return true');
     $this->assertFalse($input->hasUnknown(), 'Expected hasUnknown() to return false');
     $this->assertFalse($input->hasValid(), 'Expected hasValid() to return false');
     $messages = $input->getMessages();
     $this->assertInternalType('array', $messages);
     $this->assertEquals(array('field1', 'field2'), array_keys($messages));
     $this->assertEquals($messageUserDefined, current($messages['field1']), 'Expected message to break 2 validators, the message of the latter overwriting that of the former');
     $this->assertEquals("'150' is not between '1' and '100', inclusively", current($messages['field2']), 'Expected rule for field2 to break the validation chain at the first validator');
 }
Exemple #4
0
 /**
  * Validate Group Search Options
  *
  * @param  array $options
  * @throws Exception\DomainException
  * @return void
  */
 protected function validateGroupPoolGetPhotos(array $options)
 {
     $validOptions = array('api_key', 'tags', 'method', 'group_id', 'per_page', 'page', 'extras', 'user_id');
     $this->compareOptions($options, $validOptions);
     $between = new BetweenValidator(1, 500, true);
     if (!$between->isValid($options['per_page'])) {
         throw new Exception\DomainException($options['per_page'] . ' is not valid for the "per_page" option');
     }
     $int = new IntValidator();
     $int->setLocale('en');
     if (!$int->isValid($options['page'])) {
         throw new Exception\DomainException($options['page'] . ' is not valid for the "page" option');
     }
     // validate extras, which are delivered in csv format
     if (isset($options['extras'])) {
         $extras = explode(',', $options['extras']);
         $validExtras = array('license', 'date_upload', 'date_taken', 'owner_name', 'icon_server');
         foreach ($extras as $extra) {
             /**
              * @todo The following does not do anything [yet], so it is commented out.
              */
             //in_array(trim($extra), $validExtras);
         }
     }
 }