mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-09 03:32:00 +09:00
issue 74: Implement conditional statement in rulesets
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@8582 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
e0c298d958
commit
1e70e0240b
4 changed files with 107 additions and 10 deletions
|
|
@ -75,6 +75,42 @@ class ValidatorTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
public function testJSCompile() {
|
||||
}
|
||||
|
||||
public function testCondition() {
|
||||
$vd = new Validator();
|
||||
$data = array('greeting1'=>'hello');
|
||||
|
||||
// No condition
|
||||
$vd->addFilter('greeting1', array('required'=>'true'));
|
||||
$this->assertTrue($vd->validate($data));
|
||||
|
||||
// Now greeting2 being mandatory if greeting1 is 'Hello'
|
||||
$vd->addFilter('greeting2', array('if'=>array('test'=>'$greeting1 == "Hello"', 'attr'=>'required', 'value'=>'true')));
|
||||
|
||||
// Because greeting1 is 'hello', including lowercase 'h', greeting2 isn't required yet.
|
||||
$this->assertTrue($vd->validate($data));
|
||||
|
||||
// Change the value of greeting1. Greeting2 is required now
|
||||
$data['greeting1'] = 'Hello';
|
||||
$this->assertFalse($vd->validate($data));
|
||||
|
||||
$data['greeting2'] = 'World';
|
||||
$this->assertTrue($vd->validate($data));
|
||||
}
|
||||
|
||||
public function testConditionXml() {
|
||||
$vd = new Validator(dirname(__FILE__).'/condition.xml');
|
||||
$data = array('greeting1'=>'hello');
|
||||
|
||||
$this->assertTrue($vd->validate($data));
|
||||
|
||||
// Change the value of greeting1. Greeting2 is required now
|
||||
$data['greeting1'] = 'Hello';
|
||||
$this->assertFalse($vd->validate($data));
|
||||
|
||||
$data['greeting2'] = 'World';
|
||||
$this->assertTrue($vd->validate($data));
|
||||
}
|
||||
}
|
||||
|
||||
$mock_vars = array();
|
||||
|
|
|
|||
9
tests/classes/validator/condition.xml
Normal file
9
tests/classes/validator/condition.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ruleset version="1.5.0">
|
||||
<fields>
|
||||
<field name="greeting1" required="true" />
|
||||
<field name="greeting2">
|
||||
<if test="$greeting1 == 'Hello'" attr="required" value="true" />
|
||||
</field>
|
||||
</fields>
|
||||
</ruleset>
|
||||
Loading…
Add table
Add a link
Reference in a new issue