aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/HttpUtils/ServerUrlTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/HttpUtils/ServerUrlTest.php')
-rw-r--r--tests/HttpUtils/ServerUrlTest.php135
1 files changed, 135 insertions, 0 deletions
diff --git a/tests/HttpUtils/ServerUrlTest.php b/tests/HttpUtils/ServerUrlTest.php
new file mode 100644
index 00000000..5096db65
--- /dev/null
+++ b/tests/HttpUtils/ServerUrlTest.php
@@ -0,0 +1,135 @@
1<?php
2/**
3 * HttpUtils' tests
4 */
5
6require_once 'application/HttpUtils.php';
7
8/**
9 * Unitary tests for server_url()
10 */
11class 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 );
70 }
71
72 /**
73 * Detect if the server uses a specific port (!= 80)
74 */
75 public function testPort()
76 {
77 // HTTP
78 $this->assertEquals(
79 'http://host.tld:8080',
80 server_url(
81 array(
82 'HTTPS' => 'OFF',
83 'SERVER_NAME' => 'host.tld',
84 'SERVER_PORT' => '8080'
85 )
86 )
87 );
88
89 // HTTPS
90 $this->assertEquals(
91 'https://host.tld:8080',
92 server_url(
93 array(
94 'HTTPS' => 'ON',
95 'SERVER_NAME' => 'host.tld',
96 'SERVER_PORT' => '8080'
97 )
98 )
99 );
100 }
101
102 /**
103 * HTTP server on port 80
104 */
105 public function testStandardHttpPort()
106 {
107 $this->assertEquals(
108 'http://host.tld',
109 server_url(
110 array(
111 'HTTPS' => 'OFF',
112 'SERVER_NAME' => 'host.tld',
113 'SERVER_PORT' => '80'
114 )
115 )
116 );
117 }
118
119 /**
120 * HTTPS server on port 443
121 */
122 public function testStandardHttpsPort()
123 {
124 $this->assertEquals(
125 'https://host.tld',
126 server_url(
127 array(
128 'HTTPS' => 'ON',
129 'SERVER_NAME' => 'host.tld',
130 'SERVER_PORT' => '443'
131 )
132 )
133 );
134 }
135}