aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/HttpUtils/IndexUrlTest.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2015-09-06 21:31:37 +0200
committerVirtualTam <virtualtam@flibidi.net>2015-09-14 20:27:16 +0200
commit482d67bd523bf12f36508a0131d09fe299ee02f4 (patch)
treeb4e7c6ddaa1d88cc49bc96c2524f12431d8fcce0 /tests/HttpUtils/IndexUrlTest.php
parent7b114771d337af3bfd51d8fda1e8f2fd5b39535d (diff)
downloadShaarli-482d67bd523bf12f36508a0131d09fe299ee02f4.tar.gz
Shaarli-482d67bd523bf12f36508a0131d09fe299ee02f4.tar.zst
Shaarli-482d67bd523bf12f36508a0131d09fe299ee02f4.zip
HTTP: move server URL functions to `HttpUtils.php`
Relates to #333 Modifications: - refactor server URL utility functions - do not access global `$_SERVER` variables - add test coverage - improve readability - apply coding conventions Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'tests/HttpUtils/IndexUrlTest.php')
-rw-r--r--tests/HttpUtils/IndexUrlTest.php72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/HttpUtils/IndexUrlTest.php b/tests/HttpUtils/IndexUrlTest.php
new file mode 100644
index 00000000..337dcab0
--- /dev/null
+++ b/tests/HttpUtils/IndexUrlTest.php
@@ -0,0 +1,72 @@
1<?php
2/**
3 * HttpUtils' tests
4 */
5
6require_once 'application/HttpUtils.php';
7
8/**
9 * Unitary tests for index_url()
10 */
11class IndexUrlTest extends PHPUnit_Framework_TestCase
12{
13 /**
14 * If on the main page, remove "index.php" from the URL resource
15 */
16 public function testRemoveIndex()
17 {
18 $this->assertEquals(
19 'http://host.tld/',
20 index_url(
21 array(
22 'HTTPS' => 'Off',
23 'SERVER_NAME' => 'host.tld',
24 'SERVER_PORT' => '80',
25 'SCRIPT_NAME' => '/index.php'
26 )
27 )
28 );
29
30 $this->assertEquals(
31 'http://host.tld/admin/',
32 index_url(
33 array(
34 'HTTPS' => 'Off',
35 'SERVER_NAME' => 'host.tld',
36 'SERVER_PORT' => '80',
37 'SCRIPT_NAME' => '/admin/index.php'
38 )
39 )
40 );
41 }
42
43 /**
44 * The resource is != "index.php"
45 */
46 public function testOtherResource()
47 {
48 $this->assertEquals(
49 'http://host.tld/page.php',
50 page_url(
51 array(
52 'HTTPS' => 'Off',
53 'SERVER_NAME' => 'host.tld',
54 'SERVER_PORT' => '80',
55 'SCRIPT_NAME' => '/page.php'
56 )
57 )
58 );
59
60 $this->assertEquals(
61 'http://host.tld/admin/page.php',
62 page_url(
63 array(
64 'HTTPS' => 'Off',
65 'SERVER_NAME' => 'host.tld',
66 'SERVER_PORT' => '80',
67 'SCRIPT_NAME' => '/admin/page.php'
68 )
69 )
70 );
71 }
72}