2015-09-02 13:55:39 +02:00
|
|
|
<?php
|
2021-04-05 09:39:34 +02:00
|
|
|
|
2015-09-02 13:55:39 +02:00
|
|
|
/**
|
|
|
|
* Unitary tests for cleanup_url()
|
|
|
|
*/
|
|
|
|
|
2018-12-03 00:34:53 +01:00
|
|
|
namespace Shaarli\Http;
|
2015-09-02 13:55:39 +02:00
|
|
|
|
2018-12-03 00:34:53 +01:00
|
|
|
require_once 'application/http/UrlUtils.php';
|
|
|
|
|
2020-09-29 14:41:40 +02:00
|
|
|
class CleanupUrlTest extends \Shaarli\TestCase
|
2015-09-02 13:55:39 +02:00
|
|
|
{
|
|
|
|
/**
|
2017-01-03 17:04:18 +01:00
|
|
|
* @var string reference URL
|
|
|
|
*/
|
|
|
|
protected $ref = 'http://domain.tld:3000';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean empty URL
|
2015-09-02 13:55:39 +02:00
|
|
|
*/
|
|
|
|
public function testCleanupUrlEmpty()
|
|
|
|
{
|
|
|
|
$this->assertEquals('', cleanup_url(''));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-03 17:04:18 +01:00
|
|
|
* Clean an already cleaned URL
|
2015-09-02 13:55:39 +02:00
|
|
|
*/
|
|
|
|
public function testCleanupUrlAlreadyClean()
|
|
|
|
{
|
2017-01-03 17:04:18 +01:00
|
|
|
$this->assertEquals($this->ref, cleanup_url($this->ref));
|
2021-04-05 09:39:34 +02:00
|
|
|
$this->ref2 = $this->ref . '/path/to/dir/';
|
2017-01-03 17:04:18 +01:00
|
|
|
$this->assertEquals($this->ref2, cleanup_url($this->ref2));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean URL fragments
|
|
|
|
*/
|
|
|
|
public function testCleanupUrlFragment()
|
|
|
|
{
|
2021-04-05 09:39:34 +02:00
|
|
|
$this->assertEquals($this->ref, cleanup_url($this->ref . '#tk.rss_all'));
|
|
|
|
$this->assertEquals($this->ref, cleanup_url($this->ref . '#xtor=RSS-'));
|
|
|
|
$this->assertEquals($this->ref, cleanup_url($this->ref . '#xtor=RSS-U3ht0tkc4b'));
|
2017-01-03 17:04:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean URL query - single annoying parameter
|
|
|
|
*/
|
|
|
|
public function testCleanupUrlQuerySingle()
|
|
|
|
{
|
2021-04-05 09:39:34 +02:00
|
|
|
$this->assertEquals($this->ref, cleanup_url($this->ref . '?action_object_map=junk'));
|
|
|
|
$this->assertEquals($this->ref, cleanup_url($this->ref . '?action_ref_map=Cr4p!'));
|
|
|
|
$this->assertEquals($this->ref, cleanup_url($this->ref . '?action_type_map=g4R84g3'));
|
2017-01-03 17:04:18 +01:00
|
|
|
|
2021-04-05 09:39:34 +02:00
|
|
|
$this->assertEquals($this->ref, cleanup_url($this->ref . '?fb_stuff=v41u3'));
|
|
|
|
$this->assertEquals($this->ref, cleanup_url($this->ref . '?fb=71m3w4573'));
|
2017-01-03 17:04:18 +01:00
|
|
|
|
2021-04-05 09:39:34 +02:00
|
|
|
$this->assertEquals($this->ref, cleanup_url($this->ref . '?utm_campaign=zomg'));
|
|
|
|
$this->assertEquals($this->ref, cleanup_url($this->ref . '?utm_medium=numnum'));
|
|
|
|
$this->assertEquals($this->ref, cleanup_url($this->ref . '?utm_source=c0d3'));
|
|
|
|
$this->assertEquals($this->ref, cleanup_url($this->ref . '?utm_term=1n4l'));
|
2017-01-03 17:04:18 +01:00
|
|
|
|
2021-04-05 09:39:34 +02:00
|
|
|
$this->assertEquals($this->ref, cleanup_url($this->ref . '?xtor=some-url'));
|
2017-01-03 17:04:18 +01:00
|
|
|
|
2021-04-05 09:39:34 +02:00
|
|
|
$this->assertEquals($this->ref, cleanup_url($this->ref . '?campaign_name=junk'));
|
|
|
|
$this->assertEquals($this->ref, cleanup_url($this->ref . '?campaign_start=junk'));
|
|
|
|
$this->assertEquals($this->ref, cleanup_url($this->ref . '?campaign_item_index=junk'));
|
2015-09-02 13:55:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-03 17:04:18 +01:00
|
|
|
* Clean URL query - multiple annoying parameters
|
2015-09-02 13:55:39 +02:00
|
|
|
*/
|
2017-01-03 17:04:18 +01:00
|
|
|
public function testCleanupUrlQueryMultiple()
|
2015-09-02 13:55:39 +02:00
|
|
|
{
|
2021-04-05 09:39:34 +02:00
|
|
|
$this->assertEquals($this->ref, cleanup_url($this->ref . '?xtor=some-url&fb=som3th1ng'));
|
2017-01-03 17:04:18 +01:00
|
|
|
|
|
|
|
$this->assertEquals($this->ref, cleanup_url(
|
2021-04-05 09:39:34 +02:00
|
|
|
$this->ref . '?fb=stuff&utm_campaign=zomg&utm_medium=numnum&utm_source=c0d3'
|
2015-09-02 13:55:39 +02:00
|
|
|
));
|
2017-01-03 17:04:18 +01:00
|
|
|
|
|
|
|
$this->assertEquals($this->ref, cleanup_url(
|
2021-04-05 09:39:34 +02:00
|
|
|
$this->ref . '?campaign_start=zomg&campaign_name=numnum'
|
2017-01-03 17:04:18 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean URL query - multiple annoying parameters and fragment
|
|
|
|
*/
|
|
|
|
public function testCleanupUrlQueryFragment()
|
|
|
|
{
|
|
|
|
$this->assertEquals($this->ref, cleanup_url(
|
2021-04-05 09:39:34 +02:00
|
|
|
$this->ref . '?xtor=some-url&fb=som3th1ng#tk.rss_all'
|
2015-09-02 13:55:39 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
// ditch annoying query params and fragment, keep useful params
|
|
|
|
$this->assertEquals(
|
2021-04-05 09:39:34 +02:00
|
|
|
$this->ref . '?my=stuff&is=kept',
|
2015-09-02 13:55:39 +02:00
|
|
|
cleanup_url(
|
2021-04-05 09:39:34 +02:00
|
|
|
$this->ref . '?fb=zomg&my=stuff&utm_medium=numnum&is=kept#tk.rss_all'
|
2015-09-02 13:55:39 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// ditch annoying query params, keep useful params and fragment
|
|
|
|
$this->assertEquals(
|
2021-04-05 09:39:34 +02:00
|
|
|
$this->ref . '?my=stuff&is=kept#again',
|
2015-09-02 13:55:39 +02:00
|
|
|
cleanup_url(
|
2021-04-05 09:39:34 +02:00
|
|
|
$this->ref . '?fb=zomg&my=stuff&utm_medium=numnum&is=kept#again'
|
2015-09-02 13:55:39 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|