Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@googlemail.com>2014-10-05 15:05:47 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-10-05 15:05:47 +0400
commit5a1eab97f54b44f57356b4276b9c9df2a8eef51b (patch)
tree83864ece2806ccf6e6bb49abf3fd65de92c13ad8 /tests/PHPUnit/System/PurgeDataTest.php
parent19bcd2d262343eae9d553378e4c66ce7e033b4d8 (diff)
refs #5940 put tests in correct folders, better testsuite names, some tests still fail and I cannot figure out why
Diffstat (limited to 'tests/PHPUnit/System/PurgeDataTest.php')
-rwxr-xr-xtests/PHPUnit/System/PurgeDataTest.php194
1 files changed, 194 insertions, 0 deletions
diff --git a/tests/PHPUnit/System/PurgeDataTest.php b/tests/PHPUnit/System/PurgeDataTest.php
new file mode 100755
index 0000000000..30bf2244ff
--- /dev/null
+++ b/tests/PHPUnit/System/PurgeDataTest.php
@@ -0,0 +1,194 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+namespace Piwik\Tests\System;
+
+require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/MockLocationProvider.php';
+
+use Piwik\API\Request;
+use Piwik\Plugins\PrivacyManager\PrivacyManager;
+use Piwik\Plugins\PrivacyManager\ReportsPurger;
+use Piwik\Tests\SystemTestCase;
+use Piwik\Tests\Fixtures\OneVisitorTwoVisits;
+
+/**
+ * TODO: shouldn't this be merged w/ PrivacyManagerTest? the original data purging tests are there
+ *
+ * @group Core
+ * @group PurgeDataTest
+ */
+class PurgeDataTest extends SystemTestCase
+{
+ public static $fixture = null; // initialized below class definition
+
+ public static function setUpBeforeClass()
+ {
+
+ }
+ public static function tearDownBeforeClass()
+ {
+
+ }
+
+ public function setUp()
+ {
+ parent::setUpBeforeClass();
+ }
+
+ public function tearDown()
+ {
+ parent::tearDownAfterClass();
+ }
+
+ public function test_purgeData_keepAllExceptDay()
+ {
+ $this->assertHasOneDownload('day');
+ $this->assertHasOneDownload('week');
+ $this->assertHasOneDownload('month');
+ $this->assertHasOneDownload('year');
+
+ $deleteReportsOlderThan = 1;
+ $keepBasicMetrics = true;
+ $reportPeriodsToKeep = array(2,3,4,5);
+ $this->purgeData($deleteReportsOlderThan, $reportPeriodsToKeep, $keepBasicMetrics);
+
+ $this->assertHasNoDownload('day');
+ $this->assertHasOneDownload('week');
+ $this->assertHasOneDownload('month');
+ $this->assertHasOneDownload('year');
+ }
+
+ public function test_purgeData_keepOnlyDay()
+ {
+ $this->assertHasOneDownload('day');
+ $this->assertHasOneDownload('week');
+ $this->assertHasOneDownload('month');
+ $this->assertHasOneDownload('year');
+
+ $deleteReportsOlderThan = 1;
+ $keepBasicMetrics = true;
+ $reportPeriodsToKeep = array(1);
+ $this->purgeData($deleteReportsOlderThan, $reportPeriodsToKeep, $keepBasicMetrics);
+
+ $this->assertNumVisits(2, 'day');
+ $this->assertNumVisits(2, 'week');
+ $this->assertHasOneDownload('day');
+ $this->assertHasNoDownload('week');
+ $this->assertHasNoDownload('month');
+ $this->assertHasNoDownload('year');
+ }
+
+ public function test_purgeData_shouldNotPurgeAnything_IfDeleteReportsOlderThanIsFarBackInThePast()
+ {
+ $this->assertHasOneDownload('day');
+ $this->assertHasOneDownload('week');
+ $this->assertHasOneDownload('month');
+ $this->assertHasOneDownload('year');
+
+ $deleteReportsOlderThan = 1000;
+ $keepBasicMetrics = true;
+ $reportPeriodsToKeep = array(1,2,3,4,5);
+ $this->purgeData($deleteReportsOlderThan, $reportPeriodsToKeep, $keepBasicMetrics);
+
+ $this->assertHasOneDownload('day');
+ $this->assertHasOneDownload('week');
+ $this->assertHasOneDownload('month');
+ $this->assertHasOneDownload('year');
+ }
+
+ public function test_purgeData_shouldPurgeAllPeriodsExceptBasicMetrics_IfNoPeriodToKeepIsGiven()
+ {
+ $this->assertHasOneDownload('day');
+ $this->assertHasOneDownload('week');
+ $this->assertHasOneDownload('month');
+ $this->assertHasOneDownload('year');
+
+ $deleteReportsOlderThan = 1;
+ $keepBasicMetrics = true;
+ $reportPeriodsToKeep = array();
+ $this->purgeData($deleteReportsOlderThan, $reportPeriodsToKeep, $keepBasicMetrics);
+
+ $this->assertNumVisits(2, 'day');
+ $this->assertNumVisits(2, 'week');
+ $this->assertNumVisits(2, 'month');
+ $this->assertNumVisits(2, 'year');
+ $this->assertHasNoDownload('day');
+ $this->assertHasNoDownload('week');
+ $this->assertHasNoDownload('month');
+ $this->assertHasNoDownload('year');
+ }
+
+ public function test_purgeData_shouldPurgeEverything_IfNoPeriodToKeepIsGivenAndBasicMetricsNotKept()
+ {
+ $this->assertHasOneDownload('day');
+ $this->assertHasOneDownload('week');
+ $this->assertHasOneDownload('month');
+ $this->assertHasOneDownload('year');
+
+ $deleteReportsOlderThan = 1;
+ $keepBasicMetrics = false;
+ $reportPeriodsToKeep = array();
+ $this->purgeData($deleteReportsOlderThan, $reportPeriodsToKeep, $keepBasicMetrics);
+
+ $this->assertNumVisits(0, 'day');
+ $this->assertNumVisits(0, 'week');
+ $this->assertNumVisits(0, 'month');
+ $this->assertNumVisits(0, 'year');
+ $this->assertHasNoDownload('day');
+ $this->assertHasNoDownload('week');
+ $this->assertHasNoDownload('month');
+ $this->assertHasNoDownload('year');
+ }
+
+ private function assertNumVisits($expectedNumVisits, $period)
+ {
+ $url = 'method=VisitsSummary.getVisits'
+ . '&idSite=' . self::$fixture->idSite
+ . '&date=' . self::$fixture->dateTime
+ . '&period='. $period
+ . '&format=original';
+ $api = new Request($url);
+ $table = $api->process();
+ $this->assertEquals($expectedNumVisits, $table->getFirstRow()->getColumn('nb_visits'));
+ }
+
+ private function assertHasOneDownload($period)
+ {
+ $api = new Request($this->getDownloadApiRequestUrl($period));
+ $table = $api->process();
+ $this->assertEquals(1, $table->getRowsCount(), $period . ' should have one download but has not');
+ }
+
+ private function assertHasNoDownload($period)
+ {
+ $api = new Request($this->getDownloadApiRequestUrl($period));
+ $table = $api->process();
+ $this->assertEquals(0, $table->getRowsCount(), $period . ' should not have a download but has one');
+ }
+
+ private function getDownloadApiRequestUrl($period)
+ {
+ return 'method=Actions.getDownloads'
+ . '&idSite=' . self::$fixture->idSite
+ . '&date=' . self::$fixture->dateTime
+ . '&period='. $period
+ . '&format=original';
+ }
+
+ private function purgeData($deleteReportsOlderThan, $reportPeriodsToKeep, $keepBasicMetrics)
+ {
+ $metricsToKeep = PrivacyManager::getAllMetricsToKeep();
+ $maxRowsToDeletePerQuery = 100000;
+ $keepSegmentReports = false;
+
+ $purger = new ReportsPurger($deleteReportsOlderThan, $keepBasicMetrics, $reportPeriodsToKeep,
+ $keepSegmentReports, $metricsToKeep, $maxRowsToDeletePerQuery);
+ $purger->purgeData();
+ }
+}
+
+PurgeDataTest::$fixture = new OneVisitorTwoVisits();