Skip to content

Commit

Permalink
[FrameworkBundle] added some functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Mar 20, 2013
1 parent ff9d688 commit 5d7b835
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
@@ -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);
}
}
Expand Up @@ -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());
}
}

0 comments on commit 5d7b835

Please sign in to comment.