قرینه از
https://github.com/matomo-org/matomo.git
synced 2025-08-22 06:57:53 +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>
134 خطوط
3.4 KiB
PHP
134 خطوط
3.4 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\Plugins\PrivacyManager\Config;
|
|
use Piwik\Plugins\PrivacyManager\DoNotTrackHeaderChecker;
|
|
|
|
/**
|
|
* Class DoNotTrackHeaderCheckerTest
|
|
* @group DoNotTrackHeaderCheckerTest
|
|
*/
|
|
class DoNotTrackHeaderCheckerTest extends \PHPUnit\Framework\TestCase
|
|
{
|
|
public function setUp(): void
|
|
{
|
|
$this->cleanupServerGlobals();
|
|
|
|
$this->setUserAgentToChrome();
|
|
}
|
|
|
|
public function tearDown(): void
|
|
{
|
|
$this->cleanupServerGlobals();
|
|
}
|
|
|
|
public function testIsDoNotTrackFoundWhenDntNotActivated()
|
|
{
|
|
$dntChecker = $this->makeDntHeaderChecker();
|
|
|
|
$this->assertFalse($dntChecker->isActive());
|
|
$this->assertFalse($dntChecker->isDoNotTrackFound());
|
|
}
|
|
|
|
public function getHeaderDntIsActivated()
|
|
{
|
|
return array(
|
|
array('HTTP_X_DO_NOT_TRACK', '1'),
|
|
array('HTTP_DNT', '1'),
|
|
array('HTTP_DNT', '10'),
|
|
);
|
|
}
|
|
|
|
public function getHeaderDntIsNotActivated()
|
|
{
|
|
return array(
|
|
array('HTTP_DNT', '0'),
|
|
array('HTTP_DNT', 'x'),
|
|
array('HTTP_X_DO_NOT_TRACK', 'false'),
|
|
array('HTTP_X_DO_NOT_TRACK', 'ok'),
|
|
array('HTTP_X_DO_NOT_TRACK', '11'),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider getHeaderDntIsActivated
|
|
*/
|
|
public function testIsDoNotTrackFoundWhenDntActivatedBrowserHasDntHeader($headerName, $headerValue)
|
|
{
|
|
$dntChecker = $this->makeDntHeaderCheckerEnabled();
|
|
|
|
$_SERVER[$headerName] = $headerValue;
|
|
$this->assertTrue($dntChecker->isDoNotTrackFound());
|
|
}
|
|
|
|
/**
|
|
* @dataProvider getHeaderDntIsNotActivated
|
|
*/
|
|
public function testIsDoNotTrackFoundWhenDntActivatedBrowserDoesNotHaveDntHeader($headerName, $headerValue)
|
|
{
|
|
$dntChecker = $this->makeDntHeaderCheckerEnabled();
|
|
|
|
$_SERVER[$headerName] = $headerValue;
|
|
$this->assertFalse($dntChecker->isDoNotTrackFound());
|
|
}
|
|
|
|
/**
|
|
* @return Config
|
|
*/
|
|
protected function makeConfig()
|
|
{
|
|
return new \Piwik\Plugins\PrivacyManager\tests\Framework\Mock\Config();
|
|
}
|
|
|
|
/**
|
|
* @return DoNotTrackHeaderChecker
|
|
*/
|
|
protected function makeDntHeaderChecker()
|
|
{
|
|
$config = $this->makeConfig();
|
|
$config->doNotTrackEnabled = false;
|
|
|
|
$dntChecker = new DoNotTrackHeaderChecker($config);
|
|
|
|
$this->assertFalse($dntChecker->isActive());
|
|
|
|
return $dntChecker;
|
|
}
|
|
|
|
protected function cleanupServerGlobals()
|
|
{
|
|
$_SERVER['HTTP_X_DO_NOT_TRACK'] = null;
|
|
$_SERVER['HTTP_DNT'] = null;
|
|
$_SERVER['HTTP_USER_AGENT'] = null;
|
|
}
|
|
|
|
/**
|
|
* @return DoNotTrackHeaderChecker
|
|
*/
|
|
protected function makeDntHeaderCheckerEnabled()
|
|
{
|
|
$dntChecker = $this->makeDntHeaderChecker();
|
|
$dntChecker->activate();
|
|
$this->assertTrue($dntChecker->isActive());
|
|
return $dntChecker;
|
|
}
|
|
|
|
protected function setUserAgentToChrome()
|
|
{
|
|
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 ArchLinux (X11; U; Linux x86_64; en-US) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.100 Safari/534.30';
|
|
}
|
|
|
|
protected function activateDoNotTrackInBrowser()
|
|
{
|
|
$_SERVER['HTTP_DNT'] = '1';
|
|
}
|
|
}
|