diff options
author | pafgoncalves <pafgoncalves@users.noreply.github.com> | 2016-11-30 21:52:08 +0300 |
---|---|---|
committer | Matthieu Aubry <mattab@users.noreply.github.com> | 2016-11-30 21:52:08 +0300 |
commit | fa2fca9512c208e89971661548bf960f991d613d (patch) | |
tree | d7025286fa7a4519d715ca3a52a4cd8ac4ea051e /tests | |
parent | ffc37961d811b1922bc94bf3a1173f71562305f9 (diff) |
Add regular expressions to the exclude parameters (#10846)
Allows to use regular expressions in the exclude parameters option.
Doesn't break compatibility if the parameter is not a regular expression, doing a strict compare.
"/.*/" can be used to exclude all parameters.
* Changed the UI texts to explain that the excluding parameters list supports regular expressions.
Added unit tests.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PHPUnit/Integration/Tracker/ActionTest.php | 15 | ||||
-rw-r--r-- | tests/PHPUnit/Unit/UrlHelperTest.php | 60 |
2 files changed, 75 insertions, 0 deletions
diff --git a/tests/PHPUnit/Integration/Tracker/ActionTest.php b/tests/PHPUnit/Integration/Tracker/ActionTest.php index 5eab999b66..724fe963a0 100644 --- a/tests/PHPUnit/Integration/Tracker/ActionTest.php +++ b/tests/PHPUnit/Integration/Tracker/ActionTest.php @@ -174,6 +174,21 @@ class ActionTest extends IntegrationTestCase } /** + * Testing with some website specific parameters excluded using regular expressions + * @dataProvider getTestUrls + */ + public function testExcludeQueryParametersRegExSiteExcluded($url, $filteredUrl) + { + $excludedQueryParameters = '/p[4|2]/, /^var.*/'; + $this->setUpRootAccess(); + $idSite = API::getInstance()->addSite("site1", array('http://example.org'), $ecommerce = 0, + $siteSearch = 1, $searchKeywordParameters = null, $searchCategoryParameters = null, + $excludedIps = '', $excludedQueryParameters, $timezone = null, $currency = null, + $group = null, $startDate = null, $excludedUserAgents = null, $keepURLFragments = 1); + $this->assertEquals($filteredUrl[1], PageUrl::excludeQueryParametersFromUrl($url, $idSite)); + } + + /** * Testing with some website specific and some global excluded query parameters * @dataProvider getTestUrls */ diff --git a/tests/PHPUnit/Unit/UrlHelperTest.php b/tests/PHPUnit/Unit/UrlHelperTest.php index 09aab2c2f3..369cfb3a34 100644 --- a/tests/PHPUnit/Unit/UrlHelperTest.php +++ b/tests/PHPUnit/Unit/UrlHelperTest.php @@ -234,4 +234,64 @@ class UrlHelperTest extends \PHPUnit_Framework_TestCase $this->assertEquals('add=foo', UrlHelper::getQueryFromUrl('/', array('add' => 'foo'))); $this->assertEquals('add[]=foo&add[]=test', UrlHelper::getQueryFromUrl('/', array('add' => array('foo', 'test')))); } + + + /** + * Dataprovider for testGetQueryStringWithExcludedParameters + */ + public function getQueryParameters() + { + return array( + array( + 'p1=v1&p2=v2', //expected + array('p1'=>'v1', 'p2'=>'v2'), //queryParameters + array() //parametersToExclude + ), + array( + 'p2=v2', + array('p1'=>'v1', 'p2'=>'v2'), + array('p1') + ), + array( + 'p1=v1&p2=v2', + array('p1'=>'v1', 'p2'=>'v2', 'sessionId'=>'HHSJHERTG'), + array('sessionId') + ), + array( + 'p1=v1&p2=v2', + array('p1'=>'v1', 'p2'=>'v2', 'sessionId'=>'HHSJHERTG'), + array('/session/') + ), + array( + 'p1=v1&p2=v2', + array('p1'=>'v1', 'sessionId'=>'HHSJHERTG', 'p2'=>'v2', 'token'=>'RYUN36HSAO'), + array('/[session|token]/') + ), + array( + '', + array('p1'=>'v1', 'p2'=>'v2', 'sessionId'=>'HHSJHERTG', 'token'=>'RYUN36HSAO'), + array('/.*/') + ), + array( + 'p2=v2&p4=v4', + array('p1'=>'v1', 'p2'=>'v2', 'p3'=>'v3', 'p4'=>'v4'), + array('/p[1|3]/') + ), + array( + 'p2=v2&p4=v4', + array('p1'=>'v1', 'p2'=>'v2', 'p3'=>'v3', 'p4'=>'v4', 'utm_source'=>'gekko', 'utm_medium'=>'email', 'utm_campaign'=>'daily'), + array('/p[1|3]/', '/utm_/') + ) + ); + } + + /** + * @dataProvider getQueryParameters + * @group Core + */ + public function testGetQueryStringWithExcludedParameters($expected, $queryParameters, $parametersToExclude) + { + $this->assertEquals($expected, UrlHelper::getQueryStringWithExcludedParameters($queryParameters, $parametersToExclude)); + } + } |