mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-06 11:32:40 +00:00
Fixing issues with request stack not being used correctly
when there are requestAction requests being performed. Adding Router::popRequest() to allow manipulation of request stack so nested requestAction or serial requestAction calls work correctly. Fixes #1906
This commit is contained in:
parent
3014d3fb84
commit
fdacc9de16
4 changed files with 52 additions and 8 deletions
|
@ -463,12 +463,14 @@ class ObjectTest extends CakeTestCase {
|
|||
'views' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS),
|
||||
'controllers' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Controller' . DS)
|
||||
), true);
|
||||
$this->assertNull(Router::getRequest(), 'request stack should be empty.');
|
||||
|
||||
$result = $this->object->requestAction('');
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = $this->object->requestAction('/request_action/test_request_action');
|
||||
$expected = 'This is a test';
|
||||
$this->assertEqual($expected, $result);;
|
||||
$this->assertEqual($expected, $result);
|
||||
|
||||
$result = $this->object->requestAction('/request_action/another_ra_test/2/5');
|
||||
$expected = 7;
|
||||
|
@ -488,6 +490,8 @@ class ObjectTest extends CakeTestCase {
|
|||
$result = $this->object->requestAction('/request_action/normal_request_action');
|
||||
$expected = 'Hello World';
|
||||
$this->assertEqual($expected, $result);
|
||||
|
||||
$this->assertNull(Router::getRequest(), 'requests were not popped off the stack, this will break url generation');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2298,6 +2298,35 @@ class RouterTest extends CakeTestCase {
|
|||
$this->assertEqual($result->webroot, '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that Router::url() uses the first request
|
||||
*/
|
||||
public function testUrlWithRequestAction() {
|
||||
$firstRequest = new CakeRequest('/posts/index');
|
||||
$firstRequest->addParams(array(
|
||||
'plugin' => null,
|
||||
'controller' => 'posts',
|
||||
'action' => 'index'
|
||||
))->addPaths(array('base' => ''));
|
||||
|
||||
$secondRequest = new CakeRequest('/posts/index');
|
||||
$secondRequest->addParams(array(
|
||||
'requested' => 1,
|
||||
'plugin' => null,
|
||||
'controller' => 'comments',
|
||||
'action' => 'listing'
|
||||
))->addPaths(array('base' => ''));
|
||||
|
||||
Router::setRequestInfo($firstRequest);
|
||||
Router::setRequestInfo($secondRequest);
|
||||
|
||||
$result = Router::url(array('base' => false));
|
||||
$this->assertEquals('/comments/listing', $result, 'with second requests, the last should win.');
|
||||
|
||||
Router::popRequest();
|
||||
$result = Router::url(array('base' => false));
|
||||
$this->assertEquals('/posts', $result, 'with second requests, the last should win.');
|
||||
}
|
||||
/**
|
||||
* test that a route object returning a full url is not modified.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue