[FrameworkBundle] added some functional tests
This commit is contained in:
parent
ff9d6883bb
commit
5d7b8356ab
@ -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);
|
||||
}
|
||||
}
|
@ -21,3 +21,18 @@ session_showflash:
|
||||
profiler:
|
||||
path: /profiler
|
||||
defaults: { _controller: TestBundle:Profiler:index }
|
||||
|
||||
subrequest_index:
|
||||
path: /subrequest/{_locale}.{_format}
|
||||
defaults: { _controller: TestBundle:SubRequest:index, _format: "html" }
|
||||
schemes: [https]
|
||||
|
||||
subrequest_fragment_error:
|
||||
path: /subrequest/fragment/error/{_locale}.{_format}
|
||||
defaults: { _controller: TestBundle:SubRequest:fragmentError, _format: "html" }
|
||||
schemes: [http]
|
||||
|
||||
subrequest_fragment:
|
||||
path: /subrequest/fragment/{_locale}.{_format}
|
||||
defaults: { _controller: TestBundle:SubRequest:fragment, _format: "html" }
|
||||
schemes: [http]
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user