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); }
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()); } }
public function test_textInput_toString_only_with_name() { $textInput = Input::createText("my_input"); $this->assertEquals("<input type=\"text\" name=\"my_input\"/>", $textInput->toString()); }