Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / symfony / http-kernel / Tests / Fragment / FragmentHandlerTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
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\Component\HttpKernel\Tests\Fragment;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpFoundation\Request;
16 use Symfony\Component\HttpFoundation\Response;
17 use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
18
19 /**
20  * @group time-sensitive
21  */
22 class FragmentHandlerTest extends TestCase
23 {
24     private $requestStack;
25
26     protected function setUp()
27     {
28         $this->requestStack = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\RequestStack')
29             ->disableOriginalConstructor()
30             ->getMock()
31         ;
32         $this->requestStack
33             ->expects($this->any())
34             ->method('getCurrentRequest')
35             ->will($this->returnValue(Request::create('/')))
36         ;
37     }
38
39     /**
40      * @expectedException \InvalidArgumentException
41      */
42     public function testRenderWhenRendererDoesNotExist()
43     {
44         $handler = new FragmentHandler($this->requestStack);
45         $handler->render('/', 'foo');
46     }
47
48     /**
49      * @expectedException \InvalidArgumentException
50      */
51     public function testRenderWithUnknownRenderer()
52     {
53         $handler = $this->getHandler($this->returnValue(new Response('foo')));
54
55         $handler->render('/', 'bar');
56     }
57
58     /**
59      * @expectedException \RuntimeException
60      * @expectedExceptionMessage Error when rendering "http://localhost/" (Status code is 404).
61      */
62     public function testDeliverWithUnsuccessfulResponse()
63     {
64         $handler = $this->getHandler($this->returnValue(new Response('foo', 404)));
65
66         $handler->render('/', 'foo');
67     }
68
69     public function testRender()
70     {
71         $handler = $this->getHandler($this->returnValue(new Response('foo')), array('/', Request::create('/'), array('foo' => 'foo', 'ignore_errors' => true)));
72
73         $this->assertEquals('foo', $handler->render('/', 'foo', array('foo' => 'foo')));
74     }
75
76     protected function getHandler($returnValue, $arguments = array())
77     {
78         $renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock();
79         $renderer
80             ->expects($this->any())
81             ->method('getName')
82             ->will($this->returnValue('foo'))
83         ;
84         $e = $renderer
85             ->expects($this->any())
86             ->method('render')
87             ->will($returnValue)
88         ;
89
90         if ($arguments) {
91             \call_user_func_array(array($e, 'with'), $arguments);
92         }
93
94         $handler = new FragmentHandler($this->requestStack);
95         $handler->addRenderer($renderer);
96
97         return $handler;
98     }
99 }