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