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
path: root/tests
diff options
context:
space:
mode:
authordiosmosis <benaka@piwik.pro>2015-03-15 22:31:25 +0300
committerdiosmosis <benaka@piwik.pro>2015-03-15 22:31:25 +0300
commit2c325c6352619fe7967233d78860e41b35813a7a (patch)
tree6fd68b56bf910fdcbb463b7adc39bd9fb90cdf47 /tests
parentd03cae1e4c5113f987c1df3ab90ab6e0e9f4e624 (diff)
parent649337c7a37a3fda9a35532240ef06092fd2f7e3 (diff)
Merge branch 'master' into geo-attribution-task
Diffstat (limited to 'tests')
-rw-r--r--tests/PHPUnit/Fixtures/RawArchiveDataWithTempAndInvalidated.php396
-rw-r--r--tests/PHPUnit/Framework/TestCase/ConsoleCommandTestCase.php18
-rw-r--r--tests/PHPUnit/Integration/Archive/PurgerTest.php117
-rw-r--r--tests/PHPUnit/Integration/Concurrency/DistributedListTest.php153
-rw-r--r--tests/PHPUnit/Integration/CronArchiveTest.php2
-rw-r--r--tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php2
-rw-r--r--tests/PHPUnit/Integration/Tracker/VisitTest.php2
-rwxr-xr-xtests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysConversionsTest.php2
-rwxr-xr-xtests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchVisitorTypeTest.php4
9 files changed, 684 insertions, 12 deletions
diff --git a/tests/PHPUnit/Fixtures/RawArchiveDataWithTempAndInvalidated.php b/tests/PHPUnit/Fixtures/RawArchiveDataWithTempAndInvalidated.php
new file mode 100644
index 0000000000..a6ef25a89f
--- /dev/null
+++ b/tests/PHPUnit/Fixtures/RawArchiveDataWithTempAndInvalidated.php
@@ -0,0 +1,396 @@
+<?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\Fixtures;
+
+use Piwik\DataAccess\ArchiveTableCreator;
+use Piwik\DataAccess\ArchiveWriter;
+use Piwik\Date;
+use Piwik\Db;
+use Piwik\Tests\Framework\Fixture;
+
+/**
+ * Fixture that inserts rows into archive tables for Jan. 2015 + Feb. 2015. The rows include
+ * done rows + metrics/blobs, and the done rows have values of DONE_OK_TEMPORARY,
+ * DONE_OK, DONE_INVALIDATED. There are also some custom range archives.
+ *
+ * This class is used to test archive purging.
+ */
+class RawArchiveDataWithTempAndInvalidated extends Fixture
+{
+ private static $dummyArchiveData = array(
+ // outdated temporary
+ array(
+ 'idarchive' => 1,
+ 'idsite' => 1,
+ 'name' => 'done',
+ 'value' => ArchiveWriter::DONE_OK_TEMPORARY,
+ 'date1' => '2015-02-03',
+ 'date2' => '2015-02-03',
+ 'period' => 1,
+ 'ts_archived' => '2015-02-03 12:12:12'
+ ),
+
+ array(
+ 'idarchive' => 2,
+ 'idsite' => 2,
+ 'name' => 'doneDUMMYHASHSTR',
+ 'value' => ArchiveWriter::DONE_OK_TEMPORARY,
+ 'date1' => '2015-02-01',
+ 'date2' => '2015-02-31',
+ 'period' => 3,
+ 'ts_archived' => '2015-02-18 10:10:10'
+ ),
+
+ array(
+ 'idarchive' => 3,
+ 'idsite' => 3,
+ 'name' => 'done',
+ 'value' => ArchiveWriter::DONE_OK_TEMPORARY,
+ 'date1' => '2015-02-04',
+ 'date2' => '2015-02-10',
+ 'period' => 2,
+ 'ts_archived' => '2015-02-10 12:34:56'
+ ),
+
+ array(
+ 'idarchive' => 4,
+ 'idsite' => 1,
+ 'name' => 'doneDUMMYHASHSTR',
+ 'value' => ArchiveWriter::DONE_OK_TEMPORARY,
+ 'date1' => '2015-02-15',
+ 'date2' => '2015-02-15',
+ 'period' => 1,
+ 'ts_archived' => '2015-02-15 08:12:13'
+ ),
+
+
+ // valid temporary
+ array( // only valid
+ 'idarchive' => 5,
+ 'idsite' => 1,
+ 'name' => 'done',
+ 'value' => ArchiveWriter::DONE_OK_TEMPORARY,
+ 'date1' => '2015-02-27',
+ 'date2' => '2015-02-27',
+ 'period' => 1,
+ 'ts_archived' => '2015-02-27 08:08:08'
+ ),
+
+ array(
+ 'idarchive' => 6,
+ 'idsite' => 2,
+ 'name' => 'doneDUMMYHASHSTR',
+ 'value' => ArchiveWriter::DONE_OK_TEMPORARY,
+ 'date1' => '2015-02-26',
+ 'date2' => '2015-02-26',
+ 'period' => 1,
+ 'ts_archived' => '2015-02-26 07:07:07'
+ ),
+
+ array(
+ 'idarchive' => 7,
+ 'idsite' => 3,
+ 'name' => 'done',
+ 'value' => ArchiveWriter::DONE_OK_TEMPORARY,
+ 'date1' => '2015-02-01',
+ 'date2' => '2015-02-28',
+ 'period' => 3,
+ 'ts_archived' => '2015-02-15 00:00:00'
+ ),
+
+ // custom ranges
+ array(
+ 'idarchive' => 8,
+ 'idsite' => 1,
+ 'name' => 'doneDUMMYHASHSTR',
+ 'value' => ArchiveWriter::DONE_OK,
+ 'date1' => '2015-02-03',
+ 'date2' => '2015-02-14',
+ 'period' => 5,
+ 'ts_archived' => '2015-02-27 00:00:00'
+ ),
+
+ array(
+ 'idarchive' => 9,
+ 'idsite' => 2,
+ 'name' => 'done',
+ 'value' => ArchiveWriter::DONE_OK,
+ 'date1' => '2015-02-05',
+ 'date2' => '2015-02-14',
+ 'period' => 5,
+ 'ts_archived' => '2015-02-15 00:00:00'
+ ),
+
+ array(
+ 'idarchive' => 10,
+ 'idsite' => 3,
+ 'name' => 'doneDUMMYHASHSTR',
+ 'value' => ArchiveWriter::DONE_OK_TEMPORARY,
+ 'date1' => '2015-02-05',
+ 'date2' => '2015-03-05',
+ 'period' => 5,
+ 'ts_archived' => '2015-02-26 00:00:00'
+ ),
+
+ // invalidated
+ array(
+ 'idarchive' => 11,
+ 'idsite' => 1,
+ 'name' => 'done',
+ 'value' => ArchiveWriter::DONE_INVALIDATED,
+ 'date1' => '2015-02-10',
+ 'date2' => '2015-02-10',
+ 'period' => 1,
+ 'ts_archived' => '2015-02-10 12:13:14'
+ ),
+
+ array(
+ 'idarchive' => 12,
+ 'idsite' => 2,
+ 'name' => 'doneDUMMYHASHSTR',
+ 'value' => ArchiveWriter::DONE_INVALIDATED,
+ 'date1' => '2015-02-08',
+ 'date2' => '2015-02-14',
+ 'period' => 2,
+ 'ts_archived' => '2015-02-15 00:00:00'
+ ),
+
+ array(
+ 'idarchive' => 13,
+ 'idsite' => 3,
+ 'name' => 'done',
+ 'value' => ArchiveWriter::DONE_INVALIDATED,
+ 'date1' => '2015-02-01',
+ 'date2' => '2015-02-28',
+ 'period' => 3,
+ 'ts_archived' => '2015-02-27 13:13:13'
+ ),
+
+ array(
+ 'idarchive' => 14,
+ 'idsite' => 1,
+ 'name' => 'doneDUMMYHASHSTR',
+ 'value' => ArchiveWriter::DONE_INVALIDATED,
+ 'date1' => '2015-02-28',
+ 'date2' => '2015-02-28',
+ 'period' => 1,
+ 'ts_archived' => '2015-02-28 12:12:12'
+ ),
+
+ array(
+ 'idarchive' => 15,
+ 'idsite' => 1,
+ 'name' => 'done',
+ 'value' => ArchiveWriter::DONE_INVALIDATED,
+ 'date1' => '2015-02-27',
+ 'date2' => '2015-02-27',
+ 'period' => 1,
+ 'ts_archived' => '2015-02-28 12:12:12'
+ ),
+
+ // reprocessed invalidated
+ array(
+ 'idarchive' => 16,
+ 'idsite' => 1,
+ 'name' => 'done',
+ 'value' => ArchiveWriter::DONE_OK,
+ 'date1' => '2015-02-10',
+ 'date2' => '2015-02-10',
+ 'period' => 1,
+ 'ts_archived' => '2015-02-11 12:13:14'
+ ),
+
+ array(
+ 'idarchive' => 17,
+ 'idsite' => 2,
+ 'name' => 'doneDUMMYHASHSTR',
+ 'value' => ArchiveWriter::DONE_OK,
+ 'date1' => '2015-02-08',
+ 'date2' => '2015-02-14',
+ 'period' => 2,
+ 'ts_archived' => '2015-02-16 00:00:00'
+ ),
+
+ array(
+ 'idarchive' => 18,
+ 'idsite' => 3,
+ 'name' => 'done',
+ 'value' => ArchiveWriter::DONE_OK,
+ 'date1' => '2015-02-01',
+ 'date2' => '2015-02-28',
+ 'period' => 3,
+ 'ts_archived' => '2015-02-28 13:13:13'
+ ),
+
+ array(
+ 'idarchive' => 19,
+ 'idsite' => 1,
+ 'name' => 'doneDUMMYHASHSTR',
+ 'value' => ArchiveWriter::DONE_OK_TEMPORARY,
+ 'date1' => '2015-02-28',
+ 'date2' => '2015-02-28',
+ 'period' => 1,
+ 'ts_archived' => '2015-02-28 16:12:12' // must be late so it doesn't screw up the purgeOutdatedArchives test
+ ),
+ );
+
+ /**
+ * @var Date
+ */
+ public $january;
+
+ /**
+ * @var Date
+ */
+ public $february;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->january = Date::factory('2015-01-01');
+ $this->february = Date::factory('2015-02-01');
+
+ $this->insertOutdatedArchives($this->january);
+ $this->insertOutdatedArchives($this->february);
+ }
+
+ private function insertOutdatedArchives(Date $archiveDate)
+ {
+ $dummyArchiveData = $this->getDummyArchiveDataForDate($archiveDate);
+
+ $numericTable = ArchiveTableCreator::getNumericTable($archiveDate);
+ foreach ($dummyArchiveData as $row) {
+ // done row
+ $this->insertTestArchiveRow($numericTable, $row);
+
+ // two metrics
+ $row['name'] = 'nb_visits';
+ $row['value'] = 1;
+ $this->insertTestArchiveRow($numericTable, $row);
+
+ $row['name'] = 'nb_actions';
+ $row['value'] = 2;
+ $this->insertTestArchiveRow($numericTable, $row);
+ }
+
+ $blobTable = ArchiveTableCreator::getBlobTable($archiveDate);
+ foreach ($dummyArchiveData as $row) {
+ // two blobs
+ $row['name'] = 'blobname';
+ $row['value'] = 'dummyvalue';
+ $this->insertTestArchiveRow($blobTable, $row);
+
+ $row['name'] = 'blobname2';
+ $row['value'] = 'dummyvalue';
+ $this->insertTestArchiveRow($blobTable, $row);
+ }
+ }
+
+ private function insertTestArchiveRow($table, $row)
+ {
+ $insertSqlTemplate = "INSERT INTO %s (idarchive, idsite, name, value, date1, date2, period, ts_archived) VALUES ('%s')";
+
+ Db::exec(sprintf($insertSqlTemplate, $table, implode("','", $row)));
+ }
+
+ private function getDummyArchiveDataForDate($archiveDate)
+ {
+ $rows = self::$dummyArchiveData;
+ foreach ($rows as &$row) {
+ $row['date1'] = $this->setDateMonthAndYear($row['date1'], $archiveDate);
+ $row['date2'] = $this->setDateMonthAndYear($row['date1'], $archiveDate);
+ }
+ return$rows;
+ }
+
+ private function setDateMonthAndYear($dateString, Date $archiveDate)
+ {
+ return $archiveDate->toString('Y-m') . '-' . Date::factory($dateString)->toString('d');
+ }
+
+ public function assertTemporaryArchivesPurged($isBrowserTriggeredArchivingEnabled, Date $date)
+ {
+ if ($isBrowserTriggeredArchivingEnabled) {
+ $expectedPurgedArchives = array(1,2,3,4,6,7); // only archives from 2 hours before "now" are purged
+ } else {
+ $expectedPurgedArchives = array(1,2,3,4,7); // only archives before start of "yesterday" are purged
+ }
+
+ $this->assertArchivesDoNotExist($expectedPurgedArchives, $date);
+ }
+
+ public function assertCustomRangesPurged(Date $date)
+ {
+ $expectedPurgedArchives = array(8,9,10);
+ $this->assertArchivesDoNotExist($expectedPurgedArchives, $date);
+ }
+
+ public function assertTemporaryArchivesNotPurged(Date $date)
+ {
+ $expectedPresentArchives = array(1,2,3,4,5,6,7);
+ $this->assertArchivesExist($expectedPresentArchives, $date);
+ }
+
+ public function assertInvalidatedArchivesNotPurged(Date $date)
+ {
+ $expectedPresentArchives = array(11, 12, 13, 14);
+ $this->assertArchivesExist($expectedPresentArchives, $date);
+ }
+
+ public function assertCustomRangesNotPurged(Date $date, $includeTemporary = true)
+ {
+ $expectedPresentArchives = array(8, 9);
+ if ($includeTemporary) {
+ $expectedPresentArchives[] = 10;
+ }
+ $this->assertArchivesExist($expectedPresentArchives, $date);
+ }
+
+ public function assertArchivesDoNotExist($expectedPurgedArchiveIds, $archiveDate)
+ {
+ $numericTable = ArchiveTableCreator::getNumericTable($archiveDate);
+ $blobTable = ArchiveTableCreator::getBlobTable($archiveDate);
+
+ $numericPurgedArchiveCount = $this->getArchiveRowCountWithId($numericTable, $expectedPurgedArchiveIds);
+ $this->assertEquals(0, $numericPurgedArchiveCount);
+
+ $blobPurgedArchiveCount = $this->getArchiveRowCountWithId($blobTable, $expectedPurgedArchiveIds);
+ $this->assertEquals(0, $blobPurgedArchiveCount);
+ }
+
+ public function assertArchivesExist($expectedPresentArchiveIds, $archiveDate)
+ {
+ $numericTable = ArchiveTableCreator::getNumericTable($archiveDate);
+ $blobTable = ArchiveTableCreator::getBlobTable($archiveDate);
+
+ $numericArchiveCount = $this->getArchiveRowCountWithId($numericTable, $expectedPresentArchiveIds);
+ $expectedNumericRowCount = count($expectedPresentArchiveIds) * 3; // two metrics + 1 done row
+ $this->assertEquals($expectedNumericRowCount, $numericArchiveCount);
+
+ $blobArchiveCount = $this->getArchiveRowCountWithId($blobTable, $expectedPresentArchiveIds);
+ $expectedBlobRowCount = count($expectedPresentArchiveIds) * 2; // two blob rows
+ $this->assertEquals($expectedBlobRowCount, $blobArchiveCount);
+ }
+
+ private function getArchiveRowCountWithId($table, $archiveIds)
+ {
+ return Db::fetchOne("SELECT COUNT(*) FROM $table WHERE idarchive IN (".implode(',', $archiveIds).")");
+ }
+
+ public function assertInvalidatedArchivesPurged(Date $date)
+ {
+ // check invalidated archives for all sites are purged
+ $expectedPurgedArchives = array(11, 12, 13, 14);
+ $this->assertArchivesDoNotExist($expectedPurgedArchives, $date);
+
+ // check archive 15 is not purged since it doesn't have newer DONE_OK/DONE_TEMPORARY archive
+ $expectedExistingArchives = array(15);
+ $this->assertArchivesExist($expectedExistingArchives, $date);
+ }
+} \ No newline at end of file
diff --git a/tests/PHPUnit/Framework/TestCase/ConsoleCommandTestCase.php b/tests/PHPUnit/Framework/TestCase/ConsoleCommandTestCase.php
index f88a62b445..3a8d33c7a5 100644
--- a/tests/PHPUnit/Framework/TestCase/ConsoleCommandTestCase.php
+++ b/tests/PHPUnit/Framework/TestCase/ConsoleCommandTestCase.php
@@ -8,8 +8,8 @@
namespace Piwik\Tests\Framework\TestCase;
-use Piwik\Config;
use Piwik\Console;
+use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\ApplicationTester;
/**
@@ -37,18 +37,24 @@ use Symfony\Component\Console\Tester\ApplicationTester;
*/
class ConsoleCommandTestCase extends SystemTestCase
{
+ /**
+ * @var ApplicationTester
+ */
protected $applicationTester = null;
+ /**
+ * @var Console
+ */
+ protected $application;
+
public function setUp()
{
parent::setUp();
- $application = new Console();
- $application->setAutoExit(false);
-
- $this->applicationTester = new ApplicationTester($application);
+ $this->application = new Console();
+ $this->application->setAutoExit(false);
- Config::unsetInstance();
+ $this->applicationTester = new ApplicationTester($this->application);
}
protected function getCommandDisplayOutputErrorMessage()
diff --git a/tests/PHPUnit/Integration/Archive/PurgerTest.php b/tests/PHPUnit/Integration/Archive/PurgerTest.php
new file mode 100644
index 0000000000..a422473479
--- /dev/null
+++ b/tests/PHPUnit/Integration/Archive/PurgerTest.php
@@ -0,0 +1,117 @@
+<?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\Integration\Archive;
+
+use Piwik\Archive\ArchivePurger;
+use Piwik\Config;
+use Piwik\Date;
+use Piwik\Db;
+use Piwik\Tests\Fixtures\RawArchiveDataWithTempAndInvalidated;
+use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
+
+/**
+ * @group Core
+ */
+class PurgerTest extends IntegrationTestCase
+{
+ /**
+ * @var RawArchiveDataWithTempAndInvalidated
+ */
+ public static $fixture;
+
+ /**
+ * @var ArchivePurger
+ */
+ private $archivePurger;
+
+ /**
+ * @var Date
+ */
+ private $january;
+
+ /**
+ * @var Date
+ */
+ private $february;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->january = self::$fixture->january;
+ $this->february = self::$fixture->february;
+
+ $this->archivePurger = new ArchivePurger();
+ $this->archivePurger->setTodayDate(Date::factory('2015-02-27'));
+ $this->archivePurger->setYesterdayDate(Date::factory('2015-02-26'));
+ $this->archivePurger->setNow(Date::factory('2015-02-27 08:00:00')->getTimestamp());
+
+ $this->configureCustomRangePurging();
+
+ // assert test data was added correctly
+ self::$fixture->assertInvalidatedArchivesNotPurged(self::$fixture->january);
+ self::$fixture->assertInvalidatedArchivesNotPurged(self::$fixture->february);
+ }
+
+ public function test_purgeOutdatedArchives_PurgesCorrectTemporaryArchives_WhileKeepingNewerTemporaryArchives_WithBrowserTriggeringEnabled()
+ {
+ $this->enableBrowserTriggeredArchiving();
+
+ $this->archivePurger->purgeOutdatedArchives($this->february);
+
+ self::$fixture->assertTemporaryArchivesPurged($browserTriggeringEnabled = true, $this->february);
+
+ self::$fixture->assertCustomRangesNotPurged($this->february, $includeTemporary = false);
+ self::$fixture->assertTemporaryArchivesNotPurged($this->january);
+ }
+
+ public function test_purgeOutdatedArchives_PurgesCorrectTemporaryArchives_WhileKeepingNewerTemporaryArchives_WithBrowserTriggeringDisabled()
+ {
+ $this->disableBrowserTriggeredArchiving();
+
+ $this->archivePurger->purgeOutdatedArchives($this->february);
+
+ self::$fixture->assertTemporaryArchivesPurged($browserTriggeringEnabled = false, $this->february);
+
+ self::$fixture->assertCustomRangesNotPurged($this->february);
+ self::$fixture->assertTemporaryArchivesNotPurged($this->january);
+ }
+
+ public function test_purgeInvalidatedArchivesFrom_PurgesAllInvalidatedArchives_AndMarksDatesAndSitesAsInvalidated()
+ {
+ $this->archivePurger->purgeInvalidatedArchivesFrom($this->february);
+
+ self::$fixture->assertInvalidatedArchivesPurged($this->february);
+ self::$fixture->assertInvalidatedArchivesNotPurged($this->january);
+ }
+
+ public function test_purgeArchivesWithPeriodRange_PurgesAllRangeArchives()
+ {
+ $this->archivePurger->purgeArchivesWithPeriodRange($this->february);
+
+ self::$fixture->assertCustomRangesPurged($this->february);
+ self::$fixture->assertCustomRangesNotPurged($this->january);
+ }
+
+ private function configureCustomRangePurging()
+ {
+ Config::getInstance()->General['purge_date_range_archives_after_X_days'] = 3;
+ }
+
+ private function enableBrowserTriggeredArchiving()
+ {
+ Config::getInstance()->General['enable_browser_archiving_triggering'] = 1;
+ }
+
+ private function disableBrowserTriggeredArchiving()
+ {
+ Config::getInstance()->General['enable_browser_archiving_triggering'] = 0;
+ }
+}
+
+PurgerTest::$fixture = new RawArchiveDataWithTempAndInvalidated(); \ No newline at end of file
diff --git a/tests/PHPUnit/Integration/Concurrency/DistributedListTest.php b/tests/PHPUnit/Integration/Concurrency/DistributedListTest.php
new file mode 100644
index 0000000000..0facc27a74
--- /dev/null
+++ b/tests/PHPUnit/Integration/Concurrency/DistributedListTest.php
@@ -0,0 +1,153 @@
+<?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\Integration\Concurrency;
+
+use Piwik\Common;
+use Piwik\Concurrency\DistributedList;
+use Piwik\Date;
+use Piwik\Db;
+use Piwik\Option;
+use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
+
+/**
+ * @group Core
+ */
+class DistributedListTest extends IntegrationTestCase
+{
+ const TEST_OPTION_NAME = 'test.distributed.list';
+
+ public static $defaultOptionValues = array(
+ 'val1',
+ 'val2',
+ 'val3',
+ 'val4'
+ );
+
+ /**
+ * @var DistributedList
+ */
+ private $distributedList;
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->distributedList = new DistributedList(self::TEST_OPTION_NAME);
+
+ $this->initOptionValue();
+ }
+
+ public function test_getAll_CorrectlyReturnsItemsInOption()
+ {
+ $list = $this->distributedList->getAll();
+ $this->assertEquals(self::$defaultOptionValues, $list);
+ }
+
+ public function test_getAll_ReturnsValueInOption_IfOptionCacheHasSeparateValue()
+ {
+ // get option so cache is loaded
+ Option::get(self::TEST_OPTION_NAME);
+
+ // set option value to something else
+ $newList = array('1', '2', '3');
+ $this->initOptionValue($newList);
+
+ // test option is now different
+ $list = $this->distributedList->getAll();
+ $this->assertEquals($newList, $list);
+ }
+
+ public function test_setAll_CorrectlySetsNormalListInOption()
+ {
+ $newList = array('1', '2', '3');
+ $this->distributedList->setAll($newList);
+
+ $optionValue = $this->getOptionValueForList();
+ $this->assertEquals(serialize($newList), $optionValue);
+
+ $list = $this->distributedList->getAll();
+ $this->assertEquals($newList, $list);
+ }
+
+ public function test_setAll_CorrectlyConvertsItemsToString_BeforePersistingToOption()
+ {
+ $newList = array('1', Date::factory('2015-02-03'), 4.5);
+ $this->distributedList->setAll($newList);
+
+ $optionValue = $this->getOptionValueForList();
+ $expectedOptionList = array('1', '2015-02-03', '4.5');
+ $this->assertEquals(serialize($expectedOptionList), $optionValue);
+
+ $list = $this->distributedList->getAll();
+ $this->assertEquals($expectedOptionList, $list);
+ }
+
+ public function test_add_AddsOneItemToList_InOptionTable_IfItemIsNotArray()
+ {
+ $this->distributedList->add('val5');
+
+ $expectedOptionList = array('val1', 'val2', 'val3', 'val4', 'val5');
+ $this->assertEquals(serialize($expectedOptionList), $this->getOptionValueForList());
+ }
+
+ public function test_add_AddsMultipleItemsToList_InOptionTable_IfItemsIsArray()
+ {
+ $this->distributedList->add(array('val5', Date::factory('2015-03-04')));
+
+ $expectedOptionList = array('val1', 'val2', 'val3', 'val4', 'val5', '2015-03-04');
+ $this->assertEquals(serialize($expectedOptionList), $this->getOptionValueForList());
+ }
+
+ public function test_remove_RemovesSingleItemByValue_InOptionTable_IfItemIsNotArray()
+ {
+ $this->distributedList->remove('val2');
+
+ $expectedOptionList = array('val1', 'val3', 'val4');
+ $this->assertEquals(serialize($expectedOptionList), $this->getOptionValueForList());
+ }
+
+ public function test_remove_RemovesMultipleItemsByValue_InOptionTable_IfItemIsArray()
+ {
+ $this->distributedList->remove(array('val2', 'val4'));
+
+ $expectedOptionList = array('val1', 'val3');
+ $this->assertEquals(serialize($expectedOptionList), $this->getOptionValueForList());
+ }
+
+ public function test_removeByIndex_RemovesSingleItemByIndex_InOptionTable_IfArgIsIndex()
+ {
+ $this->distributedList->removeByIndex(2);
+
+ $expectedOptionList = array('val1', 'val2', 'val4');
+ $this->assertEquals(serialize($expectedOptionList), $this->getOptionValueForList());
+ }
+
+ public function test_removeByIndex_RemovesMultipleItemsByIndex_InOptionTable_IfArgIsArray()
+ {
+ $this->distributedList->removeByIndex(array(1, 3));
+
+ $expectedOptionList = array('val1', 'val3');
+ $this->assertEquals(serialize($expectedOptionList), $this->getOptionValueForList());
+ }
+
+ private function initOptionValue($data = false)
+ {
+ $data = $data ?: self::$defaultOptionValues;
+
+ $optionTable = Common::prefixTable('option');
+ Db::query("INSERT INTO `$optionTable` (option_name, option_value, autoload) VALUES (?, ?, ?)
+ ON DUPLICATE KEY UPDATE option_value = ?",
+ array(self::TEST_OPTION_NAME, serialize($data), 0, serialize($data)));
+ }
+
+ private function getOptionValueForList()
+ {
+ $optionTable = Common::prefixTable('option');
+ return Db::fetchOne("SELECT option_value FROM `$optionTable` WHERE option_name = ?", array(self::TEST_OPTION_NAME));
+ }
+} \ No newline at end of file
diff --git a/tests/PHPUnit/Integration/CronArchiveTest.php b/tests/PHPUnit/Integration/CronArchiveTest.php
index a85f227802..c90e64a846 100644
--- a/tests/PHPUnit/Integration/CronArchiveTest.php
+++ b/tests/PHPUnit/Integration/CronArchiveTest.php
@@ -9,7 +9,7 @@
namespace Piwik\Tests\Integration;
use Piwik\CronArchive;
-use Piwik\DataAccess\ArchiveInvalidator;
+use Piwik\Archive\ArchiveInvalidator;
use Piwik\Date;
use Piwik\Db;
use Piwik\Plugins\CoreAdminHome\tests\Framework\Mock\API;
diff --git a/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php b/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php
index fbf2c0b7a9..7847abc202 100644
--- a/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php
+++ b/tests/PHPUnit/Integration/DataAccess/ArchiveInvalidatorTest.php
@@ -11,7 +11,7 @@ namespace Piwik\Tests\Integration\DataAccess;
use Piwik\Date;
use Piwik\Option;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
-use Piwik\DataAccess\ArchiveInvalidator;
+use Piwik\Archive\ArchiveInvalidator;
/**
* @group Archiver
diff --git a/tests/PHPUnit/Integration/Tracker/VisitTest.php b/tests/PHPUnit/Integration/Tracker/VisitTest.php
index bbbb972cc3..919a918516 100644
--- a/tests/PHPUnit/Integration/Tracker/VisitTest.php
+++ b/tests/PHPUnit/Integration/Tracker/VisitTest.php
@@ -11,7 +11,7 @@ namespace Piwik\Tests\Integration\Tracker;
use Piwik\Access;
use Piwik\Cache;
use Piwik\CacheId;
-use Piwik\DataAccess\ArchiveInvalidator;
+use Piwik\Archive\ArchiveInvalidator;
use Piwik\Date;
use Piwik\Network\IPUtils;
use Piwik\Plugin\Manager;
diff --git a/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysConversionsTest.php b/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysConversionsTest.php
index 56dc98e9a0..7e9a576b71 100755
--- a/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysConversionsTest.php
+++ b/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysConversionsTest.php
@@ -9,7 +9,7 @@ namespace Piwik\Tests\System;
use Piwik\Archive;
use Piwik\Cache;
-use Piwik\DataAccess\ArchiveInvalidator;
+use Piwik\Archive\ArchiveInvalidator;
use Piwik\Option;
use Piwik\Plugins\Goals\Archiver;
use Piwik\Segment;
diff --git a/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchVisitorTypeTest.php b/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchVisitorTypeTest.php
index 4f159e8399..77bb4f8dac 100755
--- a/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchVisitorTypeTest.php
+++ b/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchVisitorTypeTest.php
@@ -8,8 +8,8 @@
namespace Piwik\Tests\System;
use Piwik\Common;
-use Piwik\DataAccess\ArchiveInvalidator;
-use Piwik\DataAccess\InvalidatedReports;
+use Piwik\Archive\ArchiveInvalidator;
+use Piwik\CronArchive\SitesToReprocessDistributedList;
use Piwik\Db;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
use Piwik\Tests\Fixtures\TwoVisitsWithCustomVariables;