コード例 #1
0
 /**
  * test to make sure that if Input has an array of posted values, are values are checked against the rules
  */
 public function testArrayOfPostedValues()
 {
     // Note that we require 3 different named Input elements, because addValidation() checks if there are
     // already rules defined and in that case doesn't overwrite the $data with another posted value
     // (which is not possible when coding decently)
     // checkboxes require a {$name}-isPosted hidden field to be posted
     $_POST['test1-isPosted'] = 1;
     $_POST['test2-isPosted'] = 1;
     $_POST['test3-isPosted'] = 1;
     // test that should pass
     $_POST['test1'] = array('one', 'two', 'three');
     $input = Form::checkbox('test1')->appendOptions(array('one' => 'one', 'two' => 'two', 'three' => 'three'));
     $this->validator->addValidation($input, 'required|all_in:one,two,three');
     $this->assertTrue($this->validator->run(), 'array of posted values should pass using all_in');
     // single posted value should pass
     $_POST['test2'] = 'two';
     $input = Form::checkbox('test2')->appendOptions(array('one' => 'one', 'two' => 'two', 'three' => 'three'));
     $this->validator->addValidation($input, 'all_in:one,two,three');
     $this->assertTrue($this->validator->run(), 'single posted value should pass using all_in');
     // this should fail
     $_POST['test3'] = array('one', 'two', 'FAIL');
     $input = Form::checkbox('test3')->appendOptions(array('one' => 'one', 'two' => 'two', 'three' => 'three'));
     $this->validator->addValidation($input, 'all_in:one,two,three');
     $this->assertFalse($this->validator->run(), 'array with a not allowed value should not pass using all_in');
 }