これが私のUsersControllerテストケースです:
<?php
App::uses('UsersController', 'Controller');
class TestUsersController extends UsersController {
public $autoRender = false;
public function redirect($url, $status = null, $exit = true) {
$this->redirectUrl = $url;
}
public function render($action = null, $layout = null, $file = null) {
$this->renderedAction = $action;
}
public function _stop($status = 0) {
$this->stopped = $status;
}
}
class UsersControllerTestCase extends ControllerTestCase {
public $fixtures = array('app.user');
public function setUp() {
parent::setUp();
$this->Users = new TestUsersController();
$this->Users->constructClasses();
}
public function tearDown() {
unset($this->Users);
parent::tearDown();
}
public function testAdminSearchStudents() {
$data = array('User' => array('search' => 'Ipsum'));
$result = $this->testAction('/admin', array('return' => 'vars', 'method' => 'post', 'data' => $data));
$this->assertCount(1, $result['users']);
}
}
私のUsersControllerには特別なことは何もありませんが、SecurityComponent(AppControllerから継承)を使用します。
そして、私がテストを実行すると、私は悪名高いものになります:
リクエストはブラックホール化されていますテストケース:UsersControllerTestCase(testAdminSearchStudents)
CSRFトークンと参照なしでPOSTリクエストを偽造しているためだと思いますか?
コントローラからセキュリティコンポーネントを削除せずにこれを機能させるにはどうすればよいですか?
これが役立つかどうかはわかりませんが、スタックトレースの重要な部分は次のとおりです。
/var/www/source/cakephp/lib/Cake/Controller/Component/SecurityComponent.php : 230
SecurityComponent::startup
/var/www/source/cakephp/lib/Cake/Utility/ObjectCollection.php : 130
ObjectCollection::trigger
/var/www/source/cakephp/lib/Cake/Event/CakeEventManager.php : 246
/var/www/source/cakephp/lib/Cake/Controller/Controller.php : 671
/var/www/source/cakephp/lib/Cake/Routing/Dispatcher.php : 183
/var/www/source/cakephp/lib/Cake/Routing/Dispatcher.php : 161
/var/www/source/cakephp/lib/Cake/TestSuite/ControllerTestCase.php : 271
ControllerTestCase::_testAction
/var/www/source/cakephp/lib/Cake/TestSuite/ControllerTestCase.php : 189
よろしく