]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - tests/Url/CleanupUrlTest.php
namespacing: \Shaarli\Http\Url
[github/shaarli/Shaarli.git] / tests / Url / CleanupUrlTest.php
1 <?php
2 /**
3 * Unitary tests for cleanup_url()
4 */
5
6 require_once 'application/Url.php';
7
8 class 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 }