From 19a446c7debfb6fc99a789889040c5bc74d9c4c6 Mon Sep 17 00:00:00 2001 From: Haotong Lin Date: Thu, 3 Mar 2016 00:02:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/README.md | 8 +-- .../thinkphp/library/think/controllerTest.php | 65 +++++++++++++++++-- tests/thinkphp/library/think/cookieTest.php | 2 +- 3 files changed, 63 insertions(+), 12 deletions(-) diff --git a/tests/README.md b/tests/README.md index 2062bd53..8de71e33 100644 --- a/tests/README.md +++ b/tests/README.md @@ -110,15 +110,15 @@ thinkphp5 的测试的主要流程是跟 thinkphp 的系统流程是相似的, |Base||| |App|Haotong Lin|| |Build|刘志淳|| -|Config|Haotong Lin|| +|Config|Haotong Lin|√| |Cache||| -|Controller|Haotong Lin|| -|Cookie|Haotong Lin|| +|Controller|Haotong Lin|√| +|Cookie|Haotong Lin|√| |Db||| |Debug|大漠|√| |Error|大漠|| |Hook|流年|√| -|Input|Haotong Lin|| +|Input|Haotong Lin|√| |Lang|流年|√| |Loader|流年|| |Log||| diff --git a/tests/thinkphp/library/think/controllerTest.php b/tests/thinkphp/library/think/controllerTest.php index 00ad6c0d..91be8389 100644 --- a/tests/thinkphp/library/think/controllerTest.php +++ b/tests/thinkphp/library/think/controllerTest.php @@ -16,9 +16,12 @@ namespace tests\thinkphp\library\think; +use ReflectionClass; +use think\Controller; + require_once CORE_PATH . '../../helper.php'; -class Foo extends \think\Controller +class Foo extends Controller { public $test = 'test'; @@ -28,7 +31,7 @@ class Foo extends \think\Controller } } -class Bar extends \think\Controller +class Bar extends Controller { public $test = 1; @@ -47,15 +50,15 @@ class Bar extends \think\Controller } } -class Baz extends \think\Controller +class Baz extends Controller { public $test = 1; public $beforeActionList = [ - 'action1' => ['only' => ['index']], - 'action2' => ['except' => ['index']], - 'action3' => ['only' => ['abcd']], - 'action4' => ['except' => ['abcd']], + 'action1' => ['only' => 'index'], + 'action2' => ['except' => 'index'], + 'action3' => ['only' => 'abcd'], + 'action4' => ['except' => 'abcd'], ]; public function action1() @@ -101,4 +104,52 @@ class controllerTest extends \PHPUnit_Framework_TestCase $obj = new Baz; $this->assertEquals(19, $obj->test); } + + private function getView($controller) + { + $rc = new ReflectionClass(get_class($controller)); + $property = $rc->getProperty('view'); + $property->setAccessible(true); + return $property->getValue($controller); + } + + public function testFetch() + { + $controller = new Foo; + $view = $this->getView($controller); + $template = __DIR__ . '/display'; + $viewFetch = $view->fetch($template, ['name' => 'ThinkPHP']); + $controllerFetch = $controller->fetch($template, ['name' => 'ThinkPHP']); + $this->assertEquals($controllerFetch, $viewFetch); + } + + public function testShow() + { + $controller = new Foo; + $view = $this->getView($controller); + $template = __DIR__ . '/display'; + $viewFetch = $view->show($template, ['name' => 'ThinkPHP']); + $controllerFetch = $controller->show($template, ['name' => 'ThinkPHP']); + $this->assertEquals($controllerFetch, $viewFetch); + } + + public function testAssign() + { + $controller = new Foo; + $view = $this->getView($controller); + $controller->assign('abcd', 'dcba'); + $controller->assign(['key1' => 'value1', 'key2' => 'value2']); + $expect = ['abcd' => 'dcba', 'key1' => 'value1', 'key2' => 'value2']; + $this->assertAttributeEquals($expect, 'data', $view); + } + + public function testEngine() + { + $controller = new Foo; + $view = $this->getView($controller); + $view->engine = null; + $this->assertEquals(null, $view->engine); + $controller->engine('php'); + $this->assertEquals('php', $view->engine); + } } diff --git a/tests/thinkphp/library/think/cookieTest.php b/tests/thinkphp/library/think/cookieTest.php index 24cb153e..885fec7f 100644 --- a/tests/thinkphp/library/think/cookieTest.php +++ b/tests/thinkphp/library/think/cookieTest.php @@ -37,7 +37,7 @@ class cookieTest extends \PHPUnit_Framework_TestCase // httponly设置 'httponly' => '', // 是否使用 setcookie - 'setcookie' => false, + 'setcookie' => true, ]; protected function setUp()