diff options
author | diosmosis <benaka@piwik.pro> | 2015-09-03 05:19:28 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-09-03 05:19:28 +0300 |
commit | 25412712c49fc7fa831dd929dd040c359920b521 (patch) | |
tree | a708262c83ac1e19a7d9295e8ec13a9c82f87c4a /plugins/CoreAdminHome/tests | |
parent | bc218dc6cff1e74382caedf19dbc8b544ee6cb87 (diff) |
Support lastN in database:optimize-archive-tables and add a test for the command.
Diffstat (limited to 'plugins/CoreAdminHome/tests')
-rw-r--r-- | plugins/CoreAdminHome/tests/Integration/Commands/OptimizeArchiveTablesTest.php | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/plugins/CoreAdminHome/tests/Integration/Commands/OptimizeArchiveTablesTest.php b/plugins/CoreAdminHome/tests/Integration/Commands/OptimizeArchiveTablesTest.php new file mode 100644 index 0000000000..2fe67b98f2 --- /dev/null +++ b/plugins/CoreAdminHome/tests/Integration/Commands/OptimizeArchiveTablesTest.php @@ -0,0 +1,92 @@ +<?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\Commands; + +use Piwik\DataAccess\ArchiveTableCreator; +use Piwik\Date; +use Piwik\Tests\Framework\TestCase\ConsoleCommandTestCase; + + +/** + * @group Core + */ +class OptimizeArchiveTablesTest extends ConsoleCommandTestCase +{ + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + ArchiveTableCreator::getNumericTable(Date::factory('2015-01-01')); + ArchiveTableCreator::getNumericTable(Date::factory('2015-02-02')); + ArchiveTableCreator::getNumericTable(Date::factory('2015-03-03')); + } + + /** + * @dataProvider getDatesToTest + */ + public function test_Command_OptimizesCorrectTables($dates, $expectedOptimizedTableDates) + { + $code = $this->applicationTester->run(array( + 'command' => 'database:optimize-archive-tables', + 'dates' => $dates, + '--dry-run' => true, + )); + + $this->assertEquals(0, $code, $this->getCommandDisplayOutputErrorMessage()); + + $output = $this->applicationTester->getDisplay(); + + preg_match_all('/Optimizing table \'([^\']+)\'/', $output, $matches); + $tablesOptimized = $matches[1]; + + $expectedOptimizedTables = array(); + foreach ($expectedOptimizedTableDates as $date) { + $expectedOptimizedTables[] = 'archive_numeric_' . $date; + $expectedOptimizedTables[] = 'archive_blob_' . $date; + } + + $this->assertEquals($expectedOptimizedTables, $tablesOptimized); + } + + public function getDatesToTest() + { + return array( + array( + array('all'), + array('2015_01', '2015_02', '2015_03'), + ), + + array( + array('now'), + array(date('Y_m')), + ), + + array( + array('2015-01-01', '2015-02-03', '2014-01-01', '2013-05-12', '2015-05-05'), + array('2015_01', '2015_02', '2014_01', '2013_05', '2015_05'), + ), + + array( + array('last1'), + array(Date::factory('now')->subMonth(1)->toString('Y_m')), + ), + + array( + array('last5'), + array( + Date::factory('now')->subMonth(1)->toString('Y_m'), + Date::factory('now')->subMonth(2)->toString('Y_m'), + Date::factory('now')->subMonth(3)->toString('Y_m'), + Date::factory('now')->subMonth(4)->toString('Y_m'), + Date::factory('now')->subMonth(5)->toString('Y_m'), + ), + ), + ); + } +}
\ No newline at end of file |