Esempio n. 1
0
 public function testInputIncorrectStringFromHttpPost()
 {
     global $_POST;
     $_POST['TestString'] = '@Test';
     // Invalid format
     $_POST['TestNotAStr'] = array('Array here');
     // Another invalid format
     $errors = array();
     $exceptionCatched = false;
     $input = Input\Input::from(Input\Source\HttpPost::import())->fields(Input\Field\Strings::bind('TestString')->defaults('Default Test')->limits(Input\Limit\Validate::create()->format('alphanumber')->maxlen(64)->minlen(1)), Input\Field\Strings::bind('TestNotAStr')->defaults('Default Test')->limits(Input\Limit\Validate::create()->format('standard')->maxlen(64)->minlen(1)))->errors($errors)->prepare();
     // prepare returns a new object: Input\Result
     $this->assertEquals(2, count($errors));
     // Error type should be INVALID
     $this->assertEquals('INVALID', $errors[0]->type());
     $this->assertEquals('INVALID', $errors[1]->type());
     // Error code should be FORMAT
     $this->assertEquals('FORMAT', $errors[0]->code());
     // And this should be DATA_TYPE
     $this->assertEquals('DATATYPE', $errors[1]->code());
     // Error code should be TESTSTRING_FORMAT
     $this->assertEquals('TESTSTRING_FORMAT', $errors[0]->errorCode());
     // And this should be TESTNOTASTR_DATA_TYPE
     $this->assertEquals('TESTNOTASTR_DATATYPE', $errors[1]->errorCode());
     try {
         $input->get('TestString')->value();
     } catch (Input\Base\Exception\Results\FieldNotFound $e) {
         $exceptionCatched = true;
     }
     // An exception should be throw out
     $this->assertTrue($exceptionCatched);
 }
Esempio n. 2
0
 public function testWithInput()
 {
     global $_POST;
     $_POST['testOneof'] = 'ValueA';
     $_POST['testOneof2'] = 'ValueB';
     $errors = array();
     $input = Input\Input::from(Input\Source\HttpPost::import())->fields(Input\Field\Strings::bind('testOneof')->limits(Input\Limit\Oneof::create()->add('ValueA'))->limits(Input\Limit\Oneof::create()->add('ValueC')), Input\Field\Strings::bind('testOneof2')->limits(Input\Limit\Oneof::create()->add('ValueA'))->limits(Input\Limit\Oneof::create()->add('ValueC'))->defaults('ValueA'))->errors($errors)->prepare();
     // There should be one error
     $this->assertEquals(1, count($errors));
     // Error should be CASE_UNKNOWN
     $this->assertEquals('INVALID', $errors[0]->type());
     $this->assertEquals('CASEUNKNOWN', $errors[0]->code());
 }
 public function testInputCorrectBooleanFromHttpPost()
 {
     global $_POST;
     $_POST['TestBooleans'] = 'hasSet';
     $errors = array();
     $input = Input\Input::from(Input\Source\HttpPost::import())->fields(Input\Field\Booleans::bind('TestBooleans')->required(false)->defaults(true), Input\Field\Booleans::bind('TestBooleansNotExisted')->required(false)->defaults(false))->errors($errors)->prepare();
     // prepare returns a new object: Input\Result
     // The error should be 0
     $this->assertEquals(0, count($errors));
     // The field TestBooleans should be true
     $this->assertEquals(true, $input->get('TestBooleans')->value());
     // The field TestBooleansNotExisted should be false
     $this->assertEquals(false, $input->get('TestBooleansNotExisted')->value());
 }
 public function testInputIncorrectIntegerFromHttpPost()
 {
     global $_POST;
     $_POST['TestIntegerLarger'] = 100;
     $_POST['TestIntegerLarger2'] = 1;
     $errors = array();
     $input = Input\Input::from(Input\Source\HttpPost::import())->fields(Input\Field\Integers::bind('TestIntegerLarger')->defaults(64)->limits(Input\Limit\Maxmin::create()->max(64)->min(10)), Input\Field\Integers::bind('TestIntegerLarger2')->defaults(64)->limits(Input\Limit\Maxmin::create()->max(64)->min(10)))->errors($errors)->prepare();
     // prepare returns a new object: Input\Result
     // The error should be 1
     $this->assertEquals(2, count($errors));
     // The Error 1 should for TestIntegerLarger and it's too large
     $this->assertEquals('INVALID', $errors[0]->type());
     $this->assertEquals('TOOLARGE', $errors[0]->code());
     // The Error 2 should for TestIntegerLarger2 and it's too small
     $this->assertEquals('INVALID', $errors[1]->type());
     $this->assertEquals('TOOSMALL', $errors[1]->code());
 }
Esempio n. 5
0
 public function testInputArrayedStringButInvalid2()
 {
     global $_POST;
     $_POST['TestStringArray3']['UserName'] = '******';
     $_POST['TestStringArray3']['Password'] = '******';
     $_POST['TestStringArray2'] = array(array('UserName' => '!Username1', 'Password' => '!1234567890'), array('UserName' => '!Username2', 'Password' => '!1234567891'));
     $errors = array();
     $input = Input\Input::from(Input\Source\HttpPost::import())->fields(Input\Field\Subs::bind('TestStringArray3')->subs(Input\Field\Strings::bind('UserName')->required(true)->limits(Input\Limit\Validate::create()->format('username')), Input\Field\Strings::bind('Password')->required(true)->limits(Input\Limit\Validate::create()->format('username'))), Input\Field\Groups::bind('TestStringArray2')->adds(Input\Field\Strings::bind('UserName')->limits(Input\Limit\Validate::create()->format('username')), Input\Field\Strings::bind('Password')))->errors($errors)->prepare();
     // The error should be 0
     $this->assertEquals(2, count($errors));
     // Error on TestStringArray3
     $this->assertEquals('INVALID', $errors[0]->type());
     $this->assertEquals('FORMAT', $errors[0]->code());
     // Error on TestStringArray2
     $this->assertEquals('INVALID', $errors[1]->type());
     $this->assertEquals('FORMAT', $errors[1]->code());
 }