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