Security update for Core, with self-updated composer
[yaffs-website] / vendor / symfony / http-kernel / Tests / Debug / FileLinkFormatterTest.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\Debug;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpFoundation\Request;
16 use Symfony\Component\HttpFoundation\RequestStack;
17 use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
18
19 class FileLinkFormatterTest extends TestCase
20 {
21     public function testWhenNoFileLinkFormatAndNoRequest()
22     {
23         $sut = new FileLinkFormatter();
24
25         $this->assertFalse($sut->format('/kernel/root/src/my/very/best/file.php', 3));
26     }
27
28     public function testWhenFileLinkFormatAndNoRequest()
29     {
30         $file = __DIR__.DIRECTORY_SEPARATOR.'file.php';
31
32         $sut = new FileLinkFormatter('debug://open?url=file://%f&line=%l', new RequestStack());
33
34         $this->assertSame("debug://open?url=file://$file&line=3", $sut->format($file, 3));
35     }
36
37     public function testWhenFileLinkFormatAndRequest()
38     {
39         $file = __DIR__.DIRECTORY_SEPARATOR.'file.php';
40         $baseDir = __DIR__;
41         $requestStack = new RequestStack();
42         $request = new Request();
43         $requestStack->push($request);
44
45         $sut = new FileLinkFormatter('debug://open?url=file://%f&line=%l', $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
46
47         $this->assertSame("debug://open?url=file://$file&line=3", $sut->format($file, 3));
48     }
49
50     public function testWhenNoFileLinkFormatAndRequest()
51     {
52         $file = __DIR__.DIRECTORY_SEPARATOR.'file.php';
53         $requestStack = new RequestStack();
54         $request = new Request();
55         $requestStack->push($request);
56
57         $request->server->set('SERVER_NAME', 'www.example.org');
58         $request->server->set('SERVER_PORT', 80);
59         $request->server->set('SCRIPT_NAME', '/app.php');
60         $request->server->set('SCRIPT_FILENAME', '/web/app.php');
61         $request->server->set('REQUEST_URI', '/app.php/example');
62
63         $sut = new FileLinkFormatter(null, $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
64
65         $this->assertSame('http://www.example.org/app.php/_profiler/open?file=file.php&line=3#line3', $sut->format($file, 3));
66     }
67 }