controllerTest增加validate测试

This commit is contained in:
thinkphp
2016-03-22 12:23:28 +08:00
parent 13a108f0b4
commit 4c7995a600
2 changed files with 30 additions and 1 deletions

View File

@@ -124,6 +124,8 @@ class controllerTest extends \PHPUnit_Framework_TestCase
$viewFetch = $view->fetch($template, ['name' => 'ThinkPHP']);
$controllerFetch = $controller->fetch($template, ['name' => 'ThinkPHP']);
$this->assertEquals($controllerFetch, $viewFetch);
$controllerFetch = $controller->display($template, ['name' => 'ThinkPHP']);
$this->assertEquals($controllerFetch, $viewFetch);
}
public function testShow()
@@ -155,4 +157,31 @@ class controllerTest extends \PHPUnit_Framework_TestCase
$controller->engine('php');
$this->assertEquals('php', $view->engine);
}
public function testValidate()
{
$controller = new Foo;
$data = [
'username' => 'username',
'nickname' => 'nickname',
'password' => '123456',
'repassword' => '123456',
'email' => 'abc@abc.com',
'sex' => '0',
'age' => '20',
'code' => '1234',
];
$validate = [
['username', 'length:5,15', '用户名长度为5到15个字符'],
['nickname', 'require', '请填昵称'],
['password', '[\w-]{6,15}', '密码长度为6到15个字符'],
['repassword', 'confirm:password', '两次密码不一到致'],
['email', 'filter:validate_email', '邮箱格式错误'],
['sex', 'in:0,1', '性别只能为为男或女'],
['age', 'between:1,80', '年龄只能在10-80之间'],
];
$result = $controller->validate($data, $validate);
$this->assertTrue($result);
}
}