diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-09-03 14:51:41 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-09-12 21:39:01 +0200 |
commit | 650a5f09cbeb1c1bef19810c6cc504c06d5b7e87 (patch) | |
tree | 6be70f1658128246e57d39c73e1bc3b13e992de1 /tests | |
parent | e809908f9e593b2cec11f72849caa1dae6394451 (diff) | |
download | Shaarli-650a5f09cbeb1c1bef19810c6cc504c06d5b7e87.tar.gz Shaarli-650a5f09cbeb1c1bef19810c6cc504c06d5b7e87.tar.zst Shaarli-650a5f09cbeb1c1bef19810c6cc504c06d5b7e87.zip |
Add manual configuration for root URL
This new setting under 'general.root_url' allows to override automatic discovery of Shaarli instance's URL.
Fixes #1339
Diffstat (limited to 'tests')
-rw-r--r-- | tests/http/HttpUtils/IndexUrlTest.php | 36 | ||||
-rw-r--r-- | tests/http/HttpUtils/IndexUrlTestWithConstant.php | 51 |
2 files changed, 86 insertions, 1 deletions
diff --git a/tests/http/HttpUtils/IndexUrlTest.php b/tests/http/HttpUtils/IndexUrlTest.php index 73d33cd4..cce45c51 100644 --- a/tests/http/HttpUtils/IndexUrlTest.php +++ b/tests/http/HttpUtils/IndexUrlTest.php | |||
@@ -5,12 +5,14 @@ | |||
5 | 5 | ||
6 | namespace Shaarli\Http; | 6 | namespace Shaarli\Http; |
7 | 7 | ||
8 | use PHPUnit\Framework\TestCase; | ||
9 | |||
8 | require_once 'application/http/HttpUtils.php'; | 10 | require_once 'application/http/HttpUtils.php'; |
9 | 11 | ||
10 | /** | 12 | /** |
11 | * Unitary tests for index_url() | 13 | * Unitary tests for index_url() |
12 | */ | 14 | */ |
13 | class IndexUrlTest extends \PHPUnit\Framework\TestCase | 15 | class IndexUrlTest extends TestCase |
14 | { | 16 | { |
15 | /** | 17 | /** |
16 | * If on the main page, remove "index.php" from the URL resource | 18 | * If on the main page, remove "index.php" from the URL resource |
@@ -103,4 +105,36 @@ class IndexUrlTest extends \PHPUnit\Framework\TestCase | |||
103 | ) | 105 | ) |
104 | ); | 106 | ); |
105 | } | 107 | } |
108 | |||
109 | /** | ||
110 | * The route is stored in REQUEST_URI and subfolder | ||
111 | */ | ||
112 | public function testPageUrlWithRouteUnderSubfolder() | ||
113 | { | ||
114 | $this->assertEquals( | ||
115 | 'http://host.tld/subfolder/picture-wall', | ||
116 | page_url( | ||
117 | array( | ||
118 | 'HTTPS' => 'Off', | ||
119 | 'SERVER_NAME' => 'host.tld', | ||
120 | 'SERVER_PORT' => '80', | ||
121 | 'SCRIPT_NAME' => '/subfolder/index.php', | ||
122 | 'REQUEST_URI' => '/subfolder/picture-wall', | ||
123 | ) | ||
124 | ) | ||
125 | ); | ||
126 | |||
127 | $this->assertEquals( | ||
128 | 'http://host.tld/subfolder/admin/picture-wall', | ||
129 | page_url( | ||
130 | array( | ||
131 | 'HTTPS' => 'Off', | ||
132 | 'SERVER_NAME' => 'host.tld', | ||
133 | 'SERVER_PORT' => '80', | ||
134 | 'SCRIPT_NAME' => '/subfolder/admin/index.php', | ||
135 | 'REQUEST_URI' => '/subfolder/admin/picture-wall', | ||
136 | ) | ||
137 | ) | ||
138 | ); | ||
139 | } | ||
106 | } | 140 | } |
diff --git a/tests/http/HttpUtils/IndexUrlTestWithConstant.php b/tests/http/HttpUtils/IndexUrlTestWithConstant.php new file mode 100644 index 00000000..15ca3d72 --- /dev/null +++ b/tests/http/HttpUtils/IndexUrlTestWithConstant.php | |||
@@ -0,0 +1,51 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\Http; | ||
6 | |||
7 | use PHPUnit\Framework\TestCase; | ||
8 | |||
9 | /** | ||
10 | * Test index_url with SHAARLI_ROOT_URL defined to override automatic retrieval. | ||
11 | * This should stay in its dedicated class to make sure to not alter other tests of the suite. | ||
12 | */ | ||
13 | class IndexUrlTestWithConstant extends TestCase | ||
14 | { | ||
15 | public static function setUpBeforeClass(): void | ||
16 | { | ||
17 | define('SHAARLI_ROOT_URL', 'http://other-host.tld/subfolder/'); | ||
18 | } | ||
19 | |||
20 | /** | ||
21 | * The route is stored in REQUEST_URI and subfolder | ||
22 | */ | ||
23 | public function testIndexUrlWithConstantDefined() | ||
24 | { | ||
25 | $this->assertEquals( | ||
26 | 'http://other-host.tld/subfolder/', | ||
27 | index_url( | ||
28 | array( | ||
29 | 'HTTPS' => 'Off', | ||
30 | 'SERVER_NAME' => 'host.tld', | ||
31 | 'SERVER_PORT' => '80', | ||
32 | 'SCRIPT_NAME' => '/index.php', | ||
33 | 'REQUEST_URI' => '/picture-wall', | ||
34 | ) | ||
35 | ) | ||
36 | ); | ||
37 | |||
38 | $this->assertEquals( | ||
39 | 'http://other-host.tld/subfolder/', | ||
40 | index_url( | ||
41 | array( | ||
42 | 'HTTPS' => 'Off', | ||
43 | 'SERVER_NAME' => 'host.tld', | ||
44 | 'SERVER_PORT' => '80', | ||
45 | 'SCRIPT_NAME' => '/admin/index.php', | ||
46 | 'REQUEST_URI' => '/admin/picture-wall', | ||
47 | ) | ||
48 | ) | ||
49 | ); | ||
50 | } | ||
51 | } | ||