File size: 12,423 Bytes
bf8c0ce | 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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | <?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\System;
use Piwik\Common;
use Piwik\Db;
use Piwik\Plugin\Manager;
use Piwik\Plugins\VisitFrequency\API as VisitFrequencyApi;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
use Piwik\Tests\Fixtures\SqlDump;
use Piwik\Tests\Framework\Fixture;
/**
* Tests that Piwik 2.0 works w/ data from Piwik 1.12.
*
* @group BackwardsCompatibility1XTest
* @group Core
*/
class BackwardsCompatibility1XTest extends SystemTestCase
{
public const FIXTURE_LOCATION = '/tests/resources/piwik-1.13-dump.sql';
/** @var SqlDump $fixture */
public static $fixture = null; // initialized below class
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
$installedPlugins = Manager::getInstance()->getInstalledPluginsName();
// ensure all plugins are installed correctly (some plugins database tables would be missing otherwise)
foreach ($installedPlugins as $installedPlugin) {
\Piwik\Plugin\Manager::getInstance()->loadPlugin($installedPlugin)->install();
}
$result = Fixture::updateDatabase();
if ($result === false) {
throw new \Exception("Failed to update pre-2.0 database (nothing to update).");
}
// truncate log tables so old data won't be re-archived
foreach (['log_visit', 'log_link_visit_action', 'log_conversion', 'log_conversion_item'] as $table) {
Db::query("TRUNCATE TABLE " . Common::prefixTable($table));
}
self::trackTwoVisitsOnSameDay();
// launch archiving
VisitFrequencyApi::getInstance()->get(1, 'year', '2012-12-29');
}
/**
* add two visits from same visitor on dec. 29
*/
private static function trackTwoVisitsOnSameDay()
{
$t = Fixture::getTracker(1, '2012-12-29 01:01:30', $defaultInit = true, $useLocal = true);
$t->enableBulkTracking();
$t->setUrl('http://site.com/index.htm');
$t->setIp('136.5.3.2');
$t->doTrackPageView('incredible title!');
$t->setForceVisitDateTime('2012-12-29 03:01:30');
$t->setUrl('http://site.com/other/index.htm');
$t->doTrackPageView('other incredible title!');
$t->doBulkTrack();
}
/**
* @dataProvider getApiForTesting
*/
public function testApi($api, $params)
{
// note: not sure why I have to manually activate plugin in order for `./console tests:run BackwardsCompatibility1XTest` to work
try {
\Piwik\Plugin\Manager::getInstance()->activatePlugin('DevicesDetection');
} catch (\Exception $e) {
}
$this->runApiTests($api, $params);
}
public function getApiForTesting()
{
$idSite = 1;
$dateTime = '2012-03-06 11:22:33';
// page performance metrics added in Matomo 4
$performanceMetrics = [
'sum_time_generation',
'nb_hits_with_time_generation',
'min_time_generation',
'max_time_generation',
'sum_time_network',
'nb_hits_with_time_network',
'min_time_network',
'max_time_network',
'sum_time_server',
'nb_hits_with_time_server',
'min_time_server',
'max_time_server',
'sum_time_transfer',
'nb_hits_with_time_transfer',
'min_time_transfer',
'max_time_transfer',
'sum_time_dom_processing',
'nb_hits_with_time_dom_processing',
'min_time_dom_processing',
'max_time_dom_processing',
'sum_time_dom_completion',
'nb_hits_with_time_dom_completion',
'min_time_dom_completion',
'max_time_dom_completion',
'sum_time_on_load',
'nb_hits_with_time_on_load',
'min_time_on_load',
'max_time_on_load',
'avg_time_generation',
'avg_time_network',
'avg_time_server',
'avg_time_transfer',
'avg_time_dom_processing',
'avg_time_dom_completion',
'avg_time_on_load',
'avg_page_load_time',
];
$defaultOptions = [
'idSite' => $idSite,
'date' => $dateTime,
'disableArchiving' => true,
'otherRequestParameters' => [
// when changing this, might also need to change the same line in OneVisitorTwoVisitsTest.php
'hideColumns' => 'nb_users,sum_bandwidth,nb_hits_with_bandwidth,min_bandwidth,max_bandwidth',
],
'xmlFieldsToRemove' => array_merge([
'entry_sum_visit_length',
'sum_visit_length',
'nb_visits_converted',
'interactionPosition',
'pageviewPosition',
], $performanceMetrics),
];
/**
* When Piwik\Tests\System\BackwardsCompatibility1XTest is failing,
* as this test compares fixtures to OneVisitorTwoVisits* fixtures,
* sometimes for a given API method that fails to generate the same output as OneVisitorTwoVisits does,
* we need to add the API below which will cause the fixtures for this API to be created in processed/
*/
$reportsToCompareSeparately = [
// those reports generate a different segment as a different raw value was stored that time
'DevicesDetection.getOsVersions',
'DevicesDetection.getBrowserVersions',
'DevicesDetection.getBrowserEngines',
'DevicesDetection.getBrowsers',
'Goals.get',
// Following #9345
'Actions.getPageUrls',
'Actions.getDownloads',
'Actions.getDownload',
'Actions.getEntryPageUrls',
'Actions.getExitPageUrls',
'Actions.getPageTitle',
// new flag dimensions
'UserCountry.getCountry',
'Tour.getLevel',
'Tour.getChallenges',
];
$apiNotToCall = [
// in the SQL dump, a referrer is named referer.com, but now in OneVisitorTwoVisits it is referrer.com
'Referrers',
// changes made to SQL dump to test VisitFrequency change the day of week
'VisitTime.getByDayOfWeek',
// did not exist in Piwik 1.X
'DevicesDetection.getBrowserEngines',
// now enriched with goal metrics
'DevicesDetection.getType',
'DevicesDetection.getBrand',
'DevicesDetection.getModel',
// different result as some plugins have been removed in Matomo 4
'DevicePlugins.getPlugin',
// has different output before and after
'PrivacyManager.getAvailableVisitColumnsToAnonymize',
// we test VisitFrequency explicitly
'VisitFrequency.get',
// do not test as label formats have changed
'VisitTime.getVisitInformationPerLocalTime',
'VisitTime.getVisitInformationPerServerTime',
// the Actions.getPageTitles test fails for unknown reason, so skipping it
// @todo check if that still the case
'Actions.getPageTitles',
'Actions.getEntryPageTitles', // segment values can differ due to missing metadata in old reports
'Actions.getExitPageTitles',
// Outlinks now tracked with URL Fragment which was not the case in 1.X
'Actions.get',
'Actions.getOutlink',
'Actions.getOutlinks',
// system settings such as enable_plugin_update_communication are enabled by default in newest version,
// but ugpraded Piwik are not
'CorePluginsAdmin.getSystemSettings',
// visit length changes slightly with change to previous visitor detection in #13935
'VisitsSummary.getSumVisitsLength',
'VisitsSummary.getSumVisitsLengthPretty',
// did not exist before Matomo 4
'PagePerformance.get',
// Did not exist before Matomo 4.11.
'MultiSites.getAllWithGroups',
// compare separately, as changes in columns
'MultiSites.getAll',
'MultiSites.getOne',
// did not exist before Matomo 5.6
'AIAgents.get',
];
if (!Manager::getInstance()->isPluginActivated('CustomVariables')) {
// includes some columns that are not available when CustomVariables plugin is not available
$apiNotToCall[] = 'PrivacyManager.getAvailableLinkVisitActionColumnsToAnonymize';
}
$apiNotToCall = array_merge($apiNotToCall, $reportsToCompareSeparately);
$allReportsOptions = $defaultOptions;
$allReportsOptions['compareAgainst'] = 'OneVisitorTwoVisits';
$allReportsOptions['apiNotToCall'] = $apiNotToCall;
return [
['all', $allReportsOptions],
['MultiSites.getAll', array_merge($defaultOptions, ['xmlFieldsToRemove' => ['hits', 'hits_evolution', 'hits_evolution_trend']])],
['MultiSites.getOne', array_merge($allReportsOptions, ['apiNotToCall' => '', 'xmlFieldsToRemove' => ['hits', 'hits_evolution', 'hits_evolution_trend']])],
['VisitFrequency.get', ['idSite' => $idSite, 'date' => '2012-03-03', 'setDateLastN' => true,
'disableArchiving' => true, 'testSuffix' => '_multipleDates']],
['VisitFrequency.get', ['idSite' => $idSite, 'date' => $dateTime,
'periods' => ['day', 'week', 'month', 'year'],
'disableArchiving' => false]],
['VisitFrequency.get', ['idSite' => $idSite, 'date' => '2012-03-06,2012-12-31',
'periods' => ['range'], 'disableArchiving' => true]],
['Actions.getPageUrls', ['idSite' => $idSite, 'date' => '2012-03-06,2012-12-31',
'otherRequestParameters' => ['expanded' => '1'],
'xmlFieldsToRemove' => $performanceMetrics,
'testSuffix' => '_expanded',
'periods' => ['range'], 'disableArchiving' => true]],
['Actions.getPageUrls', ['idSite' => $idSite, 'date' => '2012-03-06,2012-12-31',
'otherRequestParameters' => ['flat' => '1'],
'xmlFieldsToRemove' => $performanceMetrics,
'testSuffix' => '_flat',
'periods' => ['range'], 'disableArchiving' => true]],
['Actions.getPageUrls', ['idSite' => $idSite, 'date' => '2012-03-06',
'otherRequestParameters' => ['idSubtable' => '30'],
'xmlFieldsToRemove' => $performanceMetrics,
'testSuffix' => '_subtable',
'periods' => ['day'], 'disableArchiving' => true]],
['VisitFrequency.get', ['idSite' => $idSite, 'date' => '2012-03-03,2012-12-12', 'periods' => ['month'],
'testSuffix' => '_multipleOldNew', 'disableArchiving' => true]],
[$reportsToCompareSeparately, $defaultOptions],
];
}
public function provideContainerConfig()
{
return [
'Piwik\Config' => \Piwik\DI::decorate(function ($previous) {
$general = $previous->General;
$general['action_title_category_delimiter'] = "/";
$previous->General = $general;
return $previous;
}),
];
}
}
BackwardsCompatibility1XTest::$fixture = new SqlDump();
BackwardsCompatibility1XTest::$fixture->dumpUrl = PIWIK_INCLUDE_PATH . BackwardsCompatibility1XTest::FIXTURE_LOCATION;
BackwardsCompatibility1XTest::$fixture->tablesPrefix = '';
|