diff --git a/library/think/Controller.php b/library/think/Controller.php index 9f58fc27..0f9ebc74 100644 --- a/library/think/Controller.php +++ b/library/think/Controller.php @@ -82,7 +82,7 @@ class Controller } /** - * 加载模板和页面输出 可以返回输出内容 + * 加载模板输出 * @access public * @param string $template 模板文件名 * @param array $vars 模板输出变量 @@ -95,7 +95,7 @@ class Controller } /** - * 加载模板和页面输出 可以返回输出内容 + * 渲染内容输出 * @access public * @param string $template 模板文件名 * @param array $vars 模板输出变量 @@ -107,18 +107,6 @@ class Controller return $this->view->display($template, $vars, $config); } - /** - * 渲染内容输出 - * @access public - * @param string $content 内容 - * @param array $vars 模板输出变量 - * @return mixed - */ - public function show($content, $vars = []) - { - return $this->view->show($content, $vars); - } - /** * 模板变量赋值 * @access protected diff --git a/library/think/View.php b/library/think/View.php index d91c699a..9494ecd8 100644 --- a/library/think/View.php +++ b/library/think/View.php @@ -30,9 +30,11 @@ class View 'engine_config' => [], ]; - public function __construct(array $config = []) + public function __construct($config = []) { - $this->config($config); + if (is_array($config)) { + $this->config($config); + } } /** @@ -41,7 +43,7 @@ class View * @param array $config 配置参数 * @return object */ - public static function instance(array $config = []) + public static function instance($config = []) { if (is_null(self::$instance)) { self::$instance = new self($config); diff --git a/tests/thinkphp/library/think/controllerTest.php b/tests/thinkphp/library/think/controllerTest.php index d5acd08b..5a4a8397 100644 --- a/tests/thinkphp/library/think/controllerTest.php +++ b/tests/thinkphp/library/think/controllerTest.php @@ -124,17 +124,15 @@ 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() + public function testDisplay() { $controller = new Foo; $view = $this->getView($controller); $template = dirname(__FILE__) . '/display.html'; - $viewFetch = $view->show($template, ['name' => 'ThinkPHP']); - $controllerFetch = $controller->show($template, ['name' => 'ThinkPHP']); + $viewFetch = $view->display($template, ['name' => 'ThinkPHP']); + $controllerFetch = $controller->display($template, ['name' => 'ThinkPHP']); $this->assertEquals($controllerFetch, $viewFetch); } @@ -148,16 +146,6 @@ class controllerTest extends \PHPUnit_Framework_TestCase $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); - } - public function testValidate() { $controller = new Foo; diff --git a/tests/thinkphp/library/think/templateTest.php b/tests/thinkphp/library/think/templateTest.php index 3d4653f5..fb7725c6 100644 --- a/tests/thinkphp/library/think/templateTest.php +++ b/tests/thinkphp/library/think/templateTest.php @@ -319,14 +319,14 @@ EOF; $template = new Template(); $template->assign('name', 'name'); $config = [ - 'strip_space' => true, - 'view_path' => dirname(__FILE__) . '/', - 'cache_id' => '__CACHE_ID__', - 'display_cache'=> true + 'strip_space' => true, + 'view_path' => dirname(__FILE__) . '/', + 'cache_id' => '__CACHE_ID__', + 'display_cache' => true, ]; $data = ['name' => 'value']; $template->layout('layout')->display('display', $data, $config); - $this->expectOutputString('value'); + $this->expectOutputString('
value
'); } public function testFetch() @@ -385,7 +385,7 @@ EOF; $template->fetch($content); $this->expectOutputString($content2); // $template->parse($content); -// var_dump($content); + // var_dump($content); } public function testVarAssign() @@ -406,7 +406,7 @@ EOF; public function testIsCache() { - $template = new Template(['cache_id' => '__CACHE_ID__','display_cache' => true]); + $template = new Template(['cache_id' => '__CACHE_ID__', 'display_cache' => true]); $this->assertTrue(!$template->isCache('__CACHE_ID__')); $template->display_cache = false; $this->assertTrue(!$template->isCache('__CACHE_ID__'));