public static function setUpBeforeClass() { parent::setUpBeforeClass(); // Temporarily disable the purge of old archives so that getNumeric('nb_visits') // in _addReportData does not trigger the data purge of data we've just imported \Piwik\ArchiveProcessor\Rules::disablePurgeOutdatedArchives(); self::_addLogData(); self::_addReportData(); \Piwik\ArchiveProcessor\Rules::enablePurgeOutdatedArchives(); self::$dbData = self::getDbTablesWithData(); }
/** * Runs API tests. */ protected function runApiTests($api, $params) { $testConfig = new ApiTestConfig($params); // make sure that the reports we process here are not directly deleted in ArchiveProcessor/PluginsArchiver // (because we process reports in the past, they would sometimes be invalid, and would have been deleted) \Piwik\ArchiveProcessor\Rules::disablePurgeOutdatedArchives(); $testName = 'test_' . static::getOutputPrefix(); $this->missingExpectedFiles = array(); $this->comparisonFailures = array(); if ($testConfig->disableArchiving) { Rules::$archivingDisabledByTests = true; Config::getInstance()->General['browser_archiving_disabled_enforce'] = 1; } else { Rules::$archivingDisabledByTests = false; Config::getInstance()->General['browser_archiving_disabled_enforce'] = 0; } if ($testConfig->language) { $this->changeLanguage($testConfig->language); } $testRequests = new TestRequestCollection($api, $testConfig, $api); foreach ($testRequests->getRequestUrls() as $apiId => $requestUrl) { $this->_testApiUrl($testName . $testConfig->testSuffix, $apiId, $requestUrl, $testConfig->compareAgainst, $testConfig->xmlFieldsToRemove, $params); } // Restore normal purge behavior \Piwik\ArchiveProcessor\Rules::enablePurgeOutdatedArchives(); // change the language back to en if ($this->lastLanguage != 'en') { $this->changeLanguage('en'); } if (!empty($this->missingExpectedFiles)) { $expectedDir = dirname(reset($this->missingExpectedFiles)); $this->fail(" ERROR: Could not find expected API output '" . implode("', '", $this->missingExpectedFiles) . "'. For new tests, to pass the test, you can copy files from the processed/ directory into" . " {$expectedDir} after checking that the output is valid. %s "); } // Display as one error all sub-failures if (!empty($this->comparisonFailures)) { $this->printComparisonFailures(); throw reset($this->comparisonFailures); } return count($this->comparisonFailures) == 0; }
<?php // Good old test proxy endpoints have some commons if (!defined('PIWIK_INCLUDE_PATH')) { define('PIWIK_INCLUDE_PATH', realpath(dirname(__FILE__)) . '/../../../'); } if (!defined('PIWIK_USER_PATH')) { define('PIWIK_USER_PATH', PIWIK_INCLUDE_PATH); } require_once file_exists(PIWIK_INCLUDE_PATH . '/vendor/autoload.php') ? PIWIK_INCLUDE_PATH . '/vendor/autoload.php' : PIWIK_INCLUDE_PATH . '/../../autoload.php'; // Piwik is installed as a dependency require_once PIWIK_INCLUDE_PATH . '/core/EventDispatcher.php'; require_once PIWIK_INCLUDE_PATH . '/core/Piwik.php'; require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/TestingEnvironment.php'; if (file_exists(PIWIK_INCLUDE_PATH . '/vendor/autoload.php')) { $vendorDirectory = PIWIK_INCLUDE_PATH . '/vendor'; } else { $vendorDirectory = PIWIK_INCLUDE_PATH . '/../..'; } require_once $vendorDirectory . '/autoload.php'; require_once $vendorDirectory . '/mustangostang/spyc/Spyc.php'; require_once $vendorDirectory . '/piwik/device-detector/DeviceDetector.php'; \Piwik\SettingsServer::setMaxExecutionTime(0); // Make sure Data processed in cron core:archive command is not being purged instantly (useful for: Integration/ArchiveCronTest) if (\Piwik\SettingsServer::isArchivePhpTriggered()) { \Piwik\ArchiveProcessor\Rules::disablePurgeOutdatedArchives(); }