public function test_validate_ivanov_returns_true()
 {
     $input = Input::createText("firstname")->setValue("ivanov");
     $validator = new RegexValidator('/ov$/');
     $validator->setInput($input);
     $result = $validator->validate();
     $this->assertTrue($result);
 }
 public function test_validate_valid_email_returns_true()
 {
     $input = Input::createText("email")->setValue("*****@*****.**");
     $validator = new EmailValidator();
     $validator->setInput($input);
     $result = $validator->validate();
     $this->assertTrue($result);
 }
Example #3
0
 public function test_validate_required_validator_on_name_is_not_valid()
 {
     $form = GetForm::create("/index.php")->addInput(Input::createText("firstName")->addValidator(new RequiredValidator()))->addInput(Input::createText("lastName"))->addInput(Input::createSubmit()->setValue("save"));
     $validationResult = $form->validate();
     $this->assertFalse($validationResult->isValid());
     $this->assertEquals(1, count($validationResult->getErrors()));
     /** @var ValidationException $error */
     $error = $validationResult->getErrors()[0];
     $this->assertEquals("Input value is empty.", $error->getMessage());
     $this->assertEquals("firstName", $error->getInput()->getName());
 }
 public function test_validate_string_throws_validation_exception_custom_try_catch()
 {
     $input = Input::createText("height")->setValue("five");
     $validator = new OnlyDigitsValidator();
     $validator->setInput($input);
     try {
         $validator->validate();
         $this->assertTrue(false, "This line must be unreachable.");
     } catch (ValidationException $ex) {
         $this->assertEquals("Input value has to contain only digits.", $ex->getMessage());
     }
 }
Example #5
0
 /**
  * Создает скрытый элемент (тип hidden)
  *
  * @param $name string - название
  * @param $value string - значение
  * @return Input
  */
 public static function createHidden($name, $value)
 {
     $input = new Input($name, "hidden");
     $input->setValue($value);
     return $input;
 }
Example #6
0
 public function test_createHidden_simple_use_case()
 {
     $hidden = Input::createHidden("process", "next page");
     $this->assertEquals("<input type=\"hidden\" name=\"process\" value=\"next page\"/>", $hidden->toString());
 }
Example #7
0
 private function createCSRFInput()
 {
     $token = $this->salt . ':' . md5($this->salt . ':' . $this->getSecretKey());
     $input = Input::createHidden(self::CSRF_FIELD_NAME, $token);
     $this->addInput($input);
 }