From 4c7995a600d1460053bd9f1314450c1f68673135 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 22 Mar 2016 12:23:28 +0800 Subject: [PATCH] =?UTF-8?q?controllerTest=E5=A2=9E=E5=8A=A0validate?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../thinkphp/library/think/controllerTest.php | 29 +++++++++++++++++++ tests/thinkphp/library/think/debugTest.php | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/thinkphp/library/think/controllerTest.php b/tests/thinkphp/library/think/controllerTest.php index e9a8175c..d5acd08b 100644 --- a/tests/thinkphp/library/think/controllerTest.php +++ b/tests/thinkphp/library/think/controllerTest.php @@ -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); + } } diff --git a/tests/thinkphp/library/think/debugTest.php b/tests/thinkphp/library/think/debugTest.php index cec0ecac..14d2b884 100644 --- a/tests/thinkphp/library/think/debugTest.php +++ b/tests/thinkphp/library/think/debugTest.php @@ -135,7 +135,7 @@ class debugTest extends \PHPUnit_Framework_TestCase $str .= "mem"; } $memPeak = Debug::getMemPeak($start, $end); - $this->assertLessThan(400, explode(" ", $memPeak)[0]); + $this->assertLessThan(500, explode(" ", $memPeak)[0]); } /**