]>
Commit | Line | Data |
---|---|---|
482d67bd V |
1 | <?php |
2 | /** | |
3 | * HttpUtils' tests | |
4 | */ | |
5 | ||
6 | require_once 'application/HttpUtils.php'; | |
7 | ||
8 | /** | |
9 | * Unitary tests for server_url() | |
10 | */ | |
11 | class ServerUrlTest extends PHPUnit_Framework_TestCase | |
12 | { | |
13 | /** | |
14 | * Detect if the server uses SSL | |
15 | */ | |
16 | public function testHttpsScheme() | |
17 | { | |
18 | $this->assertEquals( | |
19 | 'https://host.tld', | |
20 | server_url( | |
21 | array( | |
22 | 'HTTPS' => 'ON', | |
23 | 'SERVER_NAME' => 'host.tld', | |
24 | 'SERVER_PORT' => '443' | |
25 | ) | |
26 | ) | |
27 | ); | |
28 | ||
29 | $this->assertEquals( | |
30 | 'https://host.tld:8080', | |
31 | server_url( | |
32 | array( | |
33 | 'HTTPS' => 'ON', | |
34 | 'SERVER_NAME' => 'host.tld', | |
35 | 'SERVER_PORT' => '8080' | |
36 | ) | |
37 | ) | |
38 | ); | |
39 | } | |
40 | ||
41 | /** | |
42 | * Detect a Proxy with SSL enabled | |
43 | */ | |
44 | public function testHttpsProxyForward() | |
45 | { | |
46 | $this->assertEquals( | |
47 | 'https://host.tld:8080', | |
48 | server_url( | |
49 | array( | |
50 | 'HTTPS' => 'Off', | |
51 | 'SERVER_NAME' => 'host.tld', | |
52 | 'SERVER_PORT' => '80', | |
53 | 'HTTP_X_FORWARDED_PROTO' => 'https', | |
54 | 'HTTP_X_FORWARDED_PORT' => '8080' | |
55 | ) | |
56 | ) | |
57 | ); | |
58 | ||
59 | $this->assertEquals( | |
60 | 'https://host.tld', | |
61 | server_url( | |
62 | array( | |
63 | 'HTTPS' => 'Off', | |
64 | 'SERVER_NAME' => 'host.tld', | |
65 | 'SERVER_PORT' => '80', | |
66 | 'HTTP_X_FORWARDED_PROTO' => 'https' | |
67 | ) | |
68 | ) | |
69 | ); | |
85244fa0 | 70 | |
8e4be773 A |
71 | $this->assertEquals( |
72 | 'https://host.tld', | |
73 | server_url( | |
74 | array( | |
75 | 'HTTPS' => 'Off', | |
76 | 'SERVER_NAME' => 'host.tld', | |
77 | 'SERVER_PORT' => '80', | |
78 | 'HTTP_X_FORWARDED_PROTO' => 'https', | |
79 | 'HTTP_X_FORWARDED_PORT' => '443' | |
80 | ) | |
81 | ) | |
82 | ); | |
83 | ||
85244fa0 A |
84 | $this->assertEquals( |
85 | 'https://host.tld:4974', | |
86 | server_url( | |
87 | array( | |
88 | 'HTTPS' => 'Off', | |
89 | 'SERVER_NAME' => 'host.tld', | |
90 | 'SERVER_PORT' => '80', | |
91 | 'HTTP_X_FORWARDED_PROTO' => 'https, https', | |
92 | 'HTTP_X_FORWARDED_PORT' => '4974, 80' | |
93 | ) | |
94 | ) | |
95 | ); | |
482d67bd V |
96 | } |
97 | ||
98 | /** | |
99 | * Detect if the server uses a specific port (!= 80) | |
100 | */ | |
101 | public function testPort() | |
102 | { | |
103 | // HTTP | |
104 | $this->assertEquals( | |
105 | 'http://host.tld:8080', | |
106 | server_url( | |
107 | array( | |
108 | 'HTTPS' => 'OFF', | |
109 | 'SERVER_NAME' => 'host.tld', | |
110 | 'SERVER_PORT' => '8080' | |
111 | ) | |
112 | ) | |
113 | ); | |
114 | ||
115 | // HTTPS | |
116 | $this->assertEquals( | |
117 | 'https://host.tld:8080', | |
118 | server_url( | |
119 | array( | |
120 | 'HTTPS' => 'ON', | |
121 | 'SERVER_NAME' => 'host.tld', | |
122 | 'SERVER_PORT' => '8080' | |
123 | ) | |
124 | ) | |
125 | ); | |
126 | } | |
127 | ||
128 | /** | |
129 | * HTTP server on port 80 | |
130 | */ | |
131 | public function testStandardHttpPort() | |
132 | { | |
133 | $this->assertEquals( | |
134 | 'http://host.tld', | |
135 | server_url( | |
136 | array( | |
137 | 'HTTPS' => 'OFF', | |
138 | 'SERVER_NAME' => 'host.tld', | |
139 | 'SERVER_PORT' => '80' | |
140 | ) | |
141 | ) | |
142 | ); | |
143 | } | |
144 | ||
145 | /** | |
146 | * HTTPS server on port 443 | |
147 | */ | |
148 | public function testStandardHttpsPort() | |
149 | { | |
150 | $this->assertEquals( | |
151 | 'https://host.tld', | |
152 | server_url( | |
153 | array( | |
154 | 'HTTPS' => 'ON', | |
155 | 'SERVER_NAME' => 'host.tld', | |
156 | 'SERVER_PORT' => '443' | |
157 | ) | |
158 | ) | |
159 | ); | |
160 | } | |
161 | } |