aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Url
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Url')
-rw-r--r--tests/Url/CleanupUrlTest.php109
-rw-r--r--tests/Url/GetUrlSchemeTest.php30
-rw-r--r--tests/Url/UnparseUrlTest.php30
-rw-r--r--tests/Url/WhitelistProtocolsTest.php63
4 files changed, 0 insertions, 232 deletions
diff --git a/tests/Url/CleanupUrlTest.php b/tests/Url/CleanupUrlTest.php
deleted file mode 100644
index 24791948..00000000
--- a/tests/Url/CleanupUrlTest.php
+++ /dev/null
@@ -1,109 +0,0 @@
1<?php
2/**
3 * Unitary tests for cleanup_url()
4 */
5
6require_once 'application/Url.php';
7
8class CleanupUrlTest extends PHPUnit_Framework_TestCase
9{
10 /**
11 * @var string reference URL
12 */
13 protected $ref = 'http://domain.tld:3000';
14
15
16 /**
17 * Clean empty URL
18 */
19 public function testCleanupUrlEmpty()
20 {
21 $this->assertEquals('', cleanup_url(''));
22 }
23
24 /**
25 * Clean an already cleaned URL
26 */
27 public function testCleanupUrlAlreadyClean()
28 {
29 $this->assertEquals($this->ref, cleanup_url($this->ref));
30 $this->ref2 = $this->ref.'/path/to/dir/';
31 $this->assertEquals($this->ref2, cleanup_url($this->ref2));
32 }
33
34 /**
35 * Clean URL fragments
36 */
37 public function testCleanupUrlFragment()
38 {
39 $this->assertEquals($this->ref, cleanup_url($this->ref.'#tk.rss_all'));
40 $this->assertEquals($this->ref, cleanup_url($this->ref.'#xtor=RSS-'));
41 $this->assertEquals($this->ref, cleanup_url($this->ref.'#xtor=RSS-U3ht0tkc4b'));
42 }
43
44 /**
45 * Clean URL query - single annoying parameter
46 */
47 public function testCleanupUrlQuerySingle()
48 {
49 $this->assertEquals($this->ref, cleanup_url($this->ref.'?action_object_map=junk'));
50 $this->assertEquals($this->ref, cleanup_url($this->ref.'?action_ref_map=Cr4p!'));
51 $this->assertEquals($this->ref, cleanup_url($this->ref.'?action_type_map=g4R84g3'));
52
53 $this->assertEquals($this->ref, cleanup_url($this->ref.'?fb_stuff=v41u3'));
54 $this->assertEquals($this->ref, cleanup_url($this->ref.'?fb=71m3w4573'));
55
56 $this->assertEquals($this->ref, cleanup_url($this->ref.'?utm_campaign=zomg'));
57 $this->assertEquals($this->ref, cleanup_url($this->ref.'?utm_medium=numnum'));
58 $this->assertEquals($this->ref, cleanup_url($this->ref.'?utm_source=c0d3'));
59 $this->assertEquals($this->ref, cleanup_url($this->ref.'?utm_term=1n4l'));
60
61 $this->assertEquals($this->ref, cleanup_url($this->ref.'?xtor=some-url'));
62
63 $this->assertEquals($this->ref, cleanup_url($this->ref.'?campaign_name=junk'));
64 $this->assertEquals($this->ref, cleanup_url($this->ref.'?campaign_start=junk'));
65 $this->assertEquals($this->ref, cleanup_url($this->ref.'?campaign_item_index=junk'));
66 }
67
68 /**
69 * Clean URL query - multiple annoying parameters
70 */
71 public function testCleanupUrlQueryMultiple()
72 {
73 $this->assertEquals($this->ref, cleanup_url($this->ref.'?xtor=some-url&fb=som3th1ng'));
74
75 $this->assertEquals($this->ref, cleanup_url(
76 $this->ref.'?fb=stuff&utm_campaign=zomg&utm_medium=numnum&utm_source=c0d3'
77 ));
78
79 $this->assertEquals($this->ref, cleanup_url(
80 $this->ref.'?campaign_start=zomg&campaign_name=numnum'
81 ));
82 }
83
84 /**
85 * Clean URL query - multiple annoying parameters and fragment
86 */
87 public function testCleanupUrlQueryFragment()
88 {
89 $this->assertEquals($this->ref, cleanup_url(
90 $this->ref.'?xtor=some-url&fb=som3th1ng#tk.rss_all'
91 ));
92
93 // ditch annoying query params and fragment, keep useful params
94 $this->assertEquals(
95 $this->ref.'?my=stuff&is=kept',
96 cleanup_url(
97 $this->ref.'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#tk.rss_all'
98 )
99 );
100
101 // ditch annoying query params, keep useful params and fragment
102 $this->assertEquals(
103 $this->ref.'?my=stuff&is=kept#again',
104 cleanup_url(
105 $this->ref.'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#again'
106 )
107 );
108 }
109}
diff --git a/tests/Url/GetUrlSchemeTest.php b/tests/Url/GetUrlSchemeTest.php
deleted file mode 100644
index 18b932d6..00000000
--- a/tests/Url/GetUrlSchemeTest.php
+++ /dev/null
@@ -1,30 +0,0 @@
1<?php
2/**
3 * Unitary tests for get_url_scheme()
4 */
5
6require_once 'application/Url.php';
7
8class GetUrlSchemeTest extends PHPUnit_Framework_TestCase
9{
10 /**
11 * Get empty scheme string for empty Url
12 */
13 public function testGetUrlSchemeEmpty()
14 {
15 $this->assertEquals('', get_url_scheme(''));
16 }
17
18 /**
19 * Get normal scheme of Url
20 */
21 public function testGetUrlScheme()
22 {
23 $this->assertEquals('http', get_url_scheme('http://domain.tld:3000'));
24 $this->assertEquals('https', get_url_scheme('https://domain.tld:3000'));
25 $this->assertEquals('http', get_url_scheme('domain.tld'));
26 $this->assertEquals('ssh', get_url_scheme('ssh://domain.tld'));
27 $this->assertEquals('ftp', get_url_scheme('ftp://domain.tld'));
28 $this->assertEquals('git', get_url_scheme('git://domain.tld/push?pull=clone#checkout'));
29 }
30}
diff --git a/tests/Url/UnparseUrlTest.php b/tests/Url/UnparseUrlTest.php
deleted file mode 100644
index e314b484..00000000
--- a/tests/Url/UnparseUrlTest.php
+++ /dev/null
@@ -1,30 +0,0 @@
1<?php
2/**
3 * Unpares Url's tests
4 */
5
6require_once 'application/Url.php';
7
8/**
9 * Unitary tests for unparse_url()
10 */
11class UnparseUrlTest extends PHPUnit_Framework_TestCase
12{
13 /**
14 * Thanks for building nothing
15 */
16 public function testUnparseEmptyArray()
17 {
18 $this->assertEquals('', unparse_url(array()));
19 }
20
21 /**
22 * Rebuild a full-featured URL
23 */
24 public function testUnparseFull()
25 {
26 $ref = 'http://username:password@hostname:9090/path'
27 .'?arg1=value1&arg2=value2#anchor';
28 $this->assertEquals($ref, unparse_url(parse_url($ref)));
29 }
30}
diff --git a/tests/Url/WhitelistProtocolsTest.php b/tests/Url/WhitelistProtocolsTest.php
deleted file mode 100644
index a3156804..00000000
--- a/tests/Url/WhitelistProtocolsTest.php
+++ /dev/null
@@ -1,63 +0,0 @@
1<?php
2
3require_once 'application/Url.php';
4
5use Shaarli\Config\ConfigManager;
6
7/**
8 * Class WhitelistProtocolsTest
9 *
10 * Test whitelist_protocols() function of Url.
11 */
12class WhitelistProtocolsTest extends PHPUnit_Framework_TestCase
13{
14 /**
15 * Test whitelist_protocols() on a note (relative URL).
16 */
17 public function testWhitelistProtocolsRelative()
18 {
19 $whitelist = ['ftp', 'magnet'];
20 $url = '?12443564';
21 $this->assertEquals($url, whitelist_protocols($url, $whitelist));
22 $url = '/path.jpg';
23 $this->assertEquals($url, whitelist_protocols($url, $whitelist));
24 }
25
26 /**
27 * Test whitelist_protocols() on a note (relative URL).
28 */
29 public function testWhitelistProtocolMissing()
30 {
31 $whitelist = ['ftp', 'magnet'];
32 $url = 'test.tld/path/?query=value#hash';
33 $this->assertEquals('http://'. $url, whitelist_protocols($url, $whitelist));
34 }
35
36 /**
37 * Test whitelist_protocols() with allowed protocols.
38 */
39 public function testWhitelistAllowedProtocol()
40 {
41 $whitelist = ['ftp', 'magnet'];
42 $url = 'http://test.tld/path/?query=value#hash';
43 $this->assertEquals($url, whitelist_protocols($url, $whitelist));
44 $url = 'https://test.tld/path/?query=value#hash';
45 $this->assertEquals($url, whitelist_protocols($url, $whitelist));
46 $url = 'ftp://test.tld/path/?query=value#hash';
47 $this->assertEquals($url, whitelist_protocols($url, $whitelist));
48 $url = 'magnet:test.tld/path/?query=value#hash';
49 $this->assertEquals($url, whitelist_protocols($url, $whitelist));
50 }
51
52 /**
53 * Test whitelist_protocols() with allowed protocols.
54 */
55 public function testWhitelistDisallowedProtocol()
56 {
57 $whitelist = ['ftp', 'magnet'];
58 $url = 'javascript:alert("xss");';
59 $this->assertEquals('http://alert("xss");', whitelist_protocols($url, $whitelist));
60 $url = 'other://test.tld/path/?query=value#hash';
61 $this->assertEquals('http://test.tld/path/?query=value#hash', whitelist_protocols($url, $whitelist));
62 }
63}