File size: 5,319 Bytes
968114b | 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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | <?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\AnonymousPiwikUsageMeasurement\tests\System;
use Piwik\DataTable;
use Piwik\Piwik;
use Piwik\Plugins\AnonymousPiwikUsageMeasurement\tests\Fixtures\SendSystemReportTaskFixture;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
use Piwik\Version;
/**
* @group AnonymousPiwikUsageMeasurement
* @group TasksTest
* @group Plugins
*/
class TasksTest extends SystemTestCase
{
/**
* @var SendSystemReportTaskFixture
*/
public static $fixture = null; // initialized below class definition
public function setUp(): void
{
parent::setUp();
$self = $this;
Piwik::addAction('API.Request.dispatch.end', function (&$return, $extra) use ($self) {
if ($extra['module'] !== 'Events') {
return;
}
/** @var DataTable $return*/
// we make sure processed result is the same at any time
foreach ($return as &$value) {
$value->setColumn('sum_event_value', '2');
$value->setColumn('max_event_value', '2');
$value->setColumn('min_event_value', '2');
$value->setColumn('sum_daily_nb_uniq_visitors', '2');
$value->setColumn('avg_event_value', '2');
if ($value->isSubtableLoaded()) {
$subtable = $value->getSubtable();
foreach ($subtable->getRows() as $row) {
$row->setColumn('sum_event_value', '2');
$row->setColumn('max_event_value', '2');
$row->setColumn('min_event_value', '2');
$row->setColumn('sum_daily_nb_uniq_visitors', '2');
$row->setColumn('avg_event_value', '2');
}
}
}
});
}
/**
* @dataProvider getApiForTesting
*/
public function testApi($api, $params)
{
$this->runApiTests($api, $params);
}
public function getApiForTesting()
{
$apis = [
'API.get',
'Actions.getPageUrls',
'Actions.getPageTitles',
'Events',
'Referrers.getReferrerType',
'CustomVariables',
];
$xmlFieldsToRemove = [];
if (version_compare(Version::VERSION, '5.5.0-b1', '<')) {
$xmlFieldsToRemove = ['Referrers_visitorsFromAIAssistants', 'Referrers_distinctAIAssistants', 'Referrers_visitorsFromAIAssistants_percent'];
}
if (version_compare(Version::VERSION, '5.6.0-alpha', '<')) {
// In Matomo 5.6 AI agent information had been added
$xmlFieldsToRemove = array_merge($xmlFieldsToRemove, [
'nb_visits_ai_agent',
'nb_actions_ai_agent',
'nb_uniq_visitors_ai_agent',
'nb_users_ai_agent',
'max_actions_ai_agent',
'bounce_rate_ai_agent',
'nb_actions_per_visit_ai_agent',
'avg_time_on_site_ai_agent',
'nb_visits_human',
'nb_actions_human',
'nb_uniq_visitors_human',
'nb_users_human',
'max_actions_human',
'bounce_rate_human',
'nb_actions_per_visit_human',
'avg_time_on_site_human',
]);
}
if (version_compare(Version::VERSION, '5.7.0-b1', '<')) {
$xmlFieldsToRemove = array_merge($xmlFieldsToRemove, [
'BotTracking_AIChatbotsRequests',
'BotTracking_AIChatbotsAcquiredVisits',
'BotTracking_AIChatbotsNotFoundRequests',
'BotTracking_AIChatbotsUniqueChatbots',
'BotTracking_AIChatbotsServerErrorRequests',
'BotTracking_AIChatbotsClickThroughRate',
]);
}
$apiToTest = [];
foreach ($apis as $api) {
$apiToTest[] = [
$api,
[
'idSite' => 1,
'date' => 'today',
'periods' => ['year'],
'otherRequestParameters' => [
'hideColumns' => 'hits,sum_visit_length,entry_sum_visit_length,avg_time_on_site_new,sum_bandwidth,nb_hits_with_bandwidth,min_bandwidth,max_bandwidth,avg_bandwidth,nb_total_overall_bandwidth,nb_total_pageview_bandwidth,nb_total_download_bandwidth',
],
// when calling CustomVariables.getUsagesOfSlots, new archives are created until 'today',
// which increments idsubdatatable, but we need to have deterministic idsubdatatable
'apiNotToCall' => ['CustomVariables.getUsagesOfSlots'],
'xmlFieldsToRemove' => $xmlFieldsToRemove,
]
];
}
return $apiToTest;
}
public static function getOutputPrefix()
{
return '';
}
public static function getPathToTestDirectory()
{
return dirname(__FILE__);
}
}
TasksTest::$fixture = new SendSystemReportTaskFixture();
|