forked from symfony/symfony
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FrameworkBundle] added some functional tests
- Loading branch information
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
...le/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/SubRequestController.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,66 @@ | ||
<?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\Functional\Bundle\TestBundle\Controller; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\DependencyInjection\ContainerAware; | ||
use Symfony\Component\HttpKernel\Controller\ControllerReference; | ||
|
||
class SubRequestController extends ContainerAware | ||
{ | ||
public function indexAction() | ||
{ | ||
$handler = $this->container->get('fragment.handler'); | ||
|
||
$errorUrl = $this->generateUrl('subrequest_fragment_error', array('_locale' => 'fr', '_format' => 'json')); | ||
$altUrl = $this->generateUrl('subrequest_fragment', array('_locale' => 'fr', '_format' => 'json')); | ||
|
||
// simulates a failure during the rendering of a fragment... | ||
// should render fr/json | ||
$content = $handler->render($errorUrl, 'inline', array('alt' => $altUrl)); | ||
|
||
// ...to check that the FragmentListener still references the right Request | ||
// when rendering another fragment after the error occured | ||
// should render en/html instead of fr/json | ||
$content .= $handler->render(new ControllerReference('TestBundle:SubRequest:fragment')); | ||
|
||
// forces the LocaleListener to set fr for the locale... | ||
// should render fr/json | ||
$content .= $handler->render($altUrl); | ||
|
||
// ...and check that after the rendering, the original Request is back | ||
// and en is used as a locale | ||
// should use en/html instead of fr/json | ||
$content .= '--'.$this->generateUrl('subrequest_fragment'); | ||
|
||
// The RouterListener is also tested as if it does not keep the right | ||
// Request in the context, a 301 would be generated | ||
|
||
return new Response($content); | ||
} | ||
|
||
public function fragmentAction(Request $request) | ||
{ | ||
return new Response('--'.$request->getLocale().'/'.$request->getRequestFormat()); | ||
} | ||
|
||
public function fragmentErrorAction() | ||
{ | ||
throw new \RuntimeException('error'); | ||
} | ||
|
||
protected function generateUrl($name, $arguments = array()) | ||
{ | ||
return $this->container->get('router')->generate($name, $arguments); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SubRequestsTest.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,26 @@ | ||
<?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\Functional; | ||
|
||
/** | ||
* @group functional | ||
*/ | ||
class SubRequestsTest extends WebTestCase | ||
{ | ||
public function testStateAfterSubRequest() | ||
{ | ||
$client = $this->createClient(array('test_case' => 'Session', 'root_config' => 'config.yml')); | ||
$client->request('GET', 'https://localhost/subrequest/en'); | ||
|
||
$this->assertEquals('--fr/json--en/html--fr/json--http://localhost/subrequest/fragment/en', $client->getResponse()->getContent()); | ||
} | ||
} |