Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d7b835

Browse files
committed
[FrameworkBundle] added some functional tests
1 parent ff9d688 commit 5d7b835

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;
13+
14+
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\HttpFoundation\Response;
16+
use Symfony\Component\DependencyInjection\ContainerAware;
17+
use Symfony\Component\HttpKernel\Controller\ControllerReference;
18+
19+
class SubRequestController extends ContainerAware
20+
{
21+
public function indexAction()
22+
{
23+
$handler = $this->container->get('fragment.handler');
24+
25+
$errorUrl = $this->generateUrl('subrequest_fragment_error', array('_locale' => 'fr', '_format' => 'json'));
26+
$altUrl = $this->generateUrl('subrequest_fragment', array('_locale' => 'fr', '_format' => 'json'));
27+
28+
// simulates a failure during the rendering of a fragment...
29+
// should render fr/json
30+
$content = $handler->render($errorUrl, 'inline', array('alt' => $altUrl));
31+
32+
// ...to check that the FragmentListener still references the right Request
33+
// when rendering another fragment after the error occured
34+
// should render en/html instead of fr/json
35+
$content .= $handler->render(new ControllerReference('TestBundle:SubRequest:fragment'));
36+
37+
// forces the LocaleListener to set fr for the locale...
38+
// should render fr/json
39+
$content .= $handler->render($altUrl);
40+
41+
// ...and check that after the rendering, the original Request is back
42+
// and en is used as a locale
43+
// should use en/html instead of fr/json
44+
$content .= '--'.$this->generateUrl('subrequest_fragment');
45+
46+
// The RouterListener is also tested as if it does not keep the right
47+
// Request in the context, a 301 would be generated
48+
49+
return new Response($content);
50+
}
51+
52+
public function fragmentAction(Request $request)
53+
{
54+
return new Response('--'.$request->getLocale().'/'.$request->getRequestFormat());
55+
}
56+
57+
public function fragmentErrorAction()
58+
{
59+
throw new \RuntimeException('error');
60+
}
61+
62+
protected function generateUrl($name, $arguments = array())
63+
{
64+
return $this->container->get('router')->generate($name, $arguments);
65+
}
66+
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,18 @@ session_showflash:
2121
profiler:
2222
path: /profiler
2323
defaults: { _controller: TestBundle:Profiler:index }
24+
25+
subrequest_index:
26+
path: /subrequest/{_locale}.{_format}
27+
defaults: { _controller: TestBundle:SubRequest:index, _format: "html" }
28+
schemes: [https]
29+
30+
subrequest_fragment_error:
31+
path: /subrequest/fragment/error/{_locale}.{_format}
32+
defaults: { _controller: TestBundle:SubRequest:fragmentError, _format: "html" }
33+
schemes: [http]
34+
35+
subrequest_fragment:
36+
path: /subrequest/fragment/{_locale}.{_format}
37+
defaults: { _controller: TestBundle:SubRequest:fragment, _format: "html" }
38+
schemes: [http]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
13+
14+
/**
15+
* @group functional
16+
*/
17+
class SubRequestsTest extends WebTestCase
18+
{
19+
public function testStateAfterSubRequest()
20+
{
21+
$client = $this->createClient(array('test_case' => 'Session', 'root_config' => 'config.yml'));
22+
$client->request('GET', 'https://localhost/subrequest/en');
23+
24+
$this->assertEquals('--fr/json--en/html--fr/json--http://localhost/subrequest/fragment/en', $client->getResponse()->getContent());
25+
}
26+
}

0 commit comments

Comments
 (0)