aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/http/UrlUtils/CleanupUrlTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-10-13 12:07:13 +0200
committerArthurHoaro <arthur@hoa.ro>2020-10-13 12:07:13 +0200
commitd9f6275ebca035fec8331652c677981056793ccc (patch)
tree37a64baf4f0eba6b781040605965383d8aded2cc /tests/http/UrlUtils/CleanupUrlTest.php
parent38672ba0d1c722e5d6d33a58255ceb55e9410e46 (diff)
parentd63ff87a009313141ae684ec447b902562ff6ee7 (diff)
downloadShaarli-d9f6275ebca035fec8331652c677981056793ccc.tar.gz
Shaarli-d9f6275ebca035fec8331652c677981056793ccc.tar.zst
Shaarli-d9f6275ebca035fec8331652c677981056793ccc.zip
Merge branch 'v0.11' into stablestable
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}