]> git.mxchange.org Git - friendica.git/blob - tests/src/Util/BasePathTest.php
Merge pull request #11334 from annando/guid-style
[friendica.git] / tests / src / Util / BasePathTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Test\src\Util;
23
24 use Friendica\Test\MockedTest;
25 use Friendica\Util\BasePath;
26
27 class BasePathTest extends MockedTest
28 {
29         public function dataPaths()
30         {
31                 return [
32                         'fullPath' => [
33                                 'server' => [],
34                                 'input' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
35                                 'output' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
36                         ],
37                         'relative' => [
38                                 'server' => [],
39                                 'input' => 'config',
40                                 'output' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
41                         ],
42                         'document_root' => [
43                                 'server' => [
44                                         'DOCUMENT_ROOT' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
45                                 ],
46                                 'input' => '/noooop',
47                                 'output' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
48                         ],
49                         'pwd' => [
50                                 'server' => [
51                                         'PWD' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
52                                 ],
53                                 'input' => '/noooop',
54                                 'output' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
55                         ],
56                         'no_overwrite' => [
57                                 'server' => [
58                                         'DOCUMENT_ROOT' => dirname(__DIR__, 3),
59                                         'PWD' => dirname(__DIR__, 3),
60                                 ],
61                                 'input' => 'config',
62                                 'output' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
63                         ],
64                         'no_overwrite_if_invalid' => [
65                                 'server' => [
66                                         'DOCUMENT_ROOT' => '/nopopop',
67                                         'PWD' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
68                                 ],
69                                 'input' => '/noatgawe22fafa',
70                                 'output' => dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'config',
71                         ]
72                 ];
73         }
74
75         /**
76          * Test the basepath determination
77          * @dataProvider dataPaths
78          */
79         public function testDetermineBasePath(array $server, $input, $output)
80         {
81                 $basepath = new BasePath($input, $server);
82                 self::assertEquals($output, $basepath->getPath());
83         }
84
85         /**
86          * Test the basepath determination with a complete wrong path
87          */
88         public function testFailedBasePath()
89         {
90                 $this->expectException(\Exception::class);
91                 $this->expectExceptionMessageMatches("/(.*) is not a valid basepath/");
92                 
93                 $basepath = new BasePath('/now23452sgfgas', []);
94                 $basepath->getPath();
95         }
96 }