diff options
Diffstat (limited to 'tests/Url/CleanupUrlTest.php')
-rw-r--r-- | tests/Url/CleanupUrlTest.php | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/Url/CleanupUrlTest.php b/tests/Url/CleanupUrlTest.php new file mode 100644 index 00000000..ba9a0437 --- /dev/null +++ b/tests/Url/CleanupUrlTest.php | |||
@@ -0,0 +1,76 @@ | |||
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 | * Clean empty UrlThanks for building nothing | ||
12 | */ | ||
13 | public function testCleanupUrlEmpty() | ||
14 | { | ||
15 | $this->assertEquals('', cleanup_url('')); | ||
16 | } | ||
17 | |||
18 | /** | ||
19 | * Clean an already cleaned Url | ||
20 | */ | ||
21 | public function testCleanupUrlAlreadyClean() | ||
22 | { | ||
23 | $ref = 'http://domain.tld:3000'; | ||
24 | $this->assertEquals($ref, cleanup_url($ref)); | ||
25 | $ref = $ref.'/path/to/dir/'; | ||
26 | $this->assertEquals($ref, cleanup_url($ref)); | ||
27 | } | ||
28 | |||
29 | /** | ||
30 | * Clean Url needing cleaning | ||
31 | */ | ||
32 | public function testCleanupUrlNeedClean() | ||
33 | { | ||
34 | $ref = 'http://domain.tld:3000'; | ||
35 | $this->assertEquals($ref, cleanup_url($ref.'#tk.rss_all')); | ||
36 | $this->assertEquals($ref, cleanup_url($ref.'#xtor=RSS-')); | ||
37 | $this->assertEquals($ref, cleanup_url($ref.'#xtor=RSS-U3ht0tkc4b')); | ||
38 | $this->assertEquals($ref, cleanup_url($ref.'?action_object_map=junk')); | ||
39 | $this->assertEquals($ref, cleanup_url($ref.'?action_ref_map=Cr4p!')); | ||
40 | $this->assertEquals($ref, cleanup_url($ref.'?action_type_map=g4R84g3')); | ||
41 | |||
42 | $this->assertEquals($ref, cleanup_url($ref.'?fb_stuff=v41u3')); | ||
43 | $this->assertEquals($ref, cleanup_url($ref.'?fb=71m3w4573')); | ||
44 | |||
45 | $this->assertEquals($ref, cleanup_url($ref.'?utm_campaign=zomg')); | ||
46 | $this->assertEquals($ref, cleanup_url($ref.'?utm_medium=numnum')); | ||
47 | $this->assertEquals($ref, cleanup_url($ref.'?utm_source=c0d3')); | ||
48 | $this->assertEquals($ref, cleanup_url($ref.'?utm_term=1n4l')); | ||
49 | |||
50 | $this->assertEquals($ref, cleanup_url($ref.'?xtor=some-url')); | ||
51 | $this->assertEquals($ref, cleanup_url($ref.'?xtor=some-url&fb=som3th1ng')); | ||
52 | $this->assertEquals($ref, cleanup_url( | ||
53 | $ref.'?fb=stuff&utm_campaign=zomg&utm_medium=numnum&utm_source=c0d3' | ||
54 | )); | ||
55 | $this->assertEquals($ref, cleanup_url( | ||
56 | $ref.'?xtor=some-url&fb=som3th1ng#tk.rss_all' | ||
57 | )); | ||
58 | |||
59 | // ditch annoying query params and fragment, keep useful params | ||
60 | $this->assertEquals( | ||
61 | $ref.'?my=stuff&is=kept', | ||
62 | cleanup_url( | ||
63 | $ref.'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#tk.rss_all' | ||
64 | ) | ||
65 | ); | ||
66 | |||
67 | // ditch annoying query params, keep useful params and fragment | ||
68 | $this->assertEquals( | ||
69 | $ref.'?my=stuff&is=kept#again', | ||
70 | cleanup_url( | ||
71 | $ref.'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#again' | ||
72 | ) | ||
73 | ); | ||
74 | } | ||
75 | } | ||
76 | |||