diff options
Diffstat (limited to 'tests/http/UrlUtils/CleanupUrlTest.php')
-rw-r--r-- | tests/http/UrlUtils/CleanupUrlTest.php | 111 |
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 | |||
6 | namespace Shaarli\Http; | ||
7 | |||
8 | require_once 'application/http/UrlUtils.php'; | ||
9 | |||
10 | class 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 | } | ||