]>
Commit | Line | Data |
---|---|---|
482d67bd V |
1 | <?php |
2 | /** | |
3 | * HttpUtils' tests | |
4 | */ | |
5 | ||
51753e40 V |
6 | namespace Shaarli\Http; |
7 | ||
650a5f09 A |
8 | use PHPUnit\Framework\TestCase; |
9 | ||
51753e40 | 10 | require_once 'application/http/HttpUtils.php'; |
482d67bd V |
11 | |
12 | /** | |
13 | * Unitary tests for index_url() | |
14 | */ | |
650a5f09 | 15 | class IndexUrlTest extends TestCase |
482d67bd V |
16 | { |
17 | /** | |
18 | * If on the main page, remove "index.php" from the URL resource | |
19 | */ | |
20 | public function testRemoveIndex() | |
21 | { | |
22 | $this->assertEquals( | |
23 | 'http://host.tld/', | |
24 | index_url( | |
25 | array( | |
26 | 'HTTPS' => 'Off', | |
27 | 'SERVER_NAME' => 'host.tld', | |
28 | 'SERVER_PORT' => '80', | |
29 | 'SCRIPT_NAME' => '/index.php' | |
30 | ) | |
31 | ) | |
32 | ); | |
33 | ||
34 | $this->assertEquals( | |
35 | 'http://host.tld/admin/', | |
36 | index_url( | |
37 | array( | |
38 | 'HTTPS' => 'Off', | |
39 | 'SERVER_NAME' => 'host.tld', | |
40 | 'SERVER_PORT' => '80', | |
41 | 'SCRIPT_NAME' => '/admin/index.php' | |
42 | ) | |
43 | ) | |
44 | ); | |
45 | } | |
46 | ||
47 | /** | |
48 | * The resource is != "index.php" | |
49 | */ | |
50 | public function testOtherResource() | |
51 | { | |
52 | $this->assertEquals( | |
53 | 'http://host.tld/page.php', | |
54 | page_url( | |
55 | array( | |
56 | 'HTTPS' => 'Off', | |
57 | 'SERVER_NAME' => 'host.tld', | |
58 | 'SERVER_PORT' => '80', | |
59 | 'SCRIPT_NAME' => '/page.php' | |
60 | ) | |
61 | ) | |
62 | ); | |
63 | ||
64 | $this->assertEquals( | |
65 | 'http://host.tld/admin/page.php', | |
66 | page_url( | |
67 | array( | |
68 | 'HTTPS' => 'Off', | |
69 | 'SERVER_NAME' => 'host.tld', | |
70 | 'SERVER_PORT' => '80', | |
71 | 'SCRIPT_NAME' => '/admin/page.php' | |
72 | ) | |
73 | ) | |
74 | ); | |
75 | } | |
c4d5be53 A |
76 | |
77 | /** | |
78 | * The route is stored in REQUEST_URI | |
79 | */ | |
80 | public function testPageUrlWithRoute() | |
81 | { | |
82 | $this->assertEquals( | |
83 | 'http://host.tld/picture-wall', | |
84 | page_url( | |
85 | array( | |
86 | 'HTTPS' => 'Off', | |
87 | 'SERVER_NAME' => 'host.tld', | |
88 | 'SERVER_PORT' => '80', | |
89 | 'SCRIPT_NAME' => '/index.php', | |
90 | 'REQUEST_URI' => '/picture-wall', | |
91 | ) | |
92 | ) | |
93 | ); | |
94 | ||
95 | $this->assertEquals( | |
96 | 'http://host.tld/admin/picture-wall', | |
97 | page_url( | |
98 | array( | |
99 | 'HTTPS' => 'Off', | |
100 | 'SERVER_NAME' => 'host.tld', | |
101 | 'SERVER_PORT' => '80', | |
102 | 'SCRIPT_NAME' => '/admin/index.php', | |
103 | 'REQUEST_URI' => '/admin/picture-wall', | |
104 | ) | |
105 | ) | |
106 | ); | |
107 | } | |
650a5f09 A |
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 | } | |
482d67bd | 140 | } |