]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - tests/HttpUtils/ServerUrlTest.php
Merge pull request #719 from ArthurHoaro/feed-opensearch
[github/shaarli/Shaarli.git] / tests / HttpUtils / ServerUrlTest.php
CommitLineData
482d67bd
V
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 );
85244fa0
A
70
71 $this->assertEquals(
72 'https://host.tld:4974',
73 server_url(
74 array(
75 'HTTPS' => 'Off',
76 'SERVER_NAME' => 'host.tld',
77 'SERVER_PORT' => '80',
78 'HTTP_X_FORWARDED_PROTO' => 'https, https',
79 'HTTP_X_FORWARDED_PORT' => '4974, 80'
80 )
81 )
82 );
482d67bd
V
83 }
84
85 /**
86 * Detect if the server uses a specific port (!= 80)
87 */
88 public function testPort()
89 {
90 // HTTP
91 $this->assertEquals(
92 'http://host.tld:8080',
93 server_url(
94 array(
95 'HTTPS' => 'OFF',
96 'SERVER_NAME' => 'host.tld',
97 'SERVER_PORT' => '8080'
98 )
99 )
100 );
101
102 // HTTPS
103 $this->assertEquals(
104 'https://host.tld:8080',
105 server_url(
106 array(
107 'HTTPS' => 'ON',
108 'SERVER_NAME' => 'host.tld',
109 'SERVER_PORT' => '8080'
110 )
111 )
112 );
113 }
114
115 /**
116 * HTTP server on port 80
117 */
118 public function testStandardHttpPort()
119 {
120 $this->assertEquals(
121 'http://host.tld',
122 server_url(
123 array(
124 'HTTPS' => 'OFF',
125 'SERVER_NAME' => 'host.tld',
126 'SERVER_PORT' => '80'
127 )
128 )
129 );
130 }
131
132 /**
133 * HTTPS server on port 443
134 */
135 public function testStandardHttpsPort()
136 {
137 $this->assertEquals(
138 'https://host.tld',
139 server_url(
140 array(
141 'HTTPS' => 'ON',
142 'SERVER_NAME' => 'host.tld',
143 'SERVER_PORT' => '443'
144 )
145 )
146 );
147 }
148}