]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - tests/http/UrlUtils/CleanupUrlTest.php
namespacing: move HTTP utilities along \Shaarli\Http\ classes
[github/shaarli/Shaarli.git] / tests / http / UrlUtils / CleanupUrlTest.php
CommitLineData
ef591e7e
GV
1<?php
2/**
3 * Unitary tests for cleanup_url()
4 */
5
51753e40 6namespace Shaarli\Http;
ef591e7e 7
51753e40
V
8require_once 'application/http/UrlUtils.php';
9
10class CleanupUrlTest extends \PHPUnit\Framework\TestCase
ef591e7e
GV
11{
12 /**
eaf25248
V
13 * @var string reference URL
14 */
15 protected $ref = 'http://domain.tld:3000';
16
17
18 /**
19 * Clean empty URL
ef591e7e
GV
20 */
21 public function testCleanupUrlEmpty()
22 {
23 $this->assertEquals('', cleanup_url(''));
24 }
25
26 /**
eaf25248 27 * Clean an already cleaned URL
ef591e7e
GV
28 */
29 public function testCleanupUrlAlreadyClean()
30 {
eaf25248
V
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'));
ef591e7e
GV
68 }
69
70 /**
eaf25248 71 * Clean URL query - multiple annoying parameters
ef591e7e 72 */
eaf25248 73 public function testCleanupUrlQueryMultiple()
ef591e7e 74 {
eaf25248
V
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'
ef591e7e 79 ));
eaf25248
V
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'
ef591e7e
GV
93 ));
94
95 // ditch annoying query params and fragment, keep useful params
96 $this->assertEquals(
eaf25248 97 $this->ref.'?my=stuff&is=kept',
ef591e7e 98 cleanup_url(
eaf25248 99 $this->ref.'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#tk.rss_all'
ef591e7e
GV
100 )
101 );
102
103 // ditch annoying query params, keep useful params and fragment
104 $this->assertEquals(
eaf25248 105 $this->ref.'?my=stuff&is=kept#again',
ef591e7e 106 cleanup_url(
eaf25248 107 $this->ref.'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#again'
ef591e7e
GV
108 )
109 );
110 }
111}