diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2019-10-02 06:05:36 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-02 06:05:36 +0300 |
commit | d86ad317bbfc09ac48400a563915c7c25fb226cf (patch) | |
tree | 97affab9d63e4ff5c4816d47ac3f0f4576bb1e23 /tests/PHPUnit/Integration | |
parent | 378c403704552a88c6e01f955bc2379aaed8f172 (diff) |
Add option to archiver to not create archives for segments for today (#14834)
* add option to not archive segment for today
* better implementation
* added some logging and tests
* also archive when ts_last_edit is recent
* tweak message
Diffstat (limited to 'tests/PHPUnit/Integration')
-rw-r--r-- | tests/PHPUnit/Integration/CronArchiveTest.php | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/tests/PHPUnit/Integration/CronArchiveTest.php b/tests/PHPUnit/Integration/CronArchiveTest.php index 139da7c4ab..cf06c78e15 100644 --- a/tests/PHPUnit/Integration/CronArchiveTest.php +++ b/tests/PHPUnit/Integration/CronArchiveTest.php @@ -8,13 +8,11 @@ namespace Piwik\Tests\Integration; -use Piwik\CliMulti; use Piwik\Container\StaticContainer; use Piwik\CronArchive; -use Piwik\Archive\ArchiveInvalidator; use Piwik\Date; -use Piwik\Db; use Piwik\Plugins\CoreAdminHome\tests\Framework\Mock\API; +use Piwik\Plugins\SegmentEditor\Model; use Piwik\Tests\Framework\Fixture; use Piwik\Tests\Framework\Mock\FakeLogger; use Piwik\Tests\Framework\TestCase\IntegrationTestCase; @@ -65,6 +63,54 @@ class CronArchiveTest extends IntegrationTestCase $this->assertEquals($expectedSegments, array_values($cronarchive->segmentsToForce)); } + public function test_wasSegmentCreatedRecently() + { + Fixture::createWebsite('2014-12-12 00:01:02'); + SegmentAPI::getInstance()->add('foo', 'actions>=1', 1, true, true); + $id = SegmentAPI::getInstance()->add('barb', 'actions>=2', 1, true, true); + + $segments = new Model(); + $segments->updateSegment($id, array('ts_created' => Date::now()->subHour(30)->getDatetime())); + + $allSegments = $segments->getSegmentsToAutoArchive(1); + + $cronarchive = new TestCronArchive(Fixture::getRootUrl() . 'tests/PHPUnit/proxy/index.php'); + $this->assertTrue($cronarchive->wasSegmentChangedRecently('actions>=1', $allSegments)); + + // created 30 hours ago... + $this->assertFalse($cronarchive->wasSegmentChangedRecently('actions>=2', $allSegments)); + + // not configured segment + $this->assertFalse($cronarchive->wasSegmentChangedRecently('actions>=999', $allSegments)); + } + + public function test_skipSegmentsToday() + { + \Piwik\Tests\Framework\Mock\FakeCliMulti::$specifiedResults = array( + '/method=API.get/' => serialize(array(array('nb_visits' => 1))) + ); + + Fixture::createWebsite('2014-12-12 00:01:02'); + SegmentAPI::getInstance()->add('foo', 'actions>=1', 1, true, true); + $id = SegmentAPI::getInstance()->add('barb', 'actions>=2', 1, true, true); + + $segments = new Model(); + $segments->updateSegment($id, array('ts_created' => Date::now()->subHour(30)->getDatetime())); + + $logger = new FakeLogger(); + + $archiver = new CronArchive(null, $logger); + $archiver->skipSegmentsToday = true; + $archiver->shouldArchiveAllSites = true; + $archiver->shouldArchiveAllPeriodsSince = true; + $archiver->init(); + $archiver->run(); + + $this->assertContains('Will skip segments archiving for today unless they were created recently', $logger->output); + $this->assertContains('Segment "actions>=1" was created recently and will therefore archive today', $logger->output); + $this->assertNotContains('Segment "actions>=2" was created recently', $logger->output); + } + public function test_output() { \Piwik\Tests\Framework\Mock\FakeCliMulti::$specifiedResults = array( @@ -185,4 +231,9 @@ class TestCronArchive extends CronArchive protected function initPiwikHost($piwikUrl = false) { } + + public function wasSegmentChangedRecently($definition, $allSegments) + { + return parent::wasSegmentChangedRecently($definition, $allSegments); + } } |