diff options
author | Kate Butler <kate@innocraft.com> | 2019-10-16 04:01:06 +0300 |
---|---|---|
committer | Thomas Steur <tsteur@users.noreply.github.com> | 2019-10-16 04:01:06 +0300 |
commit | 8b2964a968825ede0e12de424608313563bb7f55 (patch) | |
tree | bfd77f0967eff1f6c5628ef21b7545246f71c594 /tests/PHPUnit | |
parent | d26202219e74898d583391b17959bf7bd74cb51d (diff) |
Allow date ranges to be passed to core:invalidate-report-data (#14450)
Diffstat (limited to 'tests/PHPUnit')
-rw-r--r-- | tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php | 153 |
1 files changed, 146 insertions, 7 deletions
diff --git a/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php b/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php index 6ae4410505..7bc718b373 100644 --- a/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php +++ b/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php @@ -310,6 +310,34 @@ class ArchiveInvalidatorTest extends IntegrationTestCase $this->assertEquals($expectedIdArchives, $idArchives); } + /** + * @dataProvider getTestDataForMarkArchiveRangesAsInvalidated + */ + public function test_markArchivesAsInvalidated_MarksAllSubrangesOfRange($idSites, $dates, $segment, $expectedIdArchives) + { + $dates = array_map(array('Piwik\Date', 'factory'), $dates); + + $this->insertArchiveRowsForTest(); + + if (!empty($segment)) { + $segment = new Segment($segment, $idSites); + } + + /** @var ArchiveInvalidator $archiveInvalidator */ + $archiveInvalidator = self::$fixture->piwikEnvironment->getContainer()->get('Piwik\Archive\ArchiveInvalidator'); + $result = $archiveInvalidator->markArchivesOverlappingRangeAsInvalidated($idSites, array($dates), $segment); + + $this->assertEquals(array($dates[0]), $result->processedDates); + + $idArchives = $this->getInvalidatedArchives(); + + // Remove empty values (some new empty entries may be added each month) + $idArchives = array_filter($idArchives); + $expectedIdArchives = array_filter($expectedIdArchives); + + $this->assertEquals($expectedIdArchives, $idArchives); + } + public function getTestDataForMarkArchivesAsInvalidated() { // $idSites, $dates, $period, $segment, $cascadeDown, $expectedIdArchives @@ -462,10 +490,10 @@ class ArchiveInvalidatorTest extends IntegrationTestCase ), ), - // range period, one site, cascade = true + // range period, exact match array( array(1), - array('2015-01-02', '2015-03-05'), + array('2015-01-01', '2015-01-10'), 'range', null, true, @@ -473,10 +501,20 @@ class ArchiveInvalidatorTest extends IntegrationTestCase '2015_01' => array( '1.2015-01-01.2015-01-10.5.done.VisitsSummary', ), - '2015_03' => array( - '1.2015-03-04.2015-03-05.5.done.VisitsSummary', - '1.2015-03-05.2015-03-10.5.done3736b708e4d20cfc10610e816a1b2341.UserCountry', - ), + ), + ), + + // range period, overlapping a range in the DB + array( + array(1), + array('2015-01-02', '2015-03-05'), + 'range', + null, + true, + array( + '2015_01' => array( + '1.2015-01-01.2015-01-10.5.done.VisitsSummary', + ) ), ), @@ -532,6 +570,101 @@ class ArchiveInvalidatorTest extends IntegrationTestCase ); } + public function getTestDataForMarkArchiveRangesAsInvalidated() + { + // $idSites, $dates, $segment, $expectedIdArchives + return array( + // range period, has an exact match, also a match where DB end date = reference start date + array( + array(1), + array('2015-01-01', '2015-01-10'), + null, + array( + '2014_12' => array( + '1.2014-12-05.2015-01-01.5.done.VisitsSummary', + ), + '2015_01' => array( + '1.2015-01-01.2015-01-10.5.done.VisitsSummary', + ), + ), + ), + + // range period, overlapping range = a match + array( + array(1), + array('2015-01-02', '2015-03-05'), + null, + array( + '2015_01' => array( + '1.2015-01-01.2015-01-10.5.done.VisitsSummary', + ), + '2015_03' => array( + '1.2015-03-04.2015-03-05.5.done.VisitsSummary', + '1.2015-03-05.2015-03-10.5.done3736b708e4d20cfc10610e816a1b2341.UserCountry', + ), + ), + ), + + // range period, small range within the 2014-12-05 to 2015-01-01 range should cause it to be invalidated + array( + array(1), + array('2014-12-18', '2014-12-20'), + null, + array( + '2014_12' => array( + '1.2014-12-05.2015-01-01.5.done.VisitsSummary', + ), + ), + ), + + // range period, range that overlaps start of archived range + array( + array(1), + array('2014-12-01', '2014-12-05'), + null, + array( + '2014_12' => array( + '1.2014-12-05.2015-01-01.5.done.VisitsSummary', + ), + ), + ), + + // range period, large range that includes the smallest archived range (3 to 4 March) + array( + array(1), + array('2015-01-11', '2015-03-30'), + null, + array( + '2015_03' => array( + '1.2015-03-04.2015-03-05.5.done.VisitsSummary', + '1.2015-03-05.2015-03-10.5.done3736b708e4d20cfc10610e816a1b2341.UserCountry', + ), + ), + ), + + // range period, doesn't match any archived ranges + array( + array(1), + array('2014-12-01', '2014-12-04'), + null, + array( + ), + ), + + // three-month range period, there's a range archive for the middle month + array( + array(1), + array('2014-09-01', '2014-11-08'), + null, + array( + '2014_10' => array( + '1.2014-10-15.2014-10-20.5.done3736b708e4d20cfc10610e816a1b2341', + ), + ), + ), + ); + } + private function getInvalidatedIdArchives() { $result = array(); @@ -579,7 +712,13 @@ class ArchiveInvalidatorTest extends IntegrationTestCase } } - $rangePeriods = array('2015-03-04,2015-03-05', '2014-12-05,2015-01-01', '2015-03-05,2015-03-10', '2015-01-01,2015-01-10'); + $rangePeriods = array( + '2015-03-04,2015-03-05', + '2014-12-05,2015-01-01', + '2015-03-05,2015-03-10', + '2015-01-01,2015-01-10', + '2014-10-15,2014-10-20' + ); foreach ($rangePeriods as $dateRange) { $this->insertArchiveRow($idSite = 1, $dateRange, 'range'); } |