aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/http/UrlUtils/CleanupUrlTest.php
diff options
context:
space:
mode:
authorAurélien Tamisier <virtualtam+github@flibidi.net>2019-01-18 21:26:03 +0100
committerGitHub <noreply@github.com>2019-01-18 21:26:03 +0100
commitff3b5dc5542ec150f0d9b447394364a15e9156d0 (patch)
tree5e926e36816d510e3b3a10e20b94c23f43b55092 /tests/http/UrlUtils/CleanupUrlTest.php
parent1826e383ecf501302974132fd443cf1ca06e10f6 (diff)
parentdea72c711ff740b3b829d238fcf85648465143a0 (diff)
downloadShaarli-ff3b5dc5542ec150f0d9b447394364a15e9156d0.tar.gz
Shaarli-ff3b5dc5542ec150f0d9b447394364a15e9156d0.tar.zst
Shaarli-ff3b5dc5542ec150f0d9b447394364a15e9156d0.zip
Merge pull request #1248 from virtualtam/refactor/namespacing
Ensure all PHP classes are properly namespaced
Diffstat (limited to 'tests/http/UrlUtils/CleanupUrlTest.php')
-rw-r--r--tests/http/UrlUtils/CleanupUrlTest.php111
1 files changed, 111 insertions, 0 deletions
diff --git a/tests/http/UrlUtils/CleanupUrlTest.php b/tests/http/UrlUtils/CleanupUrlTest.php
new file mode 100644
index 00000000..6c4d124b
--- /dev/null
+++ b/tests/http/UrlUtils/CleanupUrlTest.php
@@ -0,0 +1,111 @@
1<?php
2/**
3 * Unitary tests for cleanup_url()
4 */
5
6namespace Shaarli\Http;
7
8require_once 'application/http/UrlUtils.php';
9
10class CleanupUrlTest extends \PHPUnit\Framework\TestCase
11{
12 /**
13 * @var string reference URL
14 */
15 protected $ref = 'http://domain.tld:3000';
16
17
18 /**
19 * Clean empty URL
20 */
21 public function testCleanupUrlEmpty()
22 {
23 $this->assertEquals('', cleanup_url(''));
24 }
25
26 /**
27 * Clean an already cleaned URL
28 */
29 public function testCleanupUrlAlreadyClean()
30 {
31 $this->assertEquals($this->ref, cleanup_url($this->ref));
32 $this->ref2 = $this->ref.'/path/to/dir/';
33 $this->assertEquals($this->ref2, cleanup_url($this->ref2));
34 }
35
36 /**
37 * Clean URL fragments
38 */
39 public function testCleanupUrlFragment()
40 {
41 $this->assertEquals($this->ref, cleanup_url($this->ref.'#tk.rss_all'));
42 $this->assertEquals($this->ref, cleanup_url($this->ref.'#xtor=RSS-'));
43 $this->assertEquals($this->ref, cleanup_url($this->ref.'#xtor=RSS-U3ht0tkc4b'));
44 }
45
46 /**
47 * Clean URL query - single annoying parameter
48 */
49 public function testCleanupUrlQuerySingle()
50 {
51 $this->assertEquals($this->ref, cleanup_url($this->ref.'?action_object_map=junk'));
52 $this->assertEquals($this->ref, cleanup_url($this->ref.'?action_ref_map=Cr4p!'));
53 $this->assertEquals($this->ref, cleanup_url($this->ref.'?action_type_map=g4R84g3'));
54
55 $this->assertEquals($this->ref, cleanup_url($this->ref.'?fb_stuff=v41u3'));
56 $this->assertEquals($this->ref, cleanup_url($this->ref.'?fb=71m3w4573'));
57
58 $this->assertEquals($this->ref, cleanup_url($this->ref.'?utm_campaign=zomg'));
59 $this->assertEquals($this->ref, cleanup_url($this->ref.'?utm_medium=numnum'));
60 $this->assertEquals($this->ref, cleanup_url($this->ref.'?utm_source=c0d3'));
61 $this->assertEquals($this->ref, cleanup_url($this->ref.'?utm_term=1n4l'));
62
63 $this->assertEquals($this->ref, cleanup_url($this->ref.'?xtor=some-url'));
64
65 $this->assertEquals($this->ref, cleanup_url($this->ref.'?campaign_name=junk'));
66 $this->assertEquals($this->ref, cleanup_url($this->ref.'?campaign_start=junk'));
67 $this->assertEquals($this->ref, cleanup_url($this->ref.'?campaign_item_index=junk'));
68 }
69
70 /**
71 * Clean URL query - multiple annoying parameters
72 */
73 public function testCleanupUrlQueryMultiple()
74 {
75 $this->assertEquals($this->ref, cleanup_url($this->ref.'?xtor=some-url&fb=som3th1ng'));
76
77 $this->assertEquals($this->ref, cleanup_url(
78 $this->ref.'?fb=stuff&utm_campaign=zomg&utm_medium=numnum&utm_source=c0d3'
79 ));
80
81 $this->assertEquals($this->ref, cleanup_url(
82 $this->ref.'?campaign_start=zomg&campaign_name=numnum'
83 ));
84 }
85
86 /**
87 * Clean URL query - multiple annoying parameters and fragment
88 */
89 public function testCleanupUrlQueryFragment()
90 {
91 $this->assertEquals($this->ref, cleanup_url(
92 $this->ref.'?xtor=some-url&fb=som3th1ng#tk.rss_all'
93 ));
94
95 // ditch annoying query params and fragment, keep useful params
96 $this->assertEquals(
97 $this->ref.'?my=stuff&is=kept',
98 cleanup_url(
99 $this->ref.'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#tk.rss_all'
100 )
101 );
102
103 // ditch annoying query params, keep useful params and fragment
104 $this->assertEquals(
105 $this->ref.'?my=stuff&is=kept#again',
106 cleanup_url(
107 $this->ref.'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#again'
108 )
109 );
110 }
111}