From ef591e7ee21435da9314c5f7f6ea983c6f423898 Mon Sep 17 00:00:00 2001 From: Guillaume Virlet Date: Wed, 2 Sep 2015 13:55:39 +0200 Subject: 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 --- tests/Url/CleanupUrlTest.php | 76 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/Url/CleanupUrlTest.php (limited to 'tests/Url/CleanupUrlTest.php') 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 @@ +assertEquals('', cleanup_url('')); + } + + /** + * Clean an already cleaned Url + */ + public function testCleanupUrlAlreadyClean() + { + $ref = 'http://domain.tld:3000'; + $this->assertEquals($ref, cleanup_url($ref)); + $ref = $ref.'/path/to/dir/'; + $this->assertEquals($ref, cleanup_url($ref)); + } + + /** + * Clean Url needing cleaning + */ + public function testCleanupUrlNeedClean() + { + $ref = 'http://domain.tld:3000'; + $this->assertEquals($ref, cleanup_url($ref.'#tk.rss_all')); + $this->assertEquals($ref, cleanup_url($ref.'#xtor=RSS-')); + $this->assertEquals($ref, cleanup_url($ref.'#xtor=RSS-U3ht0tkc4b')); + $this->assertEquals($ref, cleanup_url($ref.'?action_object_map=junk')); + $this->assertEquals($ref, cleanup_url($ref.'?action_ref_map=Cr4p!')); + $this->assertEquals($ref, cleanup_url($ref.'?action_type_map=g4R84g3')); + + $this->assertEquals($ref, cleanup_url($ref.'?fb_stuff=v41u3')); + $this->assertEquals($ref, cleanup_url($ref.'?fb=71m3w4573')); + + $this->assertEquals($ref, cleanup_url($ref.'?utm_campaign=zomg')); + $this->assertEquals($ref, cleanup_url($ref.'?utm_medium=numnum')); + $this->assertEquals($ref, cleanup_url($ref.'?utm_source=c0d3')); + $this->assertEquals($ref, cleanup_url($ref.'?utm_term=1n4l')); + + $this->assertEquals($ref, cleanup_url($ref.'?xtor=some-url')); + $this->assertEquals($ref, cleanup_url($ref.'?xtor=some-url&fb=som3th1ng')); + $this->assertEquals($ref, cleanup_url( + $ref.'?fb=stuff&utm_campaign=zomg&utm_medium=numnum&utm_source=c0d3' + )); + $this->assertEquals($ref, cleanup_url( + $ref.'?xtor=some-url&fb=som3th1ng#tk.rss_all' + )); + + // ditch annoying query params and fragment, keep useful params + $this->assertEquals( + $ref.'?my=stuff&is=kept', + cleanup_url( + $ref.'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#tk.rss_all' + ) + ); + + // ditch annoying query params, keep useful params and fragment + $this->assertEquals( + $ref.'?my=stuff&is=kept#again', + cleanup_url( + $ref.'?fb=zomg&my=stuff&utm_medium=numnum&is=kept#again' + ) + ); + } +} + -- cgit v1.2.3