1 | <?php |
||
11 | class TwigFormatterTest extends TestCase |
||
12 | { |
||
13 | /** |
||
14 | * @var TwigFormatter |
||
15 | */ |
||
16 | private $formatter; |
||
17 | |||
18 | protected function setUp() |
||
19 | { |
||
20 | $loader = new TwigLoaderFilesystem(__DIR__.'/Asset/templates'); |
||
21 | |||
22 | $this->formatter = new TwigFormatter( |
||
23 | new TwigEnvironment($loader) |
||
24 | ); |
||
25 | } |
||
26 | |||
27 | public function testAccepts() |
||
28 | { |
||
29 | $this->assertEquals(['text/html'], TwigFormatter::accepts()); |
||
30 | } |
||
31 | |||
32 | public function testType() |
||
33 | { |
||
34 | $this->assertEquals('text/html', $this->formatter->type()); |
||
35 | } |
||
36 | |||
37 | public function testResponse() |
||
38 | { |
||
39 | $template = 'test.html.twig'; |
||
40 | $output = [ |
||
41 | 'header' => 'header', |
||
42 | 'body' => 'body', |
||
43 | 'footer' => 'footer' |
||
44 | ]; |
||
45 | |||
46 | $payload = $this->createMock(PayloadInterface::class); |
||
47 | $payload->expects($this->any())->method('getOutput')->willReturn($output); |
||
48 | $payload->expects($this->any())->method('getSetting')->willReturn($template); |
||
49 | |||
50 | $body = $this->formatter->body($payload); |
||
51 | |||
52 | $this->assertEquals("<h1>header</h1>\n<p>body</p>\n<span>footer</span>\n", $body); |
||
53 | } |
||
54 | } |
||
55 |