]> git.mxchange.org Git - friendica.git/blob - tests/src/Util/BasePathTest.php
Basepath Hardening
[friendica.git] / tests / src / Util / BasePathTest.php
1 <?php
2 namespace Friendica\Test\src\Util;
3
4 use Friendica\Test\MockedTest;
5 use Friendica\Util\BasePath;
6
7 class BasePathTest extends MockedTest
8 {
9         public function dataPaths()
10         {
11                 return [
12                         'fullPath' => [
13                                 'server' => [],
14                                 'input' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
15                                 'output' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
16                         ],
17                         'relative' => [
18                                 'server' => [],
19                                 'input' => 'config',
20                                 'output' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
21                         ],
22                         'document_root' => [
23                                 'server' => [
24                                         'DOCUMENT_ROOT' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
25                                 ],
26                                 'input' => '/noooop',
27                                 'output' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
28                         ],
29                         'pwd' => [
30                                 'server' => [
31                                         'PWD' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
32                                 ],
33                                 'input' => '/noooop',
34                                 'output' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
35                         ],
36                         'no_overwrite' => [
37                                 'server' => [
38                                         'DOCUMENT_ROOT' => dirname(__DIR__, 3),
39                                         'PWD' => dirname(__DIR__, 3),
40                                 ],
41                                 'input' => 'config',
42                                 'output' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
43                         ]
44                 ];
45         }
46
47         /**
48          * Test the basepath determination
49          * @dataProvider dataPaths
50          */
51         public function testDetermineBasePath(array $server, $input, $output)
52         {
53                 $this->assertEquals($output, BasePath::create($input, $server));
54         }
55
56         /**
57          * Test the basepath determination with a complete wrong path
58          * @expectedException \Exception
59          * @expectedExceptionMessageRegExp /(.*) is not a valid basepath/
60          */
61         public function testFailedBasePath()
62         {
63                 BasePath::create('/now23452sgfgas', []);
64         }
65 }