-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed request format when forwarding a request
- Loading branch information
Showing
4 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Tests\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Tests\TestCase; | ||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class ControllerTest extends TestCase | ||
{ | ||
public function testForward() | ||
{ | ||
$request = Request::create('/'); | ||
$request->setLocale('fr'); | ||
$request->setRequestFormat('xml'); | ||
|
||
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); | ||
$kernel->expects($this->once())->method('handle')->will($this->returnCallback(function (Request $request) { | ||
return new Response($request->getRequestFormat().'--'.$request->getLocale()); | ||
})); | ||
|
||
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); | ||
$container->expects($this->at(0))->method('get')->will($this->returnValue($request)); | ||
$container->expects($this->at(1))->method('get')->will($this->returnValue($kernel)); | ||
|
||
$controller = new Controller(); | ||
$controller->setContainer($container); | ||
|
||
$response = $controller->forward('a_controller'); | ||
$this->assertEquals('xml--fr', $response->getContent()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7e87eb1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know I'm kinda late to comment this commit, but I think that this is a regression. When you forward a request, you may need to interpolate the
format
on your own ; here, you set it by default to "html" if no format was given (when it could be handled in the forwarded controller or whatever). When doing agetRequestFormat
on the forwarded part, you then get the default format.I know this is easily manageable (through in the forwarded controller setting this value to
null
again), but I still think this is a regression.7e87eb1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Taluu Can you open a new issue?
7e87eb1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirm this is a regression.
It should be
_format
as the controller variable is also called$_format
. If the_format
variable is set in my URL with ajson
value, then I'm getting an html stack trace instead of a json stack trace.7e87eb1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reported #9083 that details how the removal of _format in ExceptionListener effects the ExceptionController in the TwigBundle.
7e87eb1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the same problem as @hhamon in the current master branch!