1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
<?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\PagePerformance\tests\Integration\Tracker;
use Piwik\Common;
use Piwik\Date;
use Piwik\Db;
use Piwik\Plugins\PagePerformance\Tracker\PerformanceDataProcessor;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
/**
* @group PagePerformance
* @group Plugins
*/
class PerformanceDataProcessorTest extends IntegrationTestCase
{
/**
* @var PerformanceDataProcessor
*/
private $requestProcessor;
public function setUp(): void
{
parent::setUp();
$this->requestProcessor = new PerformanceDataProcessor();
Fixture::createWebsite('2014-01-01 02:03:04');
}
public function testShouldUpdatePerformanceTimingsInOngoingEventRequest()
{
$tracker = Fixture::getTracker(1, Date::now()->toString('Y-m-d H:i:s'));
$tracker->setUrl('http://example.org/test');
Fixture::checkResponse($tracker->doTrackPageView('My Page'));
$idPageView = $tracker->idPageview;
$this->checkActionHasTimings($idPageView);
$tracker->setPerformanceTimings(12, 77, 412, 1055, 333, 66);
Fixture::checkResponse($tracker->doTrackEvent('cat', 'act'));
$this->checkActionHasTimings($idPageView, 12, 77, 412, 1055, 333, 66);
}
public function testShouldUpdatePerformanceTimingsInOngoingPingRequest()
{
$tracker = Fixture::getTracker(1, Date::now()->toString('Y-m-d H:i:s'));
$tracker->setUrl('http://example.org/test');
Fixture::checkResponse($tracker->doTrackPageView('My Page'));
$idPageView = $tracker->idPageview;
$this->checkActionHasTimings($idPageView);
$tracker->setPerformanceTimings(5, 66, 445, 1025, 12, 111);
Fixture::checkResponse($tracker->doPing());
$this->checkActionHasTimings($idPageView, 5, 66, 445, 1025, 12, 111);
}
public function testShouldNotUpdatePerformanceTimingsInOngoingPageViewRequest()
{
$tracker = Fixture::getTracker(1, Date::now()->toString('Y-m-d H:i:s'));
$tracker->setUrl('http://example.org/test');
Fixture::checkResponse($tracker->doTrackPageView('My Page'));
$idPageView = $tracker->idPageview;
$this->checkActionHasTimings($idPageView);
$tracker->setPerformanceTimings(0, 66, 445, 1025, 12, 111);
$tracker->setUrl('http://example.org/test2');
Fixture::checkResponse($tracker->doTrackPageView('Another Page'));
$this->checkActionHasTimings($idPageView);
$this->checkActionHasTimings($tracker->idPageview, 0, 66, 445, 1025, 12, 111);
}
public function testShouldNotUseObviouslyTooHighNumbers()
{
$tracker = Fixture::getTracker(1, Date::now()->toString('Y-m-d H:i:s'));
$tracker->setUrl('http://example.org/test');
Fixture::checkResponse($tracker->doTrackPageView('My Page'));
$idPageView = $tracker->idPageview;
$this->checkActionHasTimings($idPageView);
$tracker->setPerformanceTimings(6525265942, 6525265942, 6525265942, 6525265942, 6525265942, 111);
$tracker->setUrl('http://example.org/test2');
Fixture::checkResponse($tracker->doTrackPageView('Another Page'));
$this->checkActionHasTimings($idPageView);
$this->checkActionHasTimings($tracker->idPageview, null, null, null, null, null, 111);
}
protected function checkActionHasTimings($pageViewId, $network = null, $server = null, $transfer = null, $domProcessing = null, $domCompletion = null, $onload = null)
{
$result = Db::fetchRow(
sprintf(
'SELECT time_network, time_server, time_transfer, time_dom_processing, time_dom_completion, time_on_load
FROM %1$s LEFT JOIN %2$s ON idaction_url = idaction WHERE idpageview = ? AND %2$s.type = 1',
Common::prefixTable('log_link_visit_action'),
Common::prefixTable('log_action')
),
$pageViewId
);
$this->assertEquals([
'time_network' => $network,
'time_server' => $server,
'time_transfer' => $transfer,
'time_dom_processing' => $domProcessing,
'time_dom_completion' => $domCompletion,
'time_on_load' => $onload,
], $result);
}
}
|