3 * Unitary tests for cleanup_url()
6 require_once 'application/Url.php';
8 class CleanupUrlTest
extends PHPUnit_Framework_TestCase
11 * @var string reference URL
13 protected $ref = 'http://domain.tld:3000';
19 public function testCleanupUrlEmpty()
21 $this->assertEquals('', cleanup_url(''));
25 * Clean an already cleaned URL
27 public function testCleanupUrlAlreadyClean()
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
));
37 public function testCleanupUrlFragment()
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'));
45 * Clean URL query - single annoying parameter
47 public function testCleanupUrlQuerySingle()
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'));
53 $this->assertEquals($this->ref
, cleanup_url($this->ref
.'?fb_stuff=v41u3'));
54 $this->assertEquals($this->ref
, cleanup_url($this->ref
.'?fb=71m3w4573'));
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'));
61 $this->assertEquals($this->ref
, cleanup_url($this->ref
.'?xtor=some-url'));
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'));
69 * Clean URL query - multiple annoying parameters
71 public function testCleanupUrlQueryMultiple()
73 $this->assertEquals($this->ref
, cleanup_url($this->ref
.'?xtor=some-url&fb=som3th1ng'));
75 $this->assertEquals($this->ref
, cleanup_url(
76 $this->ref
.'?fb=stuff&utm_campaign=zomg&utm_medium=numnum&utm_source=c0d3'
79 $this->assertEquals($this->ref
, cleanup_url(
80 $this->ref
.'?campaign_start=zomg&campaign_name=numnum'
85 * Clean URL query - multiple annoying parameters and fragment
87 public function testCleanupUrlQueryFragment()
89 $this->assertEquals($this->ref
, cleanup_url(
90 $this->ref
.'?xtor=some-url&fb=som3th1ng#tk.rss_all'
93 // ditch annoying query params and fragment, keep useful params
95 $this->ref
.'?my=stuff&is=kept',
97 $this->ref
.'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#tk.rss_all'
101 // ditch annoying query params, keep useful params and fragment
103 $this->ref
.'?my=stuff&is=kept#again',
105 $this->ref
.'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#again'