mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-18 02:39:56 +09:00
merged 1.5.0 branch into 1.5.0-DB
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0-DB@8547 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
4973c78fbc
commit
01d0925dd5
145 changed files with 990 additions and 31147 deletions
117
tests/classes/validator/ValidatorTest.php
Normal file
117
tests/classes/validator/ValidatorTest.php
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
|
||||
define('__DEBUG__', 1);
|
||||
$xe_path = realpath(dirname(__FILE__).'/../../../');
|
||||
require "{$xe_path}/classes/xml/XmlParser.class.php";
|
||||
require "{$xe_path}/classes/handler/Handler.class.php";
|
||||
require "{$xe_path}/classes/file/FileHandler.class.php";
|
||||
require "{$xe_path}/classes/validator/Validator.class.php";
|
||||
|
||||
error_reporting(E_ALL & ~E_NOTICE);
|
||||
|
||||
class ValidatorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function _testRequired() {
|
||||
$vd = new Validator();
|
||||
$vd->addFilter('userid', array('required'=>'true'));
|
||||
|
||||
// given data
|
||||
$this->assertFalse( $vd->validate(array('no-userid'=>'hello')) );
|
||||
$this->assertTrue( $vd->validate(array('userid'=>'myuserid')) );
|
||||
$this->assertFalse( $vd->validate(array('userid'=>'')) );
|
||||
|
||||
// context data
|
||||
$this->assertFalse( $vd->validate() );
|
||||
Context::set('userid', '');
|
||||
$this->assertFalse( $vd->validate() );
|
||||
Context::set('userid', 'myuserid');
|
||||
$this->assertTrue( $vd->validate() );
|
||||
$vd->removeFilter('userid');
|
||||
$this->assertTrue( $vd->validate() );
|
||||
}
|
||||
|
||||
public function testDefault() {
|
||||
global $mock_vars;
|
||||
|
||||
$vd = new Validator();
|
||||
$vd->addFilter('userid', array('default'=>'ididid'));
|
||||
|
||||
// given data
|
||||
$arr = array('no-userid'=>'');
|
||||
$vd->validate($arr);
|
||||
$this->assertEquals( $arr, array('no-userid'=>'') );
|
||||
|
||||
$arr = array('userid'=>'');
|
||||
$vd->validate(&$arr); // pass-by-reference
|
||||
$this->assertEquals( $arr, array('userid'=>'ididid') );
|
||||
|
||||
$arr = array('userid'=>'ownid');
|
||||
$vd->validate(&$arr);
|
||||
$this->assertEquals( $arr, array('userid'=>'ownid') );
|
||||
|
||||
// context data
|
||||
$mock_vars = array(); // empty context variables
|
||||
$vd->validate();
|
||||
$this->assertEquals( 'ididid', Context::get('userid') );
|
||||
|
||||
$vd->load(dirname(__FILE__).'/login.xml');
|
||||
|
||||
Context::set('userid', '');
|
||||
$vd->validate();
|
||||
$this->assertEquals( 'idididid', Context::get('userid') );
|
||||
}
|
||||
|
||||
public function testLength() {
|
||||
$vd = new Validator();
|
||||
|
||||
$vd->addFilter('field1', array('length'=>'3:'));
|
||||
$this->assertFalse( $vd->validate(array('field1'=>'ab')) );
|
||||
$this->assertTrue( $vd->validate(array('field1'=>'abc')) );
|
||||
$this->assertTrue( $vd->validate(array('field1'=>'abcd')) );
|
||||
}
|
||||
|
||||
public function testCustomRule() {
|
||||
}
|
||||
|
||||
public function testJSCompile() {
|
||||
}
|
||||
}
|
||||
|
||||
$mock_vars = array();
|
||||
|
||||
class Context
|
||||
{
|
||||
public function gets() {
|
||||
global $mock_vars;
|
||||
|
||||
$args = func_get_args();
|
||||
$output = new stdClass;
|
||||
|
||||
foreach($args as $name) {
|
||||
$output->{$name} = $mock_vars[$name];
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function getRequestVars() {
|
||||
global $mock_vars;
|
||||
|
||||
return $mock_vars;
|
||||
}
|
||||
|
||||
public function get($name) {
|
||||
global $mock_vars;
|
||||
return array_key_exists($name, $mock_vars)?$mock_vars[$name]:'';
|
||||
}
|
||||
|
||||
public function set($name, $value) {
|
||||
global $mock_vars;
|
||||
|
||||
$mock_vars[$name] = $value;
|
||||
}
|
||||
|
||||
public function getLangType() {
|
||||
return 'en';
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue