diff options
author | Ben <ben.burgess@innocraft.com> | 2022-03-03 03:42:42 +0300 |
---|---|---|
committer | Ben <ben.burgess@innocraft.com> | 2022-03-03 03:42:42 +0300 |
commit | c50d974db7d119d8a70a48ac93bed896363e5245 (patch) | |
tree | 3c5889dc50aa426a6e72412c1627c1313d272607 | |
parent | 9cc04a0ce278a44e4d51655e493c87711d844019 (diff) |
Added test for website with local time in the previous day from the current UTC timem-18773-do-not-archive-the-future
-rw-r--r-- | tests/PHPUnit/Integration/ArchiveTest.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/PHPUnit/Integration/ArchiveTest.php b/tests/PHPUnit/Integration/ArchiveTest.php index 0e60483a52..a4c04fc6ea 100644 --- a/tests/PHPUnit/Integration/ArchiveTest.php +++ b/tests/PHPUnit/Integration/ArchiveTest.php @@ -344,6 +344,61 @@ class ArchiveTest extends IntegrationTestCase Date::$now = time(); } + public function test_shouldNotArchivePeriodsStartingInTheFuture_IfWebSiteLocalTimeIsInPreviousDay() + { + + // Create a site with a timezone behind of UTC + $idSite = Fixture::createWebsite('2014-05-06', 1, false, false, + 1, null, null, 'America/Vancouver'); // -8hrs + + self::$fixture->getTestEnvironment()->overrideConfig('General', 'browser_archiving_disabled_enforce', 0); + self::$fixture->getTestEnvironment()->overrideConfig('General', 'archiving_range_force_on_browser_request', 1); + self::$fixture->getTestEnvironment()->save(); + + Config::getInstance()->General['browser_archiving_disabled_enforce'] = 0; + Config::getInstance()->General['archiving_range_force_on_browser_request'] = 1; + + // track some visits + $t = Fixture::getTracker($idSite, '2020-03-04 05:05:05'); + $t->setUrl('http://abc.com/mypage'); + Fixture::checkResponse($t->doTrackPageView('page title')); + + $t->setForceVisitDateTime('2020-03-05 06:06:06'); + $t->setUrl('http://abc.com/myotherpage'); + Fixture::checkResponse($t->doTrackPageView('another page')); + + $t->setForceVisitDateTime('2020-03-06 07:07:07'); + $t->setUrl('http://abc.com/myotherpageagain'); + Fixture::checkResponse($t->doTrackPageView('another page again')); + + // Set the current UTC date to a time only 3hrs from midnight, this will ensure that the website with + // it's local timezone will be in the previous day + Date::$now = strtotime('2020-03-05 03:00:00'); + + // clear invalidations from above tracking + $cronArchive = new CronArchive(); + $cronArchive->init(); + $cronArchive->invalidateArchivedReportsForSitesThatNeedToBeArchivedAgain(1); + + // archive range and day + Rules::setBrowserTriggerArchiving(true); + API::getInstance()->get($idSite, 'day', '2020-03-04'); + API::getInstance()->get($idSite, 'day', '2020-03-05'); + API::getInstance()->get($idSite, 'day', '2020-03-06'); + API::getInstance()->get($idSite, 'day', '2020-03-07'); + + // check expected archives were created + $archives = Db::fetchAll("SELECT date1, date2, name, period, value FROM " . Common::prefixTable('archive_numeric_2020_03') + . " WHERE `name` IN ('done', 'done.VisitsSummary')"); + + $expected = [ + ['date1' => '2020-03-04', 'date2' => '2020-03-04', 'name' => 'done', 'period' => 1, 'value' => '1'] + ]; + $this->assertEquals($expected, $archives); + + Date::$now = time(); + } + public function test_archivingInvalidWeekWithSegment_doesReprocessInvalidDayWIthSegment() { $idSite = 1; |