Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / http-kernel / Tests / DataCollector / DumpDataCollectorTest.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\DataCollector;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
16 use Symfony\Component\HttpFoundation\Request;
17 use Symfony\Component\HttpFoundation\Response;
18 use Symfony\Component\VarDumper\Cloner\Data;
19
20 /**
21  * @author Nicolas Grekas <p@tchwork.com>
22  */
23 class DumpDataCollectorTest extends TestCase
24 {
25     public function testDump()
26     {
27         $data = new Data(array(array(123)));
28
29         $collector = new DumpDataCollector();
30
31         $this->assertSame('dump', $collector->getName());
32
33         $collector->dump($data);
34         $line = __LINE__ - 1;
35         $this->assertSame(1, $collector->getDumpsCount());
36
37         $dump = $collector->getDumps('html');
38         $this->assertTrue(isset($dump[0]['data']));
39         $dump[0]['data'] = preg_replace('/^.*?<pre/', '<pre', $dump[0]['data']);
40         $dump[0]['data'] = preg_replace('/sf-dump-\d+/', 'sf-dump', $dump[0]['data']);
41
42         $xDump = array(
43             array(
44                 'data' => "<pre class=sf-dump id=sf-dump data-indent-pad=\"  \"><span class=sf-dump-num>123</span>\n</pre><script>Sfdump(\"sf-dump\")</script>\n",
45                 'name' => 'DumpDataCollectorTest.php',
46                 'file' => __FILE__,
47                 'line' => $line,
48                 'fileExcerpt' => false,
49             ),
50         );
51         $this->assertEquals($xDump, $dump);
52
53         $this->assertStringMatchesFormat('a:3:{i:0;a:5:{s:4:"data";%c:39:"Symfony\Component\VarDumper\Cloner\Data":%a', $collector->serialize());
54         $this->assertSame(0, $collector->getDumpsCount());
55         $this->assertSame('a:2:{i:0;b:0;i:1;s:5:"UTF-8";}', $collector->serialize());
56     }
57
58     public function testCollectDefault()
59     {
60         $data = new Data(array(array(123)));
61
62         $collector = new DumpDataCollector();
63
64         $collector->dump($data);
65         $line = __LINE__ - 1;
66
67         ob_start();
68         $collector->collect(new Request(), new Response());
69         $output = ob_get_clean();
70
71         $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output);
72         $this->assertSame(1, $collector->getDumpsCount());
73         $collector->serialize();
74     }
75
76     public function testCollectHtml()
77     {
78         $data = new Data(array(array(123)));
79
80         $collector = new DumpDataCollector(null, 'test://%f:%l');
81
82         $collector->dump($data);
83         $line = __LINE__ - 1;
84         $file = __FILE__;
85         $xOutput = <<<EOTXT
86 <pre class=sf-dump id=sf-dump data-indent-pad="  "><a href="test://{$file}:{$line}" title="{$file}"><span class=sf-dump-meta>DumpDataCollectorTest.php</span></a> on line <span class=sf-dump-meta>{$line}</span>:
87 <span class=sf-dump-num>123</span>
88 </pre>
89 EOTXT;
90
91         ob_start();
92         $response = new Response();
93         $response->headers->set('Content-Type', 'text/html');
94         $collector->collect(new Request(), $response);
95         $output = ob_get_clean();
96         $output = preg_replace('#<(script|style).*?</\1>#s', '', $output);
97         $output = preg_replace('/sf-dump-\d+/', 'sf-dump', $output);
98
99         $this->assertSame($xOutput, trim($output));
100         $this->assertSame(1, $collector->getDumpsCount());
101         $collector->serialize();
102     }
103
104     public function testFlush()
105     {
106         $data = new Data(array(array(456)));
107         $collector = new DumpDataCollector();
108         $collector->dump($data);
109         $line = __LINE__ - 1;
110
111         ob_start();
112         $collector->__destruct();
113         $this->assertSame("DumpDataCollectorTest.php on line {$line}:\n456\n", ob_get_clean());
114     }
115 }