cakephp ControllerTest
发布时间:2020-12-13 22:10:29 所属栏目:PHP教程 来源:网络整理
导读:我是一个菜鸟,试图为Cakephp书的Blog Tutorial编写一个ControllerTest. 完成这项任务后,我找到了一个很好的例子,我可以适应. 这本书提供了以下示例: http://book.cakephp.org/2.0/en/development/testing.html#testing-controllers 所以我在/ app / Control
我是一个菜鸟,试图为Cakephp书的Blog Tutorial编写一个ControllerTest.
完成这项任务后,我找到了一个很好的例子,我可以适应. 这本书提供了以下示例: http://book.cakephp.org/2.0/en/development/testing.html#testing-controllers 所以我在/ app / Controller /中创建了一个ArticlesController.php文件,在/ app / Test / Case / Controller /中创建了一个ArticlesControllerTest.php 我的ArticlesController.php的内容是: <?php class ArticlesController extends ControllerTestCase { //public $fixtures = array('app.article'); public function testIndex() { $result = $this->testAction('/articles/index'); debug($result); } public function testIndexShort() { $result = $this->testAction('/articles/index/short'); debug($result); } public function testIndexShortGetRenderedHtml() { $result = $this->testAction( '/articles/index/short',array('return' => 'contents') ); debug($result); } public function testIndexShortGetViewVars() { $result = $this->testAction( '/articles/index/short',array('return' => 'vars') ); debug($result); } public function testIndexPostData() { $data = array( 'Article' => array( 'user_id' => 1,'published' => 1,'slug' => 'new-article','title' => 'New Article','body' => 'New Body' ) ); $result = $this->testAction( '/articles/index',array('data' => $data,'method' => 'post') ); debug($result); } } 而我的ArticlesController.php的内容是: <?php class ArticlesControllerTest extends ControllerTestCase { public $fixtures = array('app.article'); public function testIndex() { $result = $this->testAction('/articles/index'); debug($result); } public function testIndexShort() { $result = $this->testAction('/articles/index/short'); debug($result); } public function testIndexShortGetRenderedHtml() { $result = $this->testAction( '/articles/index/short',array('return' => 'contents') ); debug($result); } public function testIndexShortGetViewVars() { $result = $this->testAction( '/articles/index/short',array('return' => 'vars') ); debug($result); } public function testIndexPostData() { $data = array( 'Article' => array( 'user_id' => 1,'body' => 'New Body' ) ); $result = $this->testAction( '/articles/index','method' => 'post') ); debug($result); } } 我从书中复制了这些代码,并对夹具进行了评估. 错误:找不到类’AppController’ 大法错了? 解决方法
尝试将以下内容添加到ArticlesController文件的顶部:
App::uses('AppController','Controller'); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |