public function test_RunAllTests() { parent::test_RunAllTests(); if (Test_Integration::$apiTestingLevel != Test_Integration::NO_API_TESTING) { // Check that requesting period "Range" means // only processing the requested Plugin blob (Actions in this case), not all Plugins blobs $tests = array('archive_blob_2010_12' => (4 + 7 + 2) * 3, 'archive_numeric_2010_12' => (6 + 1 + 3 + 6 + 1) * 3, 'archive_blob_2011_01' => 0, 'archive_numeric_2011_01' => 0); foreach ($tests as $table => $expectedRows) { $sql = "SELECT count(*) FROM " . Piwik_Common::prefixTable($table) . " WHERE period = " . Piwik::$idPeriods['range']; $countBlobs = Zend_Registry::get('db')->fetchOne($sql); $this->assertEqual($expectedRows, $countBlobs, "{$table} expected {$expectedRows}, got {$countBlobs}"); } } }
public function test_RunAllTests() { parent::test_RunAllTests(); if (Test_Integration::$apiTestingLevel != Test_Integration::NO_API_TESTING) { $this->_checkExpectedRowsInArchiveTable(); // Force Purge to happen again this table (since it was called at end of archiving) Piwik_SetOption(Piwik_ArchiveProcessing_Period::FLAG_TABLE_PURGED . Piwik_Common::prefixTable('archive_blob_2010_12'), '2010-01-01'); Piwik_SetOption(Piwik_ArchiveProcessing_Period::FLAG_TABLE_PURGED . Piwik_Common::prefixTable('archive_blob_2011_01'), '2010-01-01'); foreach (array('archive_numeric_2010_12', 'archive_blob_2010_12', 'archive_numeric_2011_01', 'archive_blob_2011_01') as $table) { // INSERT some ERROR records. // We use period=range since the test below is restricted to these Piwik_Query(" INSERT INTO `" . Piwik_Common::prefixTable($table) . "` (`idarchive` ,`name` ,`idsite` ,`date1` ,`date2` ,`period` ,`ts_archived` ,`value`)\n\t\t\t\t\tVALUES (10000, 'done', '1', '2010-12-06', '2010-12-06', '" . Piwik::$idPeriods['range'] . "', '2010-12-06' , '" . Piwik_ArchiveProcessing::DONE_ERROR . "'), \n\t\t\t\t\t\t\t(20000, 'doneX', '2', '2012-07-06', '2012-07-06', '" . Piwik::$idPeriods['range'] . "', '' , '" . Piwik_ArchiveProcessing::DONE_ERROR . "')"); } // We've added error rows which should fail the following test $this->_checkExpectedRowsInArchiveTable($expectPass = false); // Test Scheduled tasks Table Optimize, and Delete old reports Piwik_CoreAdminHome::purgeOutdatedArchives(); Piwik_CoreAdminHome::optimizeArchiveTable(); // Check that only the good reports were not deleted: $this->_checkExpectedRowsInArchiveTable(); } }
/** * Use case testing various important features: * - Test Multisites API use cases * - testing period=range use case. * - Recording data before and after, checking that the requested range is processed correctly * - and more */ class Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange extends IntegrationTestCase { public static $fixture = null; // initialized below class definition /** * @dataProvider getApiForTesting * @group Integration */ public function testApi($api, $params) { $this->runApiTests($api, $params); } public function getApiForTesting() { $idSite = self::$fixture->idSite; return array(array('MultiSites.getAll', array('date' => '2010-12-15,2011-01-15', 'periods' => array('range'))), array('MultiSites.getAll', array('date' => '2010-12-15', 'periods' => array('day'), 'testSuffix' => '_IndexedByDate', 'otherRequestParameters' => array('pattern' => 'aAa'))), array('MultiSites.getOne', array('date' => '2010-12-15,2011-01-15', 'periods' => array('range'), 'idSite' => $idSite)), array('MultiSites.getAll', array('date' => '2010-12-15,2011-01-15', 'periods' => array('day'), 'testSuffix' => '_MultipleDatesNotSupported')), array('Referrers.getSocials', array('idSite' => 'all', 'date' => '2010-12-13,2011-01-18', 'periods' => array('range'))), array('Referrers.getSocials', array('idSite' => 'all', 'date' => '2010-12-10', 'periods' => array('day'), 'setDateLastN' => true, 'testSuffix' => '_IndexedByDate')), array('Referrers.getUrlsForSocial', array('idSite' => 'all', 'date' => '2010-12-13,2011-01-18', 'periods' => 'range', 'testSuffix' => '_noIdSubtable')), array('Referrers.getUrlsForSocial', array('idSite' => 1, 'date' => '2010-12-13,2011-01-18', 'periods' => 'range', 'supertableApi' => 'Referrers.getSocials')), array('UserCountry.getCountry', array('idSite' => $idSite, 'date' => '2010-12-01,2011-01-15', 'periods' => array('range')))); } public static function getOutputPrefix() { return 'oneVisitor_oneWebsite_severalDays_DateRange'; } } Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange::$fixture = new Test_Piwik_Fixture_VisitsOverSeveralDays();