/** * Tests different types of validations. */ function test_All_Sorts_Of_Values() { // test a plain string $this->assertTrue(ArgumentValidator::validate("Hello!", StringValidatorRule::getRule(), true)); // test numeric values $this->assertTrue(ArgumentValidator::validate("23.21E10", NumericValidatorRule::getRule(), true)); $this->assertTrue(ArgumentValidator::validate(23, NumericValidatorRule::getRule(), true)); $this->assertTrue(ArgumentValidator::validate(23.21, NumericValidatorRule::getRule(), true)); // test integer values $this->assertTrue(ArgumentValidator::validate(23, IntegerValidatorRule::getRule(), true)); // test string values $this->assertTrue(ArgumentValidator::validate("23", StringValidatorRule::getRule(), true)); // test email values $this->assertTrue(ArgumentValidator::validate("*****@*****.**", EmailValidatorRule::getRule(), true)); $this->assertFalse(ArgumentValidator::validate("dradichk@middlebury", EmailValidatorRule::getRule(), false), "Gabe, fix this! Your EmailValidatorRule is faulty!"); // test boolean values $this->assertTrue(ArgumentValidator::validate(true, BooleanValidatorRule::getRule(), true)); $this->assertFalse(ArgumentValidator::validate("HOHO", BooleanValidatorRule::getRule(), false), "Gabe, fix this! Your BooleanValidatorRule is faulty!\nIn fact, I think you should just use is_bool() in your check() function."); }
function test_rule_set_add_multiple() { $this->assertEqual($this->testRuleSet->count(), 0); // what the hell is this??? // $error = 1; $error = new Error("UnitTest", "UnitTest", false); $rq = FieldRequiredValidatorRule::getRule(); $email = EmailValidatorRule::getRule(); $number = NumericValidatorRule::getRule(); $this->testRuleSet->addRule("mystring", $rq, $error); $this->testRuleSet->addRule("mystring", $email, $error); $this->testRuleSet->addRule("boolean", BooleanValidatorRule::getRule(), $error); $this->testRuleSet->addRule("mynumber", $number, $error); $this->assertEqual($this->testRuleSet->count(), 3); $this->assertReference($this->testRuleSet->_rules["mystring"][0][0], $rq); $this->assertReference($this->testRuleSet->_rules["mystring"][1][0], $email); $this->assertReference($this->testRuleSet->_rules["mynumber"][0][0], $number); // $this->assertEqual($this->testRuleSet->getKeys(), array("mystring","mynumber","boolean")); }