mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 19:21:40 +09:00
added a test for custom rule xml
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@10678 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
914dc85249
commit
72a4d6b0d1
2 changed files with 33 additions and 1 deletions
|
|
@ -117,7 +117,7 @@ class ValidatorTest extends PHPUnit_Framework_TestCase
|
|||
// regex
|
||||
$vd = new Validator();
|
||||
$customRules['regex_rule']['type'] = 'regex';
|
||||
$customRules['regex_rule']['test'] = '/[a-z]+/';
|
||||
$customRules['regex_rule']['test'] = '/^[a-z]+$/';
|
||||
$vd->addRule($customRules);
|
||||
$vd->addFilter('regex_field', array('rule' => 'regex_rule'));
|
||||
|
||||
|
|
@ -156,6 +156,23 @@ class ValidatorTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertFalse($vd->validate(array('expr_field' => '15')));
|
||||
}
|
||||
|
||||
public function testCustomRuleXml()
|
||||
{
|
||||
$vd = new Validator(dirname(__FILE__).'/customrule.xml');
|
||||
|
||||
$this->assertTrue($vd->validate(array('regex_field' => 'abc')));
|
||||
$this->assertFalse($vd->validate(array('regex_field' => 'ABC')));
|
||||
|
||||
$this->assertTrue($vd->validate(array('enum_field' => 'a')));
|
||||
$this->assertFalse($vd->validate(array('enum_field' => 'd')));
|
||||
|
||||
$this->assertTrue($vd->validate(array('enum_field2' => 'a')));
|
||||
$this->assertFalse($vd->validate(array('enum_field2' => 'd')));
|
||||
|
||||
$this->assertTrue($vd->validate(array('expr_field' => '5')));
|
||||
$this->assertFalse($vd->validate(array('expr_field' => '15')));
|
||||
}
|
||||
|
||||
public function testCondition() {
|
||||
$vd = new Validator();
|
||||
$data = array('greeting1'=>'hello');
|
||||
|
|
|
|||
15
tests/classes/validator/customrule.xml
Normal file
15
tests/classes/validator/customrule.xml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ruleset version="1.5.0">
|
||||
<customrules>
|
||||
<rule name="regex_rule" type="regex" test="/^[a-z]+$/" />
|
||||
<rule name="enum_rule" type="enum" test="a,b,c" />
|
||||
<rule name="enum_rule2" type="enum" test="a@b@c" delim="@" />
|
||||
<rule name="expr_rule" type="expr" test="$$ < 10" />
|
||||
</customrules>
|
||||
<fields>
|
||||
<field name="regex_field" rule="regex_rule" />
|
||||
<field name="enum_field" rule="enum_rule" />
|
||||
<field name="enum_field2" rule="enum_rule2" />
|
||||
<field name="expr_field" rule="expr_rule" />
|
||||
</fields>
|
||||
</ruleset>
|
||||
Loading…
Add table
Add a link
Reference in a new issue