Skip to content

Commit

Permalink
Backport array support for testAction()
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Dec 23, 2014
1 parent 6db96d5 commit 53f1390
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 11 additions & 0 deletions lib/Cake/Test/Case/TestSuite/ControllerTestCaseTest.php
Expand Up @@ -299,6 +299,17 @@ public function testTestAction() {
$this->assertEquals($expected, $results);
}

/**
* Test array URLs with testAction()
*
* @return void
*/
public function testTestActionArrayUrls() {
$Controller = $this->Case->generate('TestsApps');
$this->Case->testAction(array('controller' => 'tests_apps', 'action' => 'index'));
$this->assertInternalType('array', $this->Case->controller->viewVars);
}

/**
* Make sure testAction() can hit plugin controllers.
*
Expand Down
8 changes: 6 additions & 2 deletions lib/Cake/TestSuite/ControllerTestCase.php
Expand Up @@ -210,12 +210,12 @@ public function __call($name, $arguments) {
* - `result` Get the return value of the controller action. Useful
* for testing requestAction methods.
*
* @param string $url The url to test
* @param string|array $url The url to test
* @param array $options See options
* @return mixed The specified return type.
* @triggers ControllerTestCase $Dispatch, array('request' => $request)
*/
protected function _testAction($url = '', $options = array()) {
protected function _testAction($url, $options = array()) {
$this->vars = $this->result = $this->view = $this->contents = $this->headers = null;

$options += array(
Expand All @@ -224,6 +224,10 @@ protected function _testAction($url = '', $options = array()) {
'return' => 'result'
);

if (is_array($url)) {
$url = Router::url($url);
}

$restore = array('get' => $_GET, 'post' => $_POST);

$_SERVER['REQUEST_METHOD'] = strtoupper($options['method']);
Expand Down

0 comments on commit 53f1390

Please sign in to comment.