3 * Unitary tests for cleanup_url()
6 namespace Shaarli\Http
;
8 require_once 'application/http/UrlUtils.php';
10 class CleanupUrlTest
extends \PHPUnit\Framework\TestCase
13 * @var string reference URL
15 protected $ref = 'http://domain.tld:3000';
21 public function testCleanupUrlEmpty()
23 $this->assertEquals('', cleanup_url(''));
27 * Clean an already cleaned URL
29 public function testCleanupUrlAlreadyClean()
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
));
39 public function testCleanupUrlFragment()
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'));
47 * Clean URL query - single annoying parameter
49 public function testCleanupUrlQuerySingle()
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'));
55 $this->assertEquals($this->ref
, cleanup_url($this->ref
.'?fb_stuff=v41u3'));
56 $this->assertEquals($this->ref
, cleanup_url($this->ref
.'?fb=71m3w4573'));
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'));
63 $this->assertEquals($this->ref
, cleanup_url($this->ref
.'?xtor=some-url'));
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'));
71 * Clean URL query - multiple annoying parameters
73 public function testCleanupUrlQueryMultiple()
75 $this->assertEquals($this->ref
, cleanup_url($this->ref
.'?xtor=some-url&fb=som3th1ng'));
77 $this->assertEquals($this->ref
, cleanup_url(
78 $this->ref
.'?fb=stuff&utm_campaign=zomg&utm_medium=numnum&utm_source=c0d3'
81 $this->assertEquals($this->ref
, cleanup_url(
82 $this->ref
.'?campaign_start=zomg&campaign_name=numnum'
87 * Clean URL query - multiple annoying parameters and fragment
89 public function testCleanupUrlQueryFragment()
91 $this->assertEquals($this->ref
, cleanup_url(
92 $this->ref
.'?xtor=some-url&fb=som3th1ng#tk.rss_all'
95 // ditch annoying query params and fragment, keep useful params
97 $this->ref
.'?my=stuff&is=kept',
99 $this->ref
.'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#tk.rss_all'
103 // ditch annoying query params, keep useful params and fragment
105 $this->ref
.'?my=stuff&is=kept#again',
107 $this->ref
.'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#again'