قرینه از
https://github.com/matomo-org/matomo.git
synced 2025-08-24 16:07:37 +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>
188 خطوط
5.4 KiB
PHP
188 خطوط
5.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\Tests\Integration\Tracker;
|
|
|
|
use Piwik\Piwik;
|
|
use Piwik\Tests\Framework\Fixture;
|
|
use Piwik\Tracker\Request;
|
|
use Piwik\Tracker\RequestSet;
|
|
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
|
|
|
|
class TestRequestSet extends RequestSet
|
|
{
|
|
private $redirectUrl = '';
|
|
|
|
public function getAllSiteIdsWithinRequest()
|
|
{
|
|
return parent::getAllSiteIdsWithinRequest();
|
|
}
|
|
}
|
|
/**
|
|
* @group RequestSetTest
|
|
* @group RequestSet
|
|
* @group Tracker
|
|
*/
|
|
class RequestSetTest extends IntegrationTestCase
|
|
{
|
|
/**
|
|
* @var TestRequestSet
|
|
*/
|
|
private $requestSet;
|
|
private $get;
|
|
private $post;
|
|
private $time;
|
|
|
|
protected static function beforeTableDataCached()
|
|
{
|
|
parent::beforeTableDataCached();
|
|
|
|
Fixture::createWebsite('2014-01-01 00:00:00');
|
|
Fixture::createWebsite('2014-01-01 00:00:00', 0, false, 'http://www.example.com');
|
|
|
|
foreach (range(3, 10) as $idSite) {
|
|
Fixture::createWebsite('2014-01-01 00:00:00');
|
|
}
|
|
}
|
|
|
|
public function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->requestSet = $this->buildNewRequestSetThatIsNotInitializedYet();
|
|
$this->requestSet->setRequests(array(array('idsite' => 1), array('idsite' => 2)));
|
|
|
|
$this->get = $_GET;
|
|
$this->post = $_POST;
|
|
|
|
$this->time = time();
|
|
|
|
$_GET = array();
|
|
$_POST = array();
|
|
}
|
|
|
|
public function tearDown(): void
|
|
{
|
|
$_GET = $this->get;
|
|
$_POST = $this->post;
|
|
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function testGetAllSiteIdsWithinRequestShouldReturnEmptyArrayIfNoRequestsSet()
|
|
{
|
|
$this->requestSet = $this->buildNewRequestSetThatIsNotInitializedYet();
|
|
$this->assertEquals(array(), $this->requestSet->getAllSiteIdsWithinRequest());
|
|
}
|
|
|
|
public function testGetAllSiteIdsWithinRequestShouldReturnTheSiteIdsFromRequests()
|
|
{
|
|
$this->requestSet->setRequests($this->buildRequests(3));
|
|
|
|
$this->assertEquals(array(1, 2, 3), $this->requestSet->getAllSiteIdsWithinRequest());
|
|
}
|
|
|
|
public function testGetAllSiteIdsWithinRequestShouldReturnUniqueSiteIdsUnordered()
|
|
{
|
|
$this->requestSet->setRequests(array(
|
|
$this->buildRequest(1),
|
|
$this->buildRequest(5),
|
|
$this->buildRequest(1),
|
|
$this->buildRequest(2),
|
|
$this->buildRequest(2),
|
|
$this->buildRequest(9),
|
|
));
|
|
|
|
$this->assertEquals(array(1, 5, 2, 9), $this->requestSet->getAllSiteIdsWithinRequest());
|
|
}
|
|
|
|
/**
|
|
* @param int $numRequests
|
|
* @return Request[]
|
|
*/
|
|
private function buildRequests($numRequests)
|
|
{
|
|
$requests = array();
|
|
for ($index = 1; $index <= $numRequests; $index++) {
|
|
$requests[] = $this->buildRequest($index);
|
|
}
|
|
return $requests;
|
|
}
|
|
|
|
private function buildRequest($idsite)
|
|
{
|
|
$request = new Request(array('idsite' => ('' . $idsite)));
|
|
$request->setCurrentTimestamp($this->time);
|
|
|
|
return $request;
|
|
}
|
|
|
|
public function testInitRequestsAndTokenAuthShouldTriggerEventToInitRequestsButOnlyOnce()
|
|
{
|
|
$requestSet = $this->buildNewRequestSetThatIsNotInitializedYet();
|
|
|
|
$called = 0;
|
|
$passedRequest = null;
|
|
Piwik::addAction('Tracker.initRequestSet', function ($param) use (&$called, &$passedRequest) {
|
|
$called++;
|
|
$passedRequest = $param;
|
|
});
|
|
|
|
$requestSet->initRequestsAndTokenAuth();
|
|
$this->assertSame(1, $called);
|
|
$this->assertSame($requestSet, $passedRequest);
|
|
|
|
$requestSet->initRequestsAndTokenAuth(); // should not be called again
|
|
$this->assertSame(1, $called);
|
|
}
|
|
|
|
public function testInitRequestsAndTokednAuthShouldInitializeRequestsWithEmptyArray()
|
|
{
|
|
$requestSet = $this->buildNewRequestSetThatIsNotInitializedYet();
|
|
$requestSet->initRequestsAndTokenAuth();
|
|
$this->assertEquals(array(), $requestSet->getRequests());
|
|
}
|
|
|
|
public function testInitRequestsAndTokednAuthShouldInitializeFromGetAndPostIfEventDoesNotHandleRequests()
|
|
{
|
|
$_GET = array('idsite' => 1);
|
|
$_POST = array('c_i' => 'click');
|
|
|
|
Piwik::addAction('Tracker.initRequestSet', function (RequestSet $requestSet) {
|
|
$requestSet->setRequests(array(array('idsite' => '2'), array('idsite' => '3')));
|
|
});
|
|
|
|
$requestSet = $this->buildNewRequestSetThatIsNotInitializedYet();
|
|
|
|
$requestSet->initRequestsAndTokenAuth();
|
|
|
|
$requests = $requestSet->getRequests();
|
|
$this->assertCount(2, $requests);
|
|
$this->assertEquals(array('idsite' => '2'), $requests[0]->getParams());
|
|
$this->assertEquals(array('idsite' => '3'), $requests[1]->getParams());
|
|
}
|
|
|
|
public function testInitRequestsAndTokednAuthShouldIgnoreGetAndPostIfInitializedByEvent()
|
|
{
|
|
$_GET = array('idsite' => '1');
|
|
$_POST = array('c_i' => 'click');
|
|
|
|
$requestSet = $this->buildNewRequestSetThatIsNotInitializedYet();
|
|
$requestSet->initRequestsAndTokenAuth();
|
|
$requests = $requestSet->getRequests();
|
|
$this->assertCount(1, $requests);
|
|
$this->assertEquals(array('idsite' => 1, 'c_i' => 'click'), $requests[0]->getParams());
|
|
}
|
|
|
|
private function buildNewRequestSetThatIsNotInitializedYet()
|
|
{
|
|
return new TestRequestSet();
|
|
}
|
|
}
|