diff options
author | diosmosis <benaka@piwik.pro> | 2015-03-05 14:22:58 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-03-05 14:22:58 +0300 |
commit | 7c3c4057d2d540025e4da19ee4c82b06f163d07e (patch) | |
tree | e3346cf0249bf358ff05a37cab1c05f7e9b27b16 /plugins/CoreAdminHome | |
parent | d7380293fc158543a6bb3e88d9e2ce6da1dc7ff1 (diff) |
Refs #7181, move ArchivesToPurgeDistributedList to CoreAdminHome since only consumer for it is the scheduled task and add tests for task in CoreAdminHome (or rather move test from PurgerTest to new TasksTest class). Moved test setup to new fixture type.
Diffstat (limited to 'plugins/CoreAdminHome')
-rw-r--r-- | plugins/CoreAdminHome/Tasks.php | 1 | ||||
-rw-r--r-- | plugins/CoreAdminHome/tests/Integration/TasksTest.php | 88 |
2 files changed, 88 insertions, 1 deletions
diff --git a/plugins/CoreAdminHome/Tasks.php b/plugins/CoreAdminHome/Tasks.php index e09d9ad03c..07398a83e3 100644 --- a/plugins/CoreAdminHome/Tasks.php +++ b/plugins/CoreAdminHome/Tasks.php @@ -16,7 +16,6 @@ use Piwik\Db; use Piwik\Log; use Piwik\Plugins\CoreAdminHome\Tasks\ArchivesToPurgeDistributedList; -// TODO: tests for Tasks class Tasks extends \Piwik\Plugin\Tasks { /** diff --git a/plugins/CoreAdminHome/tests/Integration/TasksTest.php b/plugins/CoreAdminHome/tests/Integration/TasksTest.php new file mode 100644 index 0000000000..aacc20d7f7 --- /dev/null +++ b/plugins/CoreAdminHome/tests/Integration/TasksTest.php @@ -0,0 +1,88 @@ +<?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\Plugins\CoreAdminHome\tests\Integration; + +use Piwik\Archive\Purger; +use Piwik\Date; +use Piwik\Plugins\CoreAdminHome\Tasks; +use Piwik\Plugins\CoreAdminHome\Tasks\ArchivesToPurgeDistributedList; +use Piwik\Tests\Fixtures\RawArchiveDataWithTempAndInvalidated; +use Piwik\Tests\Framework\TestCase\IntegrationTestCase; + +/** + * @group Core + */ +class TasksTest extends IntegrationTestCase +{ + /** + * @var RawArchiveDataWithTempAndInvalidated + */ + public static $fixture; + + /** + * @var Tasks + */ + private $tasks; + + /** + * @var Date + */ + private $january; + + /** + * @var Date + */ + private $february; + + public function setUp() + { + parent::setUp(); + + $this->january = Date::factory('2015-01-01'); + $this->february = Date::factory('2015-02-01'); + + $archivePurger = new Purger(); + $archivePurger->setTodayDate(Date::factory('2015-02-27')); + $archivePurger->setYesterdayDate(Date::factory('2015-02-26')); + $archivePurger->setNow(Date::factory('2015-02-27 08:00:00')->getTimestamp()); + + $this->tasks = new Tasks($archivePurger); + } + + public function test_purgeInvalidatedArchives_PurgesCorrectInvalidatedArchives_AndOnlyPurgesDataForDatesAndSites_InInvalidatedReportsDistributedList() + { + $this->setUpInvalidatedReportsDistributedList($dates = array($this->february)); + + $this->tasks->purgeInvalidatedArchives(); + + self::$fixture->assertFebruaryInvalidatedArchivesPurged(); + self::$fixture->assertJanuaryInvalidatedArchivesNotPurged(); + + // assert invalidated reports distributed list has changed + $archivesToPurgeDistributedList = new ArchivesToPurgeDistributedList(); + $yearMonths = $archivesToPurgeDistributedList->getAll(); + + $this->assertEmpty($yearMonths); + } + + /** + * @param Date[] $dates + */ + private function setUpInvalidatedReportsDistributedList($dates) + { + $yearMonths = array(); + foreach ($dates as $date) { + $yearMonths[] = $date->toString('Y_m'); + } + + $archivesToPurgeDistributedList = new ArchivesToPurgeDistributedList(); + $archivesToPurgeDistributedList->add($yearMonths); + } +} + +TasksTest::$fixture = new RawArchiveDataWithTempAndInvalidated();
\ No newline at end of file |