完善validateTest

This commit is contained in:
thinkphp
2016-03-22 17:37:05 +08:00
parent 8871422e7c
commit c9ecc6a86b

View File

@@ -47,28 +47,29 @@ class validateTest extends \PHPUnit_Framework_TestCase
public function testRule()
{
$rule = [
'name' => 'require|alphaNum|max:25',
'account' => 'alphaDash|min:4|length:4,30',
'name' => 'require|alphaNum|max:25|expire:2016-1-1,2026-1-1',
'account' => 'requireIf:name,thinkphp|alphaDash|min:4|length:4,30',
'age' => 'number|between:1,120',
'email' => 'email',
'url' => 'activeUrl',
'email' => 'requireWith:name|email',
'host' => 'activeUrl',
'url' => 'url',
'ip' => 'ip',
'score' => 'float|gt:60|notBetween:90,100|notIn:70,80|lt:100|elt:100|egt:60',
'status' => 'integer|in:0,1,2',
'begin_time' => 'after:2016-3-18',
'end_time' => 'before:2016-10-01',
'info' => 'require|array',
'info.name' => 'require|same:thinkphp',
'info.name' => 'require|length:8|alpha|same:thinkphp',
'value' => 'same:100',
'bool' => 'boolean',
];
$data = [
'name' => 'thinkphp',
'account' => 'liuchen',
'age' => 10,
'email' => 'thinkphp@qq.com',
'url' => 'thinkphp.cn',
'host' => 'thinkphp.cn',
'url' => 'http://thinkphp.cn/topic',
'ip' => '114.34.54.5',
'score' => '89.15',
'status' => 1,
@@ -80,7 +81,6 @@ class validateTest extends \PHPUnit_Framework_TestCase
'ok' => 'yes',
'value' => 100,
'bool' => 'true',
];
$validate = new Validate($rule);
$validate->rule('zip', '/^\d{6}$/');
@@ -163,17 +163,19 @@ class validateTest extends \PHPUnit_Framework_TestCase
'name|名称' => 'require|max:25',
'age' => 'number|between:1,120',
'email' => 'email',
['sex', 'in:1,2', '性别错误'],
];
$data = [
'name' => '',
'age' => 10,
'email' => 'thinkphp@qq.com',
'sex' => '3',
];
$validate = new Validate($rule);
$validate->setTypeMsg('require', ':attribute必须');
$result = $validate->check($data);
$result = $validate->batch()->check($data);
$this->assertFalse($result);
$this->assertEquals('名称必须', $validate->getError());
$this->assertEquals(['name' => '名称必须', 'sex' => '性别错误'], $validate->getError());
}
}