Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / symfony / http-kernel / Tests / Fragment / HIncludeFragmentRendererTest.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\HttpKernel\Controller\ControllerReference;
17 use Symfony\Component\HttpKernel\Fragment\HIncludeFragmentRenderer;
18 use Symfony\Component\HttpKernel\UriSigner;
19
20 class HIncludeFragmentRendererTest extends TestCase
21 {
22     /**
23      * @expectedException \LogicException
24      */
25     public function testRenderExceptionWhenControllerAndNoSigner()
26     {
27         $strategy = new HIncludeFragmentRenderer();
28         $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'));
29     }
30
31     public function testRenderWithControllerAndSigner()
32     {
33         $strategy = new HIncludeFragmentRenderer(null, new UriSigner('foo'));
34
35         $this->assertEquals('<hx:include src="/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dmain_controller&amp;_hash=BP%2BOzCD5MRUI%2BHJpgPDOmoju00FnzLhP3TGcSHbbBLs%3D"></hx:include>', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
36     }
37
38     public function testRenderWithUri()
39     {
40         $strategy = new HIncludeFragmentRenderer();
41         $this->assertEquals('<hx:include src="/foo"></hx:include>', $strategy->render('/foo', Request::create('/'))->getContent());
42
43         $strategy = new HIncludeFragmentRenderer(null, new UriSigner('foo'));
44         $this->assertEquals('<hx:include src="/foo"></hx:include>', $strategy->render('/foo', Request::create('/'))->getContent());
45     }
46
47     public function testRenderWithDefault()
48     {
49         // only default
50         $strategy = new HIncludeFragmentRenderer();
51         $this->assertEquals('<hx:include src="/foo">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default'))->getContent());
52
53         // only global default
54         $strategy = new HIncludeFragmentRenderer(null, null, 'global_default');
55         $this->assertEquals('<hx:include src="/foo">global_default</hx:include>', $strategy->render('/foo', Request::create('/'), array())->getContent());
56
57         // global default and default
58         $strategy = new HIncludeFragmentRenderer(null, null, 'global_default');
59         $this->assertEquals('<hx:include src="/foo">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default'))->getContent());
60     }
61
62     public function testRenderWithAttributesOptions()
63     {
64         // with id
65         $strategy = new HIncludeFragmentRenderer();
66         $this->assertEquals('<hx:include src="/foo" id="bar">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default', 'id' => 'bar'))->getContent());
67
68         // with attributes
69         $strategy = new HIncludeFragmentRenderer();
70         $this->assertEquals('<hx:include src="/foo" p1="v1" p2="v2">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default', 'attributes' => array('p1' => 'v1', 'p2' => 'v2')))->getContent());
71
72         // with id & attributes
73         $strategy = new HIncludeFragmentRenderer();
74         $this->assertEquals('<hx:include src="/foo" p1="v1" p2="v2" id="bar">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default', 'id' => 'bar', 'attributes' => array('p1' => 'v1', 'p2' => 'v2')))->getContent());
75     }
76
77     public function testRenderWithDefaultText()
78     {
79         $engine = $this->getMockBuilder('Symfony\\Component\\Templating\\EngineInterface')->getMock();
80         $engine->expects($this->once())
81             ->method('exists')
82             ->with('default')
83             ->will($this->throwException(new \InvalidArgumentException()));
84
85         // only default
86         $strategy = new HIncludeFragmentRenderer($engine);
87         $this->assertEquals('<hx:include src="/foo">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default'))->getContent());
88     }
89
90     public function testRenderWithEngineAndDefaultText()
91     {
92         $engine = $this->getMockBuilder('Symfony\\Component\\Templating\\EngineInterface')->getMock();
93         $engine->expects($this->once())
94             ->method('exists')
95             ->with('loading...')
96             ->will($this->throwException(new \RuntimeException()));
97
98         // only default
99         $strategy = new HIncludeFragmentRenderer($engine);
100         $this->assertEquals('<hx:include src="/foo">loading...</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'loading...'))->getContent());
101     }
102 }