forked from matomo-org/matomo
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve site search detection in fragment query (matomo-org#13978)
* Improve site search detection in fragment query * adds some tests * improve fragment handling & add more tests
- Loading branch information
Showing
2 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
plugins/Actions/tests/Integration/ActionSiteSearchTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
/** | ||
* Matomo - free/libre analytics platform | ||
* | ||
* @link https://matomo.org | ||
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
*/ | ||
|
||
namespace Piwik\Plugins\Actions\tests\Unit; | ||
|
||
use Piwik\Plugins\Actions\Actions\ActionSiteSearch; | ||
use Piwik\Tests\Framework\Fixture; | ||
use Piwik\Tests\Framework\TestCase\IntegrationTestCase; | ||
use Piwik\Tracker\Request; | ||
|
||
/** | ||
* @group Actions | ||
* @group SiteSearch | ||
* @group Plugins | ||
*/ | ||
class ActionSiteSearchTest extends IntegrationTestCase | ||
{ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
Fixture::createWebsite('2010-01-01'); | ||
} | ||
|
||
/** | ||
* @dataProvider getSiteSearchData | ||
*/ | ||
public function testSiteSearchDetection($website, $url, $expectedResult) | ||
{ | ||
$action = new ActionSiteSearchPublic(new Request(['idsite' => 1])); | ||
$this->assertEquals($expectedResult, $action->detectSiteSearchFromUrl($website, parse_url($url))); | ||
} | ||
|
||
public function getSiteSearchData() | ||
{ | ||
$defaultWebsite = [ | ||
'idSite' => 1, | ||
'sitesearch_keyword_parameters' => ['q','k'], | ||
'sitesearch_category_parameters' => ['cat','cc'] | ||
]; | ||
|
||
return [ | ||
[$defaultWebsite, 'http://example.org/index.htm?q=keyword', ['http://example.org/index.htm', 'keyword', '', false]], | ||
[$defaultWebsite, 'http://example.org/index.htm#q=keyword&cat=test', ['http://example.org/index.htm', 'keyword', 'test', false]], | ||
[$defaultWebsite, 'http://example.org/index.htm#&q=keyword', ['http://example.org/index.htm', 'keyword', '', false]], | ||
[$defaultWebsite, 'http://example.org/index.htm#?cat=test&q=keyword', ['http://example.org/index.htm', 'keyword', 'test', false]], | ||
[$defaultWebsite, 'http://example.org/index.htm#?cat=test&q=keyword&otherparam=1', ['http://example.org/index.htm#otherparam=1', 'keyword', 'test', false]], | ||
[$defaultWebsite, 'http://example.org/index.htm?cat=test&otherparam=1&q=keyword', ['http://example.org/index.htm?otherparam=1', 'keyword', 'test', false]], | ||
[$defaultWebsite, 'http://example.org/index.htm#anchor?cat=test&otherparam=1&q=keyword', ['http://example.org/index.htm#anchor?otherparam=1', 'keyword', 'test', false]], | ||
[$defaultWebsite, 'http://example.org/index.htm?cat=test&otherparam=1&q=kw#?q=keyword', ['http://example.org/index.htm?otherparam=1', 'keyword', 'test', false]], | ||
[$defaultWebsite, 'http://example.org/index.htm?k=keyword&cc=cat', ['http://example.org/index.htm', 'keyword', 'cat', false]], | ||
[$defaultWebsite, '#?q=keyword', ['', 'keyword', '', false]], | ||
[$defaultWebsite, 'http://example.org/index.html?a=b#?&&&q=keyword', ['http://example.org/index.html?a=b', 'keyword', '', false]], | ||
[$defaultWebsite, 'http://example.org/#&?q=keyword', ['http://example.org/#&', 'keyword', '', false]], | ||
|
||
// some invalid/incorrect urls that aren't detected as site search | ||
[$defaultWebsite, 'http://example.org/index.html?a=b#?&&&?q=keyword', false], | ||
[$defaultWebsite, 'http://example.org/#&?var=val?q=keyword', false], | ||
]; | ||
} | ||
} | ||
|
||
class ActionSiteSearchPublic extends ActionSiteSearch | ||
{ | ||
public function detectSiteSearchFromUrl($website, $parsedUrl) { | ||
return parent::detectSiteSearchFromUrl($website, $parsedUrl); | ||
} | ||
} | ||
|