mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
parent
a5d497068b
commit
493ce3a442
2 changed files with 36 additions and 9 deletions
|
@ -425,6 +425,21 @@ class ControllerTestCaseTest extends CakeTestCase {
|
|||
$this->assertTrue(isset($query['blue']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that REST actions with XML/JSON input work.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTestActionJsonData() {
|
||||
$result = $this->Case->testAction('/tests_apps_posts/input_data', array(
|
||||
'return' => 'vars',
|
||||
'method' => 'post',
|
||||
'data' => '{"key":"value","json":true}'
|
||||
));
|
||||
$this->assertEquals('value', $result['data']['key']);
|
||||
$this->assertTrue($result['data']['json']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests autoMock ability
|
||||
*/
|
||||
|
|
|
@ -187,11 +187,14 @@ abstract class ControllerTestCase extends CakeTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests a controller action.
|
||||
* Lets you do functional tests of a controller action.
|
||||
*
|
||||
* ### Options:
|
||||
*
|
||||
* - `data` POST or GET data to pass. Depends on the method.
|
||||
* - `data` Will be used as the request data. If the `method` is GET,
|
||||
* data will be used a GET params. If the `method` is POST, it will be used
|
||||
* as POST data. By setting `$options['data']` to a string, you can simulate XML or JSON
|
||||
* payloads to your controllers allowing you to test REST webservices.
|
||||
* - `method` POST or GET. Defaults to POST.
|
||||
* - `return` Specify the return type you want. Choose from:
|
||||
* - `vars` Get the set view variables.
|
||||
|
@ -213,14 +216,23 @@ abstract class ControllerTestCase extends CakeTestCase {
|
|||
), $options);
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = strtoupper($options['method']);
|
||||
if (strtoupper($options['method']) == 'GET') {
|
||||
$_GET = $options['data'];
|
||||
$_POST = array();
|
||||
} else {
|
||||
$_POST = $options['data'];
|
||||
$_GET = array();
|
||||
if (is_array($options['data'])) {
|
||||
if (strtoupper($options['method']) == 'GET') {
|
||||
$_GET = $options['data'];
|
||||
$_POST = array();
|
||||
} else {
|
||||
$_POST = $options['data'];
|
||||
$_GET = array();
|
||||
}
|
||||
}
|
||||
$request = new CakeRequest($url);
|
||||
$request = $this->getMock('CakeRequest', array('_readInput'), array($url));
|
||||
|
||||
if (is_string($options['data'])) {
|
||||
$request->expects($this->any())
|
||||
->method('_readInput')
|
||||
->will($this->returnValue($options['data']));
|
||||
}
|
||||
|
||||
$Dispatch = new ControllerTestDispatcher();
|
||||
foreach (Router::$routes as $route) {
|
||||
if ($route instanceof RedirectRoute) {
|
||||
|
|
Loading…
Reference in a new issue