aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Url/CleanupUrlTest.php
diff options
context:
space:
mode:
authorGuillaume Virlet <github@virlet.org>2015-09-02 13:55:39 +0200
committerGuillaume Virlet <github@virlet.org>2015-09-08 22:00:37 +0200
commitef591e7ee21435da9314c5f7f6ea983c6f423898 (patch)
treea58c1bcaab33d42161b23d55c739737526ea17e9 /tests/Url/CleanupUrlTest.php
parent0a813cfd7cdf3c81faba8568bf6e2e667aae6f13 (diff)
downloadShaarli-ef591e7ee21435da9314c5f7f6ea983c6f423898.tar.gz
Shaarli-ef591e7ee21435da9314c5f7f6ea983c6f423898.tar.zst
Shaarli-ef591e7ee21435da9314c5f7f6ea983c6f423898.zip
Url: introduce global helper functions for cleanup and scheme detection
Relates to #314 & #326 Additions: - add global `cleanup_url()` and `get_url_scheme()` functions Modifications: - replace `Url` usage in `index.php` by calls to global functions - fix `Url` tests not being run: PHPUnit expects a single test class per file - move classes to separate files
Diffstat (limited to 'tests/Url/CleanupUrlTest.php')
-rw-r--r--tests/Url/CleanupUrlTest.php76
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
6require_once 'application/Url.php';
7
8class 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