/** * Ensures that the validator follows expected behavior * * @return void */ public function testBasic() { /** * The elements of each array are, in order: * - minimum * - maximum * - inclusive * - expected validation result * - array of test input values */ $valuesExpected = array( array(1, 100, true, true, array(1, 10, 100)), array(1, 100, true, false, array(0, 0.99, 100.01, 101)), array(1, 100, false, false, array(0, 1, 100, 101)), array('a', 'z', true, true, array('a', 'b', 'y', 'z')), array('a', 'z', false, false, array('!', 'a', 'z')) ); foreach ($valuesExpected as $element) { $validator = new Validator\Between(array('min' => $element[0], 'max' => $element[1], 'inclusive' => $element[2])); foreach ($element[4] as $input) { $this->assertEquals($element[3], $validator->isValid($input), 'Failed values: ' . $input . ":" . implode("\n", $validator->getMessages())); } } }
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); }
/** * 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); } } }