mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fix ControllerTestCase::testAction()
incompatibility with App.base
.
When using array URLs with `testAction()`, the generated URL possibly contains the configured `App.base` path, which needs to be stripped when set on the request object, as otherwise routes cannot be matched correctly. When passing the URL as an option to the `CakeRequest` constructor, the it will be set as-is, unlike when the URL is being generated by `CakeRequest::_url()`, which grabs the URL from the environment, and strips the possible base path.
This commit is contained in:
parent
0a378021a0
commit
7d74818d9a
2 changed files with 28 additions and 1 deletions
|
@ -624,4 +624,30 @@ class ControllerTestCaseTest extends CakeTestCase {
|
|||
$this->assertEquals($restored, $_POST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the `App.base` path is properly stripped from the URL generated from the
|
||||
* given URL array, and that consequently the correct controller/action is being matched.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAppBaseConfigCompatibilityWithArrayUrls() {
|
||||
Configure::write('App.base', '/cakephp');
|
||||
|
||||
$this->Case->generate('TestsApps');
|
||||
$this->Case->testAction(array('controller' => 'tests_apps', 'action' => 'index'));
|
||||
|
||||
$this->assertEquals('/cakephp', $this->Case->controller->request->base);
|
||||
$this->assertEquals('/cakephp/', $this->Case->controller->request->webroot);
|
||||
$this->assertEquals('/cakephp/tests_apps', $this->Case->controller->request->here);
|
||||
$this->assertEquals('tests_apps', $this->Case->controller->request->url);
|
||||
|
||||
$expected = array(
|
||||
'plugin' => null,
|
||||
'controller' => 'tests_apps',
|
||||
'action' => 'index',
|
||||
'named' => array(),
|
||||
'pass' => array(),
|
||||
);
|
||||
$this->assertEquals($expected, array_intersect_key($expected, $this->Case->controller->request->params));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -248,7 +248,8 @@ abstract class ControllerTestCase extends CakeTestCase {
|
|||
$_GET = array();
|
||||
}
|
||||
}
|
||||
$request = $this->getMock('CakeRequest', array('_readInput'), array($url));
|
||||
$_SERVER['REQUEST_URI'] = $url;
|
||||
$request = $this->getMock('CakeRequest', array('_readInput'));
|
||||
|
||||
if (is_string($options['data'])) {
|
||||
$request->expects($this->any())
|
||||
|
|
Loading…
Reference in a new issue