diff options
author | Matthieu Napoli <matthieu@mnapoli.fr> | 2014-12-19 00:13:27 +0300 |
---|---|---|
committer | Matthieu Napoli <matthieu@mnapoli.fr> | 2014-12-19 00:13:27 +0300 |
commit | 1fc84146b16f178f95f7b95b089426f9c84744d9 (patch) | |
tree | e90e0c099f387671e0ad12ef4c2160835abaeb1a | |
parent | 6590128885af88b5bbfe9c0a856a224006f8e7e3 (diff) | |
parent | 484cd7a3079f0165728b4391d1bbdd2d478e6bf0 (diff) |
Merge branch 'master' into log-refactoring-1
Conflicts:
CHANGELOG.md
plugins/CoreConsole/Commands/CoreArchiver.php
39 files changed, 298 insertions, 127 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 001aadcabb..c33f0d8a27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,8 @@ This is a changelog for Piwik platform developers. All changes for our HTTP API' ## Piwik 2.10.0 ### Breaking Changes -* Some duplicate reports from UserSettings plugin have been removed. Widget URLs for those reports will still work till May 1st 2015. Please update those to the new reports of DevicesDetection plugin. -* os and browser icons are now located in the DevicesDetection plugin. If you are not using the Reporting or Metadata API to get the icon locations please update your paths. * API responses containing visitor information will now longer contain the fields `screenType` and `screenTypeIcon` as those reports have been completely removed +* os and browser icons are now located in the DevicesDetection plugin. If you are not using the Reporting or Metadata API to get the icon locations please update your paths. * The following events have been removed: * `Log.formatFileMessage` * `Log.formatDatabaseMessage` @@ -17,6 +16,7 @@ This is a changelog for Piwik platform developers. All changes for our HTTP API' * The INI options `log_only_when_cli` and `log_only_when_debug_parameter` have been removed ### Deprecations +* Some duplicate reports from UserSettings plugin have been removed. Widget URLs for those reports will still work till May 1st 2015. Please update those to the new reports of DevicesDetection plugin. * The API method `UserSettings.getBrowserVersion` is deprecated and will be removed from May 1st 2015. Use `DevicesDetection.getBrowserVersions` instead * The API method `UserSettings.getBrowser` is deprecated and will be removed from May 1st 2015. Use `DevicesDetection.getBrowsers` instead * The API method `UserSettings.getOSFamily` is deprecated and will be removed from May 1st 2015. Use `DevicesDetection.getOsFamilies` instead diff --git a/composer.lock b/composer.lock index 7cc262d96d..7aaa6ff135 100644 --- a/composer.lock +++ b/composer.lock @@ -506,16 +506,16 @@ }, { "name": "piwik/cache", - "version": "0.2.1", + "version": "0.2.2", "source": { "type": "git", "url": "https://github.com/piwik/component-cache.git", - "reference": "1cbe0012f703b5462e87520ebcf76bdca89026e8" + "reference": "e6205408641cbf16b5043e0092e4414e3a4330ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/piwik/component-cache/zipball/1cbe0012f703b5462e87520ebcf76bdca89026e8", - "reference": "1cbe0012f703b5462e87520ebcf76bdca89026e8", + "url": "https://api.github.com/repos/piwik/component-cache/zipball/e6205408641cbf16b5043e0092e4414e3a4330ff", + "reference": "e6205408641cbf16b5043e0092e4414e3a4330ff", "shasum": "" }, "require": { @@ -549,7 +549,7 @@ "file", "redis" ], - "time": "2014-12-16 01:47:11" + "time": "2014-12-17 22:49:09" }, { "name": "piwik/decompress", diff --git a/config/global.ini.php b/config/global.ini.php index cf4ae8c1b1..5f6626ee63 100644 --- a/config/global.ini.php +++ b/config/global.ini.php @@ -638,7 +638,7 @@ bulk_requests_use_transaction = 1 ; Comma separated list of known Referrer Spammers, ie. bot visits that set a fake Referrer field. ; All Visits with a Referrer URL host set to one of these will be excluded. ; If you find new spam entries in Referrers>Websites, please report them here: https://github.com/piwik/piwik/issues/5099 -referrer_urls_spam = "semalt.com,buttons-for-website.com" +referrer_urls_spam = "semalt.com,buttons-for-website.com,7makemoneyonline.com" ; DO NOT USE THIS SETTING ON PUBLICLY AVAILABLE PIWIK SERVER ; !!! Security risk: if set to 0, it would allow anyone to push data to Piwik with custom dates in the past/future and even with fake IPs! diff --git a/core/API/Request.php b/core/API/Request.php index 23677e45fb..2d97ba6f41 100644 --- a/core/API/Request.php +++ b/core/API/Request.php @@ -135,6 +135,7 @@ class Request { $this->request = self::getRequestArrayFromString($request, $defaultRequest); $this->sanitizeRequest(); + $this->renameModuleAndActionInRequest(); } /** @@ -142,19 +143,23 @@ class Request * we rewrite to correct renamed plugin: Referrers * * @param $module - * @return string + * @param $action + * @return array( $module, $action ) * @ignore */ - public static function renameModule($module) + public static function getRenamedModuleAndAction($module, $action) { - $moduleToRedirect = array( - 'Referers' => 'Referrers', - 'PDFReports' => 'ScheduledReports', - ); - if (isset($moduleToRedirect[$module])) { - return $moduleToRedirect[$module]; - } - return $module; + /** + * This event is posted in the Request dispatcher and can be used + * to overwrite the Module and Action to dispatch. + * This is useful when some Controller methods or API methods have been renamed or moved to another plugin. + * + * @param $module string + * @param $action string + */ + Piwik::postEvent('Request.getRenamedModuleAndAction', array(&$module, &$action)); + + return array($module, $action); } /** @@ -213,7 +218,7 @@ class Request list($module, $method) = $this->extractModuleAndMethod($moduleMethod); - $module = $this->renameModule($module); + list($module, $method) = $this->getRenamedModuleAndAction($module, $method); if (!\Piwik\Plugin\Manager::getInstance()->isPluginActivated($module)) { throw new PluginDeactivatedException($module); @@ -412,4 +417,15 @@ class Request } return $segmentRaw; } + + private function renameModuleAndActionInRequest() + { + if (empty($this->request['apiModule'])) { + return; + } + if (empty($this->request['apiAction'])) { + $this->request['apiAction'] = null; + } + list($this->request['apiModule'], $this->request['apiAction']) = $this->getRenamedModuleAndAction($this->request['apiModule'], $this->request['apiAction']); + } } diff --git a/core/DataAccess/ArchiveInvalidator.php b/core/DataAccess/ArchiveInvalidator.php index 6648c637c8..2d1a87daf1 100644 --- a/core/DataAccess/ArchiveInvalidator.php +++ b/core/DataAccess/ArchiveInvalidator.php @@ -136,13 +136,13 @@ class ArchiveInvalidator { { // If using the feature "Delete logs older than N days"... $purgeDataSettings = PrivacyManager::getPurgeDataSettings(); - $logsAreDeletedBeforeThisDate = $purgeDataSettings['delete_logs_schedule_lowest_interval']; + $logsDeletedWhenOlderThanDays = $purgeDataSettings['delete_logs_older_than']; $logsDeleteEnabled = $purgeDataSettings['delete_logs_enable']; if ($logsDeleteEnabled - && $logsAreDeletedBeforeThisDate + && $logsDeletedWhenOlderThanDays ) { - $this->minimumDateWithLogs = Date::factory('today')->subDay($logsAreDeletedBeforeThisDate); + $this->minimumDateWithLogs = Date::factory('today')->subDay($logsDeletedWhenOlderThanDays); } } diff --git a/core/FrontController.php b/core/FrontController.php index bff9acf6ca..90b9db2fa5 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -479,7 +479,7 @@ class FrontController extends Singleton throw new Exception("Invalid module name '$module'"); } - $module = Request::renameModule($module); + list($module, $action) = Request::getRenamedModuleAndAction($module, $action); if (!\Piwik\Plugin\Manager::getInstance()->isPluginActivated($module)) { throw new PluginDeactivatedException($module); diff --git a/misc/log-analytics/import_logs.py b/misc/log-analytics/import_logs.py index a2cf7a5c1d..315b2ac1a1 100755 --- a/misc/log-analytics/import_logs.py +++ b/misc/log-analytics/import_logs.py @@ -1751,6 +1751,9 @@ class Parser(object): try: hit.referrer = format.get('referrer') + + if hit.referrer.startswith('"'): + hit.referrer = hit.referrer[1:-1] except BaseFormatException: hit.referrer = '' if hit.referrer == '-': @@ -1789,6 +1792,9 @@ class Parser(object): else: try: hit.host = format.get('host').lower().strip('.') + + if hit.host.startswith('"'): + hit.host = hit.host[1:-1] except BaseFormatException: # Some formats have no host. pass diff --git a/plugins/API/RowEvolution.php b/plugins/API/RowEvolution.php index a326b5022f..6e31a13317 100644 --- a/plugins/API/RowEvolution.php +++ b/plugins/API/RowEvolution.php @@ -280,9 +280,7 @@ class RowEvolution // note: some reports should not be filtered with AddColumnProcessedMetrics // specifically, reports without the Metrics::INDEX_NB_VISITS metric such as Goals.getVisitsUntilConversion & Goal.getDaysToConversion // this is because the AddColumnProcessedMetrics filter removes all datable rows lacking this metric - if (isset($metadata['metrics']['nb_visits']) - && !empty($label) - ) { + if (isset($metadata['metrics']['nb_visits'])) { $parameters['filter_add_columns_when_show_all_columns'] = '0'; } diff --git a/plugins/CoreAdminHome/API.php b/plugins/CoreAdminHome/API.php index 00e2095771..aa34473284 100644 --- a/plugins/CoreAdminHome/API.php +++ b/plugins/CoreAdminHome/API.php @@ -47,7 +47,7 @@ class API extends \Piwik\Plugin\API * * @param string $idSites Comma separated list of idSite that have had data imported for the specified dates * @param string $dates Comma separated list of dates to invalidate for all these websites - * @param string $period If specified (one of day, week, month, year, range) it will only delete archives for this period. + * @param string $period If specified (one of day, week, month, year, range) it will only invalidates archives for this period. * Note: because week, month, year, range reports aggregate day reports then you need to specifically invalidate day reports to see * other periods reports processed.. * @throws Exception diff --git a/plugins/CoreConsole/Commands/CoreArchiver.php b/plugins/CoreConsole/Commands/CoreArchiver.php index 39167e8870..ec151bf0ef 100644 --- a/plugins/CoreConsole/Commands/CoreArchiver.php +++ b/plugins/CoreConsole/Commands/CoreArchiver.php @@ -35,7 +35,7 @@ class CoreArchiver extends ConsoleCommand throw new \InvalidArgumentException('No valid URL given. If you have specified a valid URL try --piwik-domain instead of --url'); } - $archiver = $this->makeArchiver($url, $input); + $archiver = self::makeArchiver($url, $input); try { $archiver->main(); diff --git a/plugins/CoreHome/DataTableRowAction/RowEvolution.php b/plugins/CoreHome/DataTableRowAction/RowEvolution.php index c86b83b2d0..978b6755ca 100644 --- a/plugins/CoreHome/DataTableRowAction/RowEvolution.php +++ b/plugins/CoreHome/DataTableRowAction/RowEvolution.php @@ -230,14 +230,6 @@ class RowEvolution list($first, $last) = $this->getFirstAndLastDataPointsForMetric($metric); $details = Piwik::translate('RowEvolution_MetricBetweenText', array($first, $last)); - // TODO: this check should be determined by metric metadata, not hardcoded here - if ($metric == 'nb_users' - && $first == 0 - && $last == 0 - ) { - continue; - } - if ($change !== false) { $lowerIsBetter = Metrics::isLowerValueBetter($metric); if (substr($change, 0, 1) == '+') { @@ -275,6 +267,15 @@ class RowEvolution if (!empty($metricData['logo'])) { $newMetric['logo'] = $metricData['logo']; } + + // TODO: this check should be determined by metric metadata, not hardcoded here + if ($metric == 'nb_users' + && $first == 0 + && $last == 0 + ) { + $newMetric['hide'] = true; + } + $metrics[] = $newMetric; $i++; } diff --git a/plugins/CoreHome/templates/getMultiRowEvolutionPopover.twig b/plugins/CoreHome/templates/getMultiRowEvolutionPopover.twig index 0b1bd24eda..a43d282492 100644 --- a/plugins/CoreHome/templates/getMultiRowEvolutionPopover.twig +++ b/plugins/CoreHome/templates/getMultiRowEvolutionPopover.twig @@ -8,7 +8,7 @@ <h2>{{ availableRecordsText|translate }}</h2> <table class="metrics" border="0" cellpadding="0" cellspacing="0"> {% for i, metric in metrics %} - <tr> + <tr {% if metric.hide|default %}style="display:none"{% endif %}> <td class="sparkline"> {{ metric.sparkline|raw }} </td> diff --git a/plugins/CoreHome/templates/getRowEvolutionPopover.twig b/plugins/CoreHome/templates/getRowEvolutionPopover.twig index a99e95dd5b..5a86f7a101 100644 --- a/plugins/CoreHome/templates/getRowEvolutionPopover.twig +++ b/plugins/CoreHome/templates/getRowEvolutionPopover.twig @@ -12,7 +12,7 @@ </div> <table class="metrics" border="0" cellpadding="0" cellspacing="0" data-thing="{{ seriesColorCount }}"> {% for i, metric in metrics %} - <tr data-i="{{ i }}"> + <tr data-i="{{ i }}" {% if metric.hide|default %}style="display:none"{% endif %}> <td class="sparkline"> {{ metric.sparkline|raw }} </td> diff --git a/plugins/CorePluginsAdmin/Controller.php b/plugins/CorePluginsAdmin/Controller.php index 0a7a497d46..71d95730b9 100644 --- a/plugins/CorePluginsAdmin/Controller.php +++ b/plugins/CorePluginsAdmin/Controller.php @@ -283,7 +283,8 @@ class Controller extends Plugin\ControllerAdmin $suffix = Piwik::translate('CorePluginsAdmin_PluginNotWorkingAlternative'); // If the plugin has been renamed, we do not show message to ask user to update plugin - if ($pluginName != Request::renameModule($pluginName)) { + list($pluginNameRenamed, $methodName) = Request::getRenamedModuleAndAction($pluginName, 'index'); + if ($pluginName != $pluginNameRenamed) { $suffix = "You may uninstall the plugin or manually delete the files in piwik/plugins/$pluginName/"; } diff --git a/plugins/ImageGraph/API.php b/plugins/ImageGraph/API.php index 779d412031..b569f2c9c8 100644 --- a/plugins/ImageGraph/API.php +++ b/plugins/ImageGraph/API.php @@ -9,12 +9,12 @@ namespace Piwik\Plugins\ImageGraph; use Exception; +use Piwik\API\Request; use Piwik\Archive\DataTableFactory; use Piwik\Common; use Piwik\Filesystem; use Piwik\Period; use Piwik\Piwik; -use Piwik\Plugins\API\API as APIMetadata; use Piwik\Plugins\ImageGraph\StaticGraph; use Piwik\SettingsServer; use Piwik\Translate; @@ -156,9 +156,19 @@ class API extends \Piwik\Plugin\API $apiParameters = array('idGoal' => $idGoal); } // Fetch the metadata for given api-action - $metadata = APIMetadata::getInstance()->getMetadata( - $idSite, $apiModule, $apiAction, $apiParameters, $languageLoaded, $period, $date, - $hideMetricsDoc = false, $showSubtableReports = true); + $parameters = array( + 'idSite' => $idSite, + 'apiModule' => $apiModule, + 'apiAction' => $apiAction, + 'apiParameters' => $apiParameters, + 'language' => $languageLoaded, + 'period' => $period, + 'date' => $date, + 'hideMetricsDoc' => false, + 'showSubtableReports' => true + ); + + $metadata = Request::processRequest('API.getMetadata', $parameters); if (!$metadata) { throw new Exception('Invalid API Module and/or API Action'); } @@ -288,20 +298,21 @@ class API extends \Piwik\Plugin\API } } - $processedReport = APIMetadata::getInstance()->getRowEvolution( - $idSite, - $period, - $date, - $apiModule, - $apiAction, - $labels, - $segment, - $plottedMetric, - $languageLoaded, - $idGoal, - $legendAppendMetric, - $labelUseAbsoluteUrl = false + $parameters = array( + 'idSite' => $idSite, + 'period' => $period, + 'date' => $date, + 'apiModule' => $apiModule, + 'apiAction' => $apiAction, + 'label' => $labels, + 'segment' => $segment, + 'column' => $plottedMetric, + 'language' => $languageLoaded, + 'idGoal' => $idGoal, + 'legendAppendMetric' => $legendAppendMetric, + 'labelUseAbsoluteUrl' => false ); + $processedReport = Request::processRequest('API.getRowEvolution', $parameters); //@review this test will need to be updated after evaluating the @review comment in API/API.php if (!$processedReport) { @@ -345,22 +356,24 @@ class API extends \Piwik\Plugin\API $ordinateLabels[$plottedMetric] = $processedReport['label'] . ' (' . $metrics[$plottedMetric]['name'] . ')'; } } else { - $processedReport = APIMetadata::getInstance()->getProcessedReport( - $idSite, - $period, - $date, - $apiModule, - $apiAction, - $segment, - $apiParameters = false, - $idGoal, - $languageLoaded, - $showTimer = true, - $hideMetricsDoc = false, - $idSubtable, - $showRawMetrics = false + $parameters = array( + 'idSite' => $idSite, + 'period' => $period, + 'date' => $date, + 'apiModule' => $apiModule, + 'apiAction' => $apiAction, + 'segment' => $segment, + 'apiParameters' => false, + 'idGoal' => $idGoal, + 'language' => $languageLoaded, + 'showTimer' => true, + 'hideMetricsDoc' => false, + 'idSubtable' => $idSubtable, + 'showRawMetrics' => false ); + $processedReport = Request::processRequest('API.getProcessedReport', $parameters); } + // prepare abscissa and ordinate series $abscissaSeries = array(); $abscissaLogos = array(); diff --git a/plugins/QueuedTracking b/plugins/QueuedTracking -Subproject bad46dc2a021edf239fe603b40dfcf8532e5712 +Subproject 30de3d583ce151ac7825327ad72cc5d4b7c702b diff --git a/plugins/Referrers/Referrers.php b/plugins/Referrers/Referrers.php index 95c7e00446..cefa27bef8 100644 --- a/plugins/Referrers/Referrers.php +++ b/plugins/Referrers/Referrers.php @@ -28,11 +28,19 @@ class Referrers extends \Piwik\Plugin public function getListHooksRegistered() { return array( - 'Insights.addReportToOverview' => 'addReportToInsightsOverview', - 'Live.getAllVisitorDetails' => 'extendVisitorDetails' + 'Insights.addReportToOverview' => 'addReportToInsightsOverview', + 'Live.getAllVisitorDetails' => 'extendVisitorDetails', + 'Request.getRenamedModuleAndAction' => 'renameDeprecatedModuleAndAction', ); } + public function renameDeprecatedModuleAndAction(&$module, &$action) + { + if($module == 'Referers') { + $module = 'Referrers'; + } + } + public function extendVisitorDetails(&$visitor, $details) { $instance = new Visitor($details); diff --git a/plugins/ScheduledReports/ScheduledReports.php b/plugins/ScheduledReports/ScheduledReports.php index 6d171768a7..32c62e8b2a 100644 --- a/plugins/ScheduledReports/ScheduledReports.php +++ b/plugins/ScheduledReports/ScheduledReports.php @@ -94,9 +94,17 @@ class ScheduledReports extends \Piwik\Plugin 'SegmentEditor.deactivate' => 'segmentDeactivation', 'SegmentEditor.update' => 'segmentUpdated', 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys', + 'Request.getRenamedModuleAndAction' => 'renameDeprecatedModuleAndAction', ); } + public function renameDeprecatedModuleAndAction(&$module, &$action) + { + if($module == 'PDFReports') { + $module = 'ScheduledReports'; + } + } + public function getClientSideTranslationKeys(&$translationKeys) { $translationKeys[] = "ScheduledReports_ReportSent"; diff --git a/plugins/UserSettings/UserSettings.php b/plugins/UserSettings/UserSettings.php index f72269dedf..7596227de5 100644 --- a/plugins/UserSettings/UserSettings.php +++ b/plugins/UserSettings/UserSettings.php @@ -25,7 +25,7 @@ class UserSettings extends \Piwik\Plugin return array( 'Metrics.getDefaultMetricTranslations' => 'addMetricTranslations', 'Live.getAllVisitorDetails' => 'extendVisitorDetails', - 'Request.dispatch' => 'mapDeprecatedActions' + 'Request.getRenamedModuleAndAction' => 'renameDeprecatedModuleAndAction', ); } @@ -35,9 +35,8 @@ class UserSettings extends \Piwik\Plugin * @deprecated since 2.10.0 and will be removed from May 1st 2015 * @param $module * @param $action - * @param $parameters */ - public function mapDeprecatedActions(&$module, &$action, &$parameters) + public function renameDeprecatedModuleAndAction(&$module, &$action) { $movedMethods = array( 'getBrowser' => 'getBrowsers', diff --git a/tests/PHPUnit/Framework/TestCase/IntegrationTestCase.php b/tests/PHPUnit/Framework/TestCase/IntegrationTestCase.php index 2a782b67c3..8381aea43f 100644 --- a/tests/PHPUnit/Framework/TestCase/IntegrationTestCase.php +++ b/tests/PHPUnit/Framework/TestCase/IntegrationTestCase.php @@ -87,7 +87,7 @@ abstract class IntegrationTestCase extends SystemTestCase */ public function tearDown() { - self::$fixture->clearInMemoryCaches(); + static::$fixture->clearInMemoryCaches(); parent::tearDown(); } diff --git a/tests/PHPUnit/Integration/CacheIdTest.php b/tests/PHPUnit/Integration/CacheIdTest.php index ebdfd9c035..01d39d7e49 100644 --- a/tests/PHPUnit/Integration/CacheIdTest.php +++ b/tests/PHPUnit/Integration/CacheIdTest.php @@ -39,7 +39,11 @@ class CacheIdTest extends IntegrationTestCase { $result = CacheId::pluginAware('myrandomkey'); - // if this test fails most likely there is a new plugin loaded and you simple have to update the cache id. - $this->assertEquals('myrandomkey-8f88a1dea9163e86178e69a1293ec084-en', $result); + $parts = explode('-', $result); + + $this->assertCount(3, $parts); + $this->assertEquals('myrandomkey', $parts[0]); + $this->assertEquals(32, strlen($parts[1]), $parts[1] . ' is not a MD5 hash'); + $this->assertEquals('en', $parts[2]); } } diff --git a/tests/PHPUnit/Integration/CronArchive/SharedSiteIdsTest.php b/tests/PHPUnit/Integration/CronArchive/SharedSiteIdsTest.php index 6e3959ceda..8ad12f8b8b 100644 --- a/tests/PHPUnit/Integration/CronArchive/SharedSiteIdsTest.php +++ b/tests/PHPUnit/Integration/CronArchive/SharedSiteIdsTest.php @@ -26,11 +26,20 @@ class SharedSiteIdsTest extends IntegrationTestCase { parent::setUp(); + if (! SharedSiteIds::isSupported()) { + $this->markTestSkipped('Not supported on this platform'); + return; + } + $this->sharedSiteIds = new SharedSiteIds(array(1,2,5,9)); } public function tearDown() { + if (! SharedSiteIds::isSupported()) { + return; + } + $siteIdsToCleanup = new SharedSiteIds(array()); $siteIdsToCleanup->setSiteIdsToArchive(array()); diff --git a/tests/PHPUnit/Integration/HttpTest.php b/tests/PHPUnit/Integration/HttpTest.php index a5d62b3060..3e7f38577c 100644 --- a/tests/PHPUnit/Integration/HttpTest.php +++ b/tests/PHPUnit/Integration/HttpTest.php @@ -60,6 +60,10 @@ class HttpTest extends \PHPUnit_Framework_TestCase */ public function testCustomByteRange($method) { + if ($method == 'fopen') { + return; // not supported w/ this method + } + $result = Http::sendHttpRequestBy( $method, Fixture::getRootUrl() . '/piwik.js', @@ -74,12 +78,10 @@ class HttpTest extends \PHPUnit_Framework_TestCase $getExtendedInfo = true ); - if ($method != 'fopen') { - $this->assertEquals(206, $result['status']); - $this->assertTrue(isset($result['headers']['Content-Range'])); - $this->assertEquals('bytes 10-20/', substr($result['headers']['Content-Range'], 0, 12)); - $this->assertTrue( in_array($result['headers']['Content-Type'], array('application/x-javascript', 'application/javascript'))); - } + $this->assertEquals(206, $result['status']); + $this->assertTrue(isset($result['headers']['Content-Range'])); + $this->assertEquals('bytes 10-20/', substr($result['headers']['Content-Range'], 0, 12)); + $this->assertTrue(in_array($result['headers']['Content-Type'], array('application/x-javascript', 'application/javascript'))); } /** @@ -111,6 +113,6 @@ class HttpTest extends \PHPUnit_Framework_TestCase $this->assertTrue(isset($result['headers']['Content-Length']), "Content-Length header not set!"); $this->assertTrue(is_numeric($result['headers']['Content-Length']), "Content-Length header not numeric!"); - $this->assertEquals('application/zip', $result['headers']['Content-Type']); + $this->assertTrue(in_array($result['headers']['Content-Type'], array('application/zip', 'application/x-zip-compressed'))); } } diff --git a/tests/PHPUnit/Integration/ReleaseCheckListTest.php b/tests/PHPUnit/Integration/ReleaseCheckListTest.php index 425b400f8a..95aaccb43f 100644 --- a/tests/PHPUnit/Integration/ReleaseCheckListTest.php +++ b/tests/PHPUnit/Integration/ReleaseCheckListTest.php @@ -156,6 +156,11 @@ class ReleaseCheckListTest extends \PHPUnit_Framework_TestCase $files = Filesystem::globr(PIWIK_INCLUDE_PATH, '*.php'); foreach($files as $file) { + // skip files in these folders + if (strpos($file, '/libs/') !== false) { + continue; + } + $handle = fopen($file, "r"); $expectedStart = "<?php"; @@ -250,7 +255,7 @@ class ReleaseCheckListTest extends \PHPUnit_Framework_TestCase strpos($file, '/tests/') !== false || strpos($file, '/lang/') !== false || strpos($file, 'yuicompressor') !== false || - strpos($file, '/libs/bower_components') !== false || + strpos($file, '/libs/') !== false || (strpos($file, '/vendor') !== false && strpos($file, '/vendor/piwik') === false) || strpos($file, '/tmp/') !== false ) { @@ -258,7 +263,7 @@ class ReleaseCheckListTest extends \PHPUnit_Framework_TestCase } // skip files with these file extensions - if (preg_match('/\.(bmp|fdf|gif|deb|deflate|exe|gz|ico|jar|jpg|p12|pdf|png|rar|swf|vsd|z|zip|ttf|so|dat|eps|phar|pyc|gzip)$/', $file)) { + if (preg_match('/\.(bmp|fdf|gif|deb|deflate|exe|gz|ico|jar|jpg|p12|pdf|png|rar|swf|vsd|z|zip|ttf|so|dat|eps|phar|pyc|gzip|eot|woff|svg)$/', $file)) { continue; } @@ -311,6 +316,11 @@ class ReleaseCheckListTest extends \PHPUnit_Framework_TestCase { $errors = array(); foreach ($files as $file) { + // skip files in these folders + if (strpos($file, '/libs/') !== false) { + continue; + } + $function = "imagecreatefrom" . $format; if (!function_exists($function)) { throw new \Exception("Unexpected error: $function function does not exist!"); diff --git a/tests/PHPUnit/Integration/ServeStaticFileTest.php b/tests/PHPUnit/Integration/ServeStaticFileTest.php index 31700eebef..8eabd6a499 100644 --- a/tests/PHPUnit/Integration/ServeStaticFileTest.php +++ b/tests/PHPUnit/Integration/ServeStaticFileTest.php @@ -276,7 +276,7 @@ class ServeStaticFileTest extends \PHPUnit_Framework_TestCase // Tests deflate compression has been used $deflateFileLocation = $this->getCompressedFileLocation() . ".deflate"; - $this->assertTrue(file_exists($deflateFileLocation)); + $this->assertFileExists($deflateFileLocation); // Tests gzdeflate has been used for IE compatibility $this->assertEquals(gzinflate(file_get_contents($deflateFileLocation)), file_get_contents(TEST_FILE_LOCATION)); @@ -310,7 +310,7 @@ class ServeStaticFileTest extends \PHPUnit_Framework_TestCase // Tests gzip compression has been used $gzipFileLocation = $this->getCompressedFileLocation() . ".gz"; - $this->assertTrue(file_exists($gzipFileLocation)); + $this->assertFileExists($gzipFileLocation); $this->removeCompressedFiles(); } @@ -446,8 +446,8 @@ class ServeStaticFileTest extends \PHPUnit_Framework_TestCase clearstatcache(); // check the correct compressed file is created - $this->assertTrue(file_exists($this->getCompressedFileLocation() . '.' . PARTIAL_BYTE_START . '.' . PARTIAL_BYTE_END . ".deflate")); - $this->assertFalse(file_exists($this->getCompressedFileLocation() . ".gz")); + $this->assertFileExists($this->getCompressedFileLocation() . '.' . PARTIAL_BYTE_START . '.' . PARTIAL_BYTE_END . ".deflate"); + $this->assertFileNotExists($this->getCompressedFileLocation() . ".gz"); // check $partialResponse $expectedPartialContents = substr(file_get_contents(TEST_FILE_LOCATION), PARTIAL_BYTE_START, @@ -475,8 +475,8 @@ class ServeStaticFileTest extends \PHPUnit_Framework_TestCase clearstatcache(); // check the correct compressed file is created - $this->assertTrue(file_exists($this->getCompressedFileLocation() . ".deflate")); - $this->assertFalse(file_exists($this->getCompressedFileLocation() . ".gz")); + $this->assertFileExists($this->getCompressedFileLocation() . ".deflate"); + $this->assertFileNotExists($this->getCompressedFileLocation() . ".gz"); // check $fullResponse $this->assertEquals(file_get_contents(TEST_FILE_LOCATION), $fullResponse); diff --git a/tests/PHPUnit/Integration/Tracker/VisitTest.php b/tests/PHPUnit/Integration/Tracker/VisitTest.php index 2764e4a2aa..ef5668e737 100644 --- a/tests/PHPUnit/Integration/Tracker/VisitTest.php +++ b/tests/PHPUnit/Integration/Tracker/VisitTest.php @@ -159,6 +159,7 @@ class VisitTest extends IntegrationTestCase 'http://semalt.com/out/of/here?mate' => true, 'http://buttons-for-website.com/out/of/here?mate' => true, 'https://buttons-for-website.com' => true, + 'https://7makemoneyonline.com' => true, 'http://valid.domain/' => false, 'http://valid.domain/page' => false, 'https://valid.domain/page' => false, diff --git a/tests/PHPUnit/System/expected/test_ImportLogs__Live.getLastVisitsDetails_range.xml b/tests/PHPUnit/System/expected/test_ImportLogs__Live.getLastVisitsDetails_range.xml index 149b71426e..3e2644cca0 100644 --- a/tests/PHPUnit/System/expected/test_ImportLogs__Live.getLastVisitsDetails_range.xml +++ b/tests/PHPUnit/System/expected/test_ImportLogs__Live.getLastVisitsDetails_range.xml @@ -2184,12 +2184,12 @@ <visitDurationPretty>2s</visitDurationPretty> <searches>0</searches> <actions>2</actions> - <referrerType>direct</referrerType> - <referrerTypeName>Direct Entry</referrerTypeName> - <referrerName /> + <referrerType>website</referrerType> + <referrerTypeName>Websites</referrerTypeName> + <referrerName>example.com</referrerName> <referrerKeyword /> <referrerKeywordPosition /> - <referrerUrl /> + <referrerUrl>http://example.com/Search/SearchResults.pg?informationRecipient.languageCode.c=en</referrerUrl> <referrerSearchEngineUrl /> <referrerSearchEngineIcon /> <plugins /> diff --git a/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getAll_month.xml b/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getAll_month.xml index 808d27a0c7..8ddde34007 100644 --- a/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getAll_month.xml +++ b/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getAll_month.xml @@ -40,4 +40,24 @@ <sum_daily_nb_users>0</sum_daily_nb_users> <referer_type>3</referer_type> </row> + <row> + <label>example.com</label> + <nb_visits>1</nb_visits> + <nb_actions>2</nb_actions> + <max_actions>2</max_actions> + <sum_visit_length>2</sum_visit_length> + <bounce_count>0</bounce_count> + <goals> + <row idgoal='1'> + <nb_conversions>1</nb_conversions> + <nb_visits_converted>1</nb_visits_converted> + <revenue>5</revenue> + </row> + </goals> + <nb_conversions>1</nb_conversions> + <revenue>5</revenue> + <sum_daily_nb_uniq_visitors>1</sum_daily_nb_uniq_visitors> + <sum_daily_nb_users>1</sum_daily_nb_users> + <referer_type>3</referer_type> + </row> </result>
\ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getNumberOfDistinctWebsitesUrls_month.xml b/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getNumberOfDistinctWebsitesUrls_month.xml index 13002b2017..15ef03fb49 100644 --- a/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getNumberOfDistinctWebsitesUrls_month.xml +++ b/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getNumberOfDistinctWebsitesUrls_month.xml @@ -1,2 +1,2 @@ <?xml version="1.0" encoding="utf-8" ?> -<result>2</result>
\ No newline at end of file +<result>3</result>
\ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getNumberOfDistinctWebsites_month.xml b/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getNumberOfDistinctWebsites_month.xml index 13002b2017..15ef03fb49 100644 --- a/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getNumberOfDistinctWebsites_month.xml +++ b/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getNumberOfDistinctWebsites_month.xml @@ -1,2 +1,2 @@ <?xml version="1.0" encoding="utf-8" ?> -<result>2</result>
\ No newline at end of file +<result>3</result>
\ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getReferrerType_month.xml b/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getReferrerType_month.xml index e5e8c8d924..0f1dfce4ff 100644 --- a/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getReferrerType_month.xml +++ b/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getReferrerType_month.xml @@ -2,44 +2,63 @@ <result> <row> <label>Direct Entry</label> - <nb_visits>32</nb_visits> - <nb_actions>37</nb_actions> + <nb_visits>31</nb_visits> + <nb_actions>35</nb_actions> <max_actions>3</max_actions> - <sum_visit_length>550</sum_visit_length> + <sum_visit_length>548</sum_visit_length> <bounce_count>28</bounce_count> <goals> <row idgoal='1'> - <nb_conversions>28</nb_conversions> - <nb_visits_converted>28</nb_visits_converted> - <revenue>140</revenue> + <nb_conversions>27</nb_conversions> + <nb_visits_converted>27</nb_visits_converted> + <revenue>135</revenue> </row> </goals> - <nb_conversions>28</nb_conversions> - <revenue>140</revenue> - <sum_daily_nb_uniq_visitors>31</sum_daily_nb_uniq_visitors> - <sum_daily_nb_users>2</sum_daily_nb_users> + <nb_conversions>27</nb_conversions> + <revenue>135</revenue> + <sum_daily_nb_uniq_visitors>30</sum_daily_nb_uniq_visitors> + <sum_daily_nb_users>1</sum_daily_nb_users> <nb_visits_converted>0</nb_visits_converted> </row> <row> <label>Websites</label> - <nb_visits>2</nb_visits> - <nb_actions>2</nb_actions> - <max_actions>1</max_actions> - <sum_visit_length>0</sum_visit_length> + <nb_visits>3</nb_visits> + <nb_actions>4</nb_actions> + <max_actions>2</max_actions> + <sum_visit_length>2</sum_visit_length> <bounce_count>2</bounce_count> <goals> <row idgoal='1'> - <nb_conversions>2</nb_conversions> - <nb_visits_converted>2</nb_visits_converted> - <revenue>10</revenue> + <nb_conversions>3</nb_conversions> + <nb_visits_converted>3</nb_visits_converted> + <revenue>15</revenue> </row> </goals> - <nb_conversions>2</nb_conversions> - <revenue>10</revenue> - <sum_daily_nb_uniq_visitors>2</sum_daily_nb_uniq_visitors> - <sum_daily_nb_users>0</sum_daily_nb_users> + <nb_conversions>3</nb_conversions> + <revenue>15</revenue> + <sum_daily_nb_uniq_visitors>3</sum_daily_nb_uniq_visitors> + <sum_daily_nb_users>1</sum_daily_nb_users> <subtable> <row> + <label>example.com</label> + <nb_visits>1</nb_visits> + <nb_actions>2</nb_actions> + <max_actions>2</max_actions> + <sum_visit_length>2</sum_visit_length> + <bounce_count>0</bounce_count> + <goals> + <row idgoal='1'> + <nb_conversions>1</nb_conversions> + <nb_visits_converted>1</nb_visits_converted> + <revenue>5</revenue> + </row> + </goals> + <nb_conversions>1</nb_conversions> + <revenue>5</revenue> + <sum_daily_nb_uniq_visitors>1</sum_daily_nb_uniq_visitors> + <sum_daily_nb_users>1</sum_daily_nb_users> + </row> + <row> <label>piwik.org</label> <nb_visits>1</nb_visits> <nb_actions>1</nb_actions> diff --git a/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getWebsites_month.xml b/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getWebsites_month.xml index bfba8f21af..0abe37b28d 100644 --- a/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getWebsites_month.xml +++ b/tests/PHPUnit/System/expected/test_ImportLogs__Referrers.getWebsites_month.xml @@ -1,6 +1,38 @@ <?xml version="1.0" encoding="utf-8" ?> <result> <row> + <label>example.com</label> + <nb_visits>1</nb_visits> + <nb_actions>2</nb_actions> + <max_actions>2</max_actions> + <sum_visit_length>2</sum_visit_length> + <bounce_count>0</bounce_count> + <goals> + <row idgoal='1'> + <nb_conversions>1</nb_conversions> + <nb_visits_converted>1</nb_visits_converted> + <revenue>5</revenue> + </row> + </goals> + <nb_conversions>1</nb_conversions> + <revenue>5</revenue> + <sum_daily_nb_uniq_visitors>1</sum_daily_nb_uniq_visitors> + <sum_daily_nb_users>1</sum_daily_nb_users> + <subtable> + <row> + <label>http://example.com/Search/SearchResults.pg?informationRecipient.languageCode.c=en</label> + <nb_visits>1</nb_visits> + <nb_actions>2</nb_actions> + <max_actions>2</max_actions> + <sum_visit_length>2</sum_visit_length> + <bounce_count>0</bounce_count> + <nb_visits_converted>1</nb_visits_converted> + <sum_daily_nb_uniq_visitors>1</sum_daily_nb_uniq_visitors> + <sum_daily_nb_users>1</sum_daily_nb_users> + </row> + </subtable> + </row> + <row> <label>piwik.org</label> <nb_visits>1</nb_visits> <nb_actions>1</nb_actions> diff --git a/tests/PHPUnit/UI b/tests/PHPUnit/UI -Subproject 3c3fe985f1af4f1d897d6c1551057124fd6bffa +Subproject 903002816d39732aa2b2e8d33286725e60c9a4f diff --git a/tests/PHPUnit/Unit/DeprecatedMethodsTest.php b/tests/PHPUnit/Unit/DeprecatedMethodsTest.php index 25b9f46ee1..4cbb8e0b08 100644 --- a/tests/PHPUnit/Unit/DeprecatedMethodsTest.php +++ b/tests/PHPUnit/Unit/DeprecatedMethodsTest.php @@ -64,7 +64,7 @@ class DeprecatedMethodsTest extends \PHPUnit_Framework_TestCase $this->assertDeprecatedMethodIsRemoved('Piwik\Plugins\UserSettings\API', 'getMobileVsDesktop', $validTill); $this->assertDeprecatedMethodIsRemoved('Piwik\Plugins\UserSettings\API', 'getResolution', $validTill); $this->assertDeprecatedMethodIsRemoved('Piwik\Plugins\UserSettings\API', 'getConfiguration', $validTill); - $this->assertDeprecatedMethodIsRemoved('Piwik\Plugins\UserSettings\UserSettings', 'mapDeprecatedActions', $validTill); + $this->assertDeprecatedMethodIsRemoved('Piwik\Plugins\UserSettings\UserSettings', 'renameDeprecatedModuleAndAction', $validTill); $this->assertDeprecatedMethodIsRemovedInPiwik3('\Piwik\Menu\MenuAbstract', 'add'); } diff --git a/tests/PHPUnit/Unit/Metrics/FormatterTest.php b/tests/PHPUnit/Unit/Metrics/FormatterTest.php index 8ef4831299..ce8c268b08 100644 --- a/tests/PHPUnit/Unit/Metrics/FormatterTest.php +++ b/tests/PHPUnit/Unit/Metrics/FormatterTest.php @@ -142,8 +142,9 @@ class FormatterTest extends \PHPUnit_Framework_TestCase array(0.14, '0,14'), array(0.14567, '0,15'), array(100.1234, '100,12'), - array(1000.45, '1.000,45'), - array(23456789.00, '23.456.789,00') + // Those last two are commented because locales are platform dependent, on some platforms the separator is '' instead of '.' +// array(1000.45, '1.000,45'), +// array(23456789.00, '23.456.789,00'), ); } diff --git a/tests/PHPUnit/Unit/Tracker/RequestTest.php b/tests/PHPUnit/Unit/Tracker/RequestTest.php index e3ff037638..43898ec866 100644 --- a/tests/PHPUnit/Unit/Tracker/RequestTest.php +++ b/tests/PHPUnit/Unit/Tracker/RequestTest.php @@ -132,6 +132,8 @@ class RequestTest extends UnitTestCase $this->assertCount(1, $request->getParams()); $this->assertTrue($request->isEmptyRequest()); + + unset($_SERVER['HTTP_REFERER']); } public function test_isEmptyRequest_ShouldReturnFalse_InCaseAtLEastOneParamIssSet() @@ -464,9 +466,16 @@ class RequestTest extends UnitTestCase public function test_getBrowserLanguage_ShouldReturnADefaultLanguageInCaseNoneIsSet() { + $envLanguage = getenv('LANG'); + putenv('LANG=en'); + $lang = $this->request->getBrowserLanguage(); $this->assertNotEmpty($lang); $this->assertTrue(2 <= strlen($lang) && strlen($lang) <= 10); + + if ($envLanguage !== false) { + putenv('LANG=' . $envLanguage); + } } public function test_makeThirdPartyCookie_ShouldReturnAnInstanceOfCookie() diff --git a/tests/README.md b/tests/README.md index faf942cba4..57c9c0923b 100644 --- a/tests/README.md +++ b/tests/README.md @@ -125,10 +125,16 @@ We also have an OmniFixture that includes all other Fixtures. OmniFixture is use #### Keep OmniFixture up to date -Remember to update the [Omnifixture SQL dump](https://github.com/piwik/piwik/blob/master/tests/resources/OmniFixture-dump.sql.gz) whenever you make any change to any fixture. For instance use: - ./console tests:setup-fixture OmniFixture --sqldump=OmniFixture-dump.sql` and then gzip. +Remember to update the [Omnifixture SQL dump](https://github.com/piwik/piwik/blob/master/tests/resources/OmniFixture-dump.sql.gz) whenever you make any change to any fixture. +For instance use: -Keeping the OmniFixture up to date makes it easier to see which tests fail after each small fixture change. If we don't update the OmniFixture then we end up with many failed screenshots tests which makes it hard to see whether those changes are expected or not. + ./console tests:setup-fixture OmniFixture --sqldump=OmniFixture-dump.sql + +and then gzip. + +Keeping the OmniFixture up to date makes it easier to see which tests fail after each small fixture change. + +If we don't update the OmniFixture then we end up with many failed screenshots tests which makes it hard to see whether those changes are expected or not. ### Scheduled Reports Tests diff --git a/tests/lib/screenshot-testing/support/page-renderer.js b/tests/lib/screenshot-testing/support/page-renderer.js index 7e8edcb466..d4886e2ed2 100644 --- a/tests/lib/screenshot-testing/support/page-renderer.js +++ b/tests/lib/screenshot-testing/support/page-renderer.js @@ -250,7 +250,15 @@ PageRenderer.prototype.capture = function (outputPath, callback, selector) { var clipRect = {bottom: null, height: null, left: null, right: null, top: null, width: null}; element.each(function (index, node) { - var rect = node.getBoundingClientRect(); + if (!$(node).is(':visible')) { + return; + } + + var rect = $(node).offset(); + rect.width = $(node).outerWidth(); + rect.height = $(node).outerHeight(); + rect.right = rect.left + rect.width; + rect.bottom = rect.top + rect.height; if (isInvalidBoundingRect(rect)) { // element is not visible diff --git a/tests/resources/OmniFixture-dump.sql.gz b/tests/resources/OmniFixture-dump.sql.gz Binary files differindex 710962a0b7..cc17a2a9dd 100644 --- a/tests/resources/OmniFixture-dump.sql.gz +++ b/tests/resources/OmniFixture-dump.sql.gz |