1
0
قرینه از https://github.com/matomo-org/matomo.git synced 2025-08-22 23:17:46 +00:00
Files
matomo/plugins/Actions/tests/Integration/ActionSiteSearchTest.php
Michal Kleiner 9a3ef94df6 [Coding Style] Enable rule PSR12.Files.FileHeader + unify file headers (#22132)
* [Coding Style] Enable rule PSR12.Files.FileHeader

* Apply CS

* Replace Piwik with Matomo in file headers

* Unify file headers (position, no. of lines, https links)

* Rebuild dist files

* Apply CS

* Fix system test that relies on line numbers in a file that had the file header updated

---------

Co-authored-by: Stefan Giehl <stefan@matomo.org>
2024-04-20 20:50:47 +02:00

68 خطوط
3.1 KiB
PHP

<?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(): void
{
parent::setUp();
Fixture::createWebsite('2010-01-01');
}
/**
* @dataProvider getSiteSearchData
*/
public function testSiteSearchDetection($website, $url, $expectedResult)
{
$action = new ActionSiteSearch(new Request(['idsite' => 1]));
$this->assertEquals($expectedResult, ActionSiteSearch::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],
];
}
}