]> git.mxchange.org Git - friendica.git/blob - tests/src/Util/BasePathTest.php
Merge pull request #10294 from annando/http-input-data
[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                         'no_overwrite_if_invalid' => [
45                                 'server' => [
46                                         'DOCUMENT_ROOT' => '/nopopop',
47                                         'PWD' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
48                                 ],
49                                 'input' => '/noatgawe22fafa',
50                                 'output' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
51                         ]
52                 ];
53         }
54
55         /**
56          * Test the basepath determination
57          * @dataProvider dataPaths
58          */
59         public function testDetermineBasePath(array $server, $input, $output)
60         {
61                 $basepath = new BasePath($input, $server);
62                 self::assertEquals($output, $basepath->getPath());
63         }
64
65         /**
66          * Test the basepath determination with a complete wrong path
67          */
68         public function testFailedBasePath()
69         {
70                 $this->expectException(\Exception::class);
71                 $this->expectExceptionMessageMatches("/(.*) is not a valid basepath/");
72                 
73                 $basepath = new BasePath('/now23452sgfgas', []);
74                 $basepath->getPath();
75         }
76 }