robjingram
robjingram

Reputation: 306

CakePHP - testAction always creates a GET request

I'm trying to test a controller in CakePHP 1.3 that requires a POST request but testAction always generates a GET request. I've boiled it down to a simple example action that purely reports the request method using:

$this->RequestHandler->isPost()

Or

$this->RequestHandler->isGet()

The result is always GET, whether or not I set 'method' => 'post' or send a data array.

Forms of testAction I've tried:

$this->testAction('/testing/requesttype', array('method' => 'post'));
$this->testAction('/testing/requesttype', array('data' => array('Post' => array('title' => 'test')), 'method' => 'post'));
$this->testAction('/testing/requesttype', array('data' => array('Post' => array('title' => 'test'))));
$this->testAction('/testing/requesttype', array('form' => array('test' => 'test'), 'data' => array('Post' => array('title' => 'test')), 'method' => 'post'));

All of the above produce a GET request. If this can't be done in CakePHP 1.3, what is the point of 'method => 'post'?

Upvotes: 2

Views: 293

Answers (1)

SkarXa
SkarXa

Reputation: 1194

I do it this way, it's dirty but works for me:

    $_SERVER['REQUEST_METHOD'] = 'POST';
    $result = $this->testAction($url,
        array(
            'form' => $data
            )
        );

Upvotes: 1

Related Questions