Fixing issue with CakeTestCase::testAction not properly being able to simulate query string parameters.

Added tests for various parameter syntaxes.  
Closes #5400

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7585 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2008-09-09 16:48:52 +00:00
parent a14e939ac4
commit 8e6a5a7214
3 changed files with 45 additions and 2 deletions

View file

@ -250,6 +250,39 @@ class CakeTestCaseTest extends CakeTestCase {
$result = $this->Case->testAction('/tests_apps_posts/add', array('return' => 'vars'));
$this->assertTrue(array_key_exists('posts', $result));
$this->assertEqual(count($result['posts']), 1);
$result = $this->Case->testAction('/tests_apps_posts/url_var/var1:value1/var2:val2', array(
'return' => 'vars',
'method' => 'get',
));
$this->assertEqual(array_keys($result['params']['url']), array('case', 'output', 'url'));
$this->assertEqual(array_keys($result['params']['named']), array('var1', 'var2'));
$result = $this->Case->testAction('/tests_apps_posts/url_var/gogo/val2', array(
'return' => 'vars',
'method' => 'get',
));
$this->assertEqual($result['params']['pass'], array('gogo', 'val2'));
$result = $this->Case->testAction('/tests_apps_posts/url_var', array(
'return' => 'vars',
'method' => 'get',
'data' => array(
'red' => 'health',
'blue' => 'mana'
)
));
$this->assertEqual(array_keys($result['params']['url']), array('case', 'output', 'red', 'blue', 'url'));
$result = $this->Case->testAction('/tests_apps_posts/post_var', array(
'return' => 'vars',
'method' => 'post',
'data' => array(
'name' => 'is jonas',
'pork' => 'and beans',
)
));
$this->assertEqual(array_keys($result['data']), array('name', 'pork'));
Configure::write('controllerPaths', $_back['controller']);
Configure::write('viewPaths', $_back['view']);

View file

@ -265,14 +265,14 @@ class CakeTestCase extends UnitTestCase {
: $this->__savedGetData;
$data = (!empty($params['data']))
? array('data' => $params['data'])
? $params['data']
: array();
if (strtolower($params['method']) == 'get') {
$_GET = array_merge($this->__savedGetData, $data);
$_POST = array();
} else {
$_POST = $data;
$_POST = array('data' => $data);
$_GET = $this->__savedGetData;
}

View file

@ -43,6 +43,16 @@ class TestsAppsPostsController extends AppController {
$this->set('posts', $this->Post->find('all'));
$this->render('index');
}
function url_var() {
$this->set('params', $this->params);
$this->render('index');
}
function post_var() {
$this->set('data', $this->data);
$this->render('index');
}
}
?>