How to pass querystring to testAction in CakePHP 1.2?

In CakePHP, adding a request to a URL does not automatically parse and split, as usual, when the controller is called directly.

For example:

$this->testAction('/testing/post?company=utCompany', array('return' => 'vars')) ;

will result in:

[url] => /testing/post?company=utCompany

When calling the URL directly through a web browser, the results are:

[url] => Array
    (
        [url] => testing/post
        [company] => utCompany
    )

Without editing the CakePHP source, is there a way to split the query when running unit tests?

+5
source share
4 answers

I have something that is either a hack (i.e. might not work for future CakePHP releases), or an undocumented function.

testAction 'url', $this- > params . , .

$data = array ('company' => 'utCompany') ;

$result = $this->testAction('/testing/post', array
(
    'return' => 'vars', 
    'method' => 'get', 
    'url' => $data)
) ; 

, . , .

+3

Cake 1.3. testAction :

$this->__savedGetData['company'] = 'utcompany';

+1

CakePHP URL-, , . CakePHP, .

querystring PHP explode.

, - :

$result = explode ('&', $queryString, -1) ;

, , :

$keyPair = explode ('=', $result[n], -1) ;

However, all this says that it would be better to look under the hood of CakePHP and see what they do.

What I typed above does not correctly handle situations in which your request contains html escaped characters (with the & prefix), and also does not process URL-encoded strings.

0
source

use _GET ['parmname'];

-1
source

All Articles