قرینه از
https://github.com/matomo-org/matomo.git
synced 2025-08-22 15:07:44 +00:00

* [Coding Style] Enable rule PSR1.Methods.CamelCapsMethodName.NotCamelCaps * [Coding Style] Use camel case for method names in API plugin tests (#22145) * [Coding Style] Use camel case for method names in Core* plugin tests (#22147) * [Coding Style] Use camel case for method names in core Unit tests (#22149) * [Coding Style] Use camel case for method names in Actions and BulkTracking plugin tests (#22146) * [Coding Style] Use camel case for method names in CustomDimensions and CustomJSTracker plugin tests (#22148) * [Coding Style] Use camel case for method names in core Integration tests (#22151) * [Coding Style] Use camel case for method names in more core plugin tests (#22153) * [Coding Style] Use camel case for method names in more core plugin tests (#22157) * [Coding Style] Use camel case for method names in more core plugin tests * Update plugins/Monolog/tests/Unit/Processor/ExceptionToTextProcessorTest.php Co-authored-by: Michal Kleiner <michal@innocraft.com> --------- Co-authored-by: Michal Kleiner <michal@innocraft.com> * [Coding Style] Use camel case for method names in more core plugin tests (#22159) * [Coding Style] Use camel case for method names in remaining tests (#22160) * [Coding Style] Use camel case for method names in remaining tests * rename expected test files --------- Co-authored-by: Michal Kleiner <michal@innocraft.com>
102 خطوط
4.5 KiB
PHP
102 خطوط
4.5 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\PrivacyManager\tests\Unit;
|
|
|
|
use Piwik\Common;
|
|
use Piwik\Plugins\PrivacyManager\ReferrerAnonymizer;
|
|
|
|
class AnonymizeReferrerTest extends \PHPUnit\Framework\TestCase
|
|
{
|
|
/**
|
|
* @var ReferrerAnonymizer
|
|
*/
|
|
private $anonymizer;
|
|
|
|
public function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->anonymizer = new ReferrerAnonymizer();
|
|
}
|
|
|
|
/**
|
|
* @dataProvider getReferrerUrls
|
|
*/
|
|
public function testAnonymiseReferrerUrl($expected, $url, $option)
|
|
{
|
|
$value = $this->anonymizer->anonymiseReferrerUrl($url, $option);
|
|
$this->assertSame($expected, $value);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider getReferrerNames
|
|
*/
|
|
public function testAnonymiseReferrerName($expected, $name, $type, $option)
|
|
{
|
|
$value = $this->anonymizer->anonymiseReferrerName($name, $type, $option);
|
|
$this->assertSame($expected, $value);
|
|
}
|
|
|
|
public function getReferrerNames()
|
|
{
|
|
return array(
|
|
['foo', 'foo', Common::REFERRER_TYPE_WEBSITE, ReferrerAnonymizer::EXCLUDE_NONE,],
|
|
['baz', 'baz', Common::REFERRER_TYPE_SEARCH_ENGINE, ReferrerAnonymizer::EXCLUDE_ALL,], // search and social is always kept
|
|
['bar', 'bar', Common::REFERRER_TYPE_CAMPAIGN, ReferrerAnonymizer::EXCLUDE_ALL,], //campaign is always kept
|
|
['', 'foo.com', Common::REFERRER_TYPE_WEBSITE, ReferrerAnonymizer::EXCLUDE_ALL,],
|
|
['foo.com', 'foo.com', Common::REFERRER_TYPE_WEBSITE, ReferrerAnonymizer::EXCLUDE_PATH,], // host should be kept
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider getReferrerKeywords
|
|
*/
|
|
public function testAnonymiseReferrerKeyword($expected, $keyword, $type, $option)
|
|
{
|
|
$value = $this->anonymizer->anonymiseReferrerKeyword($keyword, $type, $option);
|
|
$this->assertSame($expected, $value);
|
|
}
|
|
|
|
public function getReferrerKeywords()
|
|
{
|
|
return array(
|
|
['foo', 'foo', Common::REFERRER_TYPE_WEBSITE, ReferrerAnonymizer::EXCLUDE_NONE,],
|
|
['bar', 'bar', Common::REFERRER_TYPE_CAMPAIGN, ReferrerAnonymizer::EXCLUDE_ALL,], //campaign is always kept
|
|
['', 'baz', Common::REFERRER_TYPE_SEARCH_ENGINE, ReferrerAnonymizer::EXCLUDE_ALL,],
|
|
['', 'foo.com', Common::REFERRER_TYPE_WEBSITE, ReferrerAnonymizer::EXCLUDE_ALL,],
|
|
['', 'foo.com', Common::REFERRER_TYPE_WEBSITE, ReferrerAnonymizer::EXCLUDE_PATH,],
|
|
['', 'foo.com', Common::REFERRER_TYPE_WEBSITE, ReferrerAnonymizer::EXCLUDE_QUERY,],
|
|
['', 'foo.com', Common::REFERRER_TYPE_SEARCH_ENGINE, ReferrerAnonymizer::EXCLUDE_QUERY,],
|
|
['', 'foo.com', Common::REFERRER_TYPE_SEARCH_ENGINE, ReferrerAnonymizer::EXCLUDE_PATH,],
|
|
['foo.com', 'foo.com', Common::REFERRER_TYPE_SEARCH_ENGINE, ReferrerAnonymizer::EXCLUDE_NONE,],
|
|
['foo.com', 'foo.com', Common::REFERRER_TYPE_WEBSITE, ReferrerAnonymizer::EXCLUDE_NONE,],
|
|
);
|
|
}
|
|
|
|
public function getReferrerUrls()
|
|
{
|
|
return array(
|
|
[false, false, ReferrerAnonymizer::EXCLUDE_ALL,],
|
|
[false, false, ReferrerAnonymizer::EXCLUDE_NONE,],
|
|
['https://foo.com/bar/baz?hello=world', 'https://foo.com/bar/baz?hello=world', ReferrerAnonymizer::EXCLUDE_NONE,],
|
|
['', 'https://foo.com/bar/baz?hello=world', ReferrerAnonymizer::EXCLUDE_ALL,],
|
|
['https://foo.com/bar/baz/', 'https://foo.com/bar/baz/?hello=world', ReferrerAnonymizer::EXCLUDE_QUERY,],
|
|
['https://foo.com/bar/baz', 'https://foo.com/bar/baz?hello=world', ReferrerAnonymizer::EXCLUDE_QUERY,],
|
|
['https://foo.com/bar/baz', 'https://foo.com/bar/baz', ReferrerAnonymizer::EXCLUDE_QUERY,],
|
|
['https://foo.com/', 'https://foo.com/bar/baz/?hello=world', ReferrerAnonymizer::EXCLUDE_PATH,],
|
|
['https://foo.com/', 'https://foo.com/bar/baz?hello=world', ReferrerAnonymizer::EXCLUDE_PATH,],
|
|
['https://foo.com/', 'https://foo.com/bar/baz', ReferrerAnonymizer::EXCLUDE_PATH,],
|
|
['https://foo.com/', 'https://foo.com/bar/baz', ReferrerAnonymizer::EXCLUDE_PATH,],
|
|
['https://foo.com', 'https://foo.com', ReferrerAnonymizer::EXCLUDE_PATH,], // no path
|
|
['//foo.com/', '//foo.com/path?x=1', ReferrerAnonymizer::EXCLUDE_PATH,],
|
|
['foo.com/path?x=2', 'foo.com/path?x=2', ReferrerAnonymizer::EXCLUDE_PATH,],// not really a URL so isn't anonymised
|
|
);
|
|
}
|
|
}
|