Example #1
0
 /**
  * A singleton method to create or return a single instance
  * of the {@link OA_DB_Table_Core} object.
  *
  * @static
  * @return OA_DB_Table_Core The created {@link OA_DB_Table_Core} object.
  */
 function &singleton()
 {
     $static =& $GLOBALS['_OA']['TABLES'][__CLASS__];
     if (!isset($static)) {
         $static = new OA_DB_Table_Core();
         // Don't use a reference here!
         $static->init(MAX_PATH . '/etc/tables_core.xml');
     }
     return $static;
 }
Example #2
0
 /**
  * Enter description here...
  *
  * @param array $installvars
  * @return boolean
  */
 function checkDatabaseExists($installvars)
 {
     $oDbh =& OA_DB::singleton();
     $oTable = OA_DB_Table_Core::singleton();
     $aTables = OA_DB_Table::listOATablesCaseSensitive();
     $result = false;
     foreach ($oTable->tables as $k => $v) {
         if (is_array($aTables) && in_array($installvars['table_prefix'] . $k, $aTables)) {
             // Table exists
             $result = true;
             break;
         }
     }
     return $result;
 }
 /**
  * initialisation
  *
  * load the 'requestset' config file
  * do not load the dataset yet - allow child scenario to choose
  *
  * @param string $filename - name of scenario's dataset and config
  * @param string $dbname database name
  */
 function init($filename)
 {
     $GLOBALS['_MAX']['CONF']['table']['prefix'] = '';
     // assign the inputs
     $this->requestFile = SCENARIOS_REQUESTSETS . $filename . '.php';
     // load the request data
     $this->loadRequestset();
     // tweak some conf vals
     $GLOBALS['_MAX']['COOKIE']['newViewerId'] = '';
     $_COOKIE = $HTTP_COOKIE_VARS = array();
     // get service locator instance
     $this->oServiceLocator =& OA_ServiceLocator::instance();
     // start with a clean set of tables
     OA_DB_Table_Core::destroy();
     $this->oCoreTables =& OA_DB_Table_Core::singleton();
     // get the database handler
     $this->oDbh =& OA_DB::singleton();
     // fake the date/time
     $this->setDateTime();
 }
 /**
  * A method to test the run() method.
  */
 function testRun()
 {
     // Reset the testing environment
     TestEnv::restoreEnv();
     $aConf =& $GLOBALS['_MAX']['CONF'];
     $oTable =& OA_DB_Table_Core::singleton();
     $oDbh =& OA_DB::singleton();
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oNow = new Date('2004-06-06 18:10:00');
     $oServiceLocator->register('now', $oNow);
     // Create and register a new OX_Maintenance_Statistics object
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     // Create a new OX_Maintenance_Statistics_Task_LogCompletion object
     $oLogCompletion = new OX_Maintenance_Statistics_Task_LogCompletion();
     // Set some of the object's variables, and log
     $oLogCompletion->oController->updateIntermediate = true;
     $oLogCompletion->oController->oUpdateIntermediateToDate = new Date('2004-06-06 17:59:59');
     $oLogCompletion->oController->updateFinal = false;
     $oLogCompletion->oController->oUpdateFinalToDate = null;
     $oEnd = new Date('2004-06-06 18:12:00');
     $oLogCompletion->run($oEnd);
     // Test
     $query = "\n            SELECT\n                *\n            FROM\n                " . $oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['log_maintenance_statistics'], true) . "\n            WHERE\n                adserver_run_type = 0";
     $rc = $oDbh->query($query);
     $aRow = $rc->fetchRow();
     $this->assertEqual($aRow['start_run'], '2004-06-06 18:10:00');
     $this->assertEqual($aRow['end_run'], '2004-06-06 18:12:00');
     $this->assertEqual($aRow['duration'], 120);
     $this->assertEqual($aRow['updated_to'], '2004-06-06 17:59:59');
     // Set some of the object's variables, and log
     $oLogCompletion->oController->updateIntermediate = false;
     $oLogCompletion->oController->oUpdateIntermediateToDate = null;
     $oLogCompletion->oController->updateFinal = true;
     $oLogCompletion->oController->oUpdateFinalToDate = new Date('2004-06-06 17:59:59');
     $oEnd = new Date('2004-06-06 18:13:00');
     $oLogCompletion->run($oEnd);
     // Test
     $query = "\n            SELECT\n                *\n            FROM\n                " . $oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['log_maintenance_statistics'], true) . "\n            WHERE\n                adserver_run_type = 1";
     $rc = $oDbh->query($query);
     $aRow = $rc->fetchRow();
     $this->assertEqual($aRow['start_run'], '2004-06-06 18:10:00');
     $this->assertEqual($aRow['end_run'], '2004-06-06 18:13:00');
     $this->assertEqual($aRow['duration'], 180);
     $this->assertEqual($aRow['updated_to'], '2004-06-06 17:59:59');
     // Set some of the object's variables, and log
     $oLogCompletion->oController->updateIntermediate = true;
     $oLogCompletion->oController->oUpdateIntermediateToDate = new Date('2004-06-06 17:59:59');
     $oLogCompletion->oController->updateFinal = true;
     $oLogCompletion->oController->oUpdateFinalToDate = new Date('2004-06-06 17:59:59');
     $oEnd = new Date('2004-06-06 18:14:00');
     $oLogCompletion->run($oEnd);
     // Test
     $query = "\n            SELECT\n                *\n            FROM\n                " . $oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['log_maintenance_statistics'], true) . "\n            WHERE\n                adserver_run_type = 2";
     $rc = $oDbh->query($query);
     $aRow = $rc->fetchRow();
     $this->assertEqual($aRow['start_run'], '2004-06-06 18:10:00');
     $this->assertEqual($aRow['end_run'], '2004-06-06 18:14:00');
     $this->assertEqual($aRow['duration'], 240);
     $this->assertEqual($aRow['updated_to'], '2004-06-06 17:59:59');
     // Reset the testing environment
     TestEnv::restoreEnv();
 }
 /**
  * A method to test the run() method.
  */
 function testRun()
 {
     // Create a reference to the OpenX configuration so that settings
     // can be changed while the tests are running
     $aConf =& $GLOBALS['_MAX']['CONF'];
     // Create the database connection and service locator objects
     $oDbh =& OA_DB::singleton();
     $oServiceLocator =& OA_ServiceLocator::instance();
     // Create the "log_maintenance_statistics" table required for the tests
     $oTables =& OA_DB_Table_Core::singleton();
     $oTables->createTable('log_maintenance_statistics');
     // Create the "controller" OX_Maintenance_Statistics class, and
     // register in the service locator
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     // Create a partially mocked instance of the
     // OX_Maintenance_Statistics_Task_SetUpdateRequirements class
     Mock::generatePartial('OX_Maintenance_Statistics_Task_SetUpdateRequirements', 'PartialOX_Maintenance_Statistics_Task_SetUpdateRequirements', array('_getMaintenanceStatisticsLastRunInfo', '_getEarliestLoggedDeliveryData'));
     // Prepare an array of times that the MSE should be run at, to
     // test the effects of different times and data sets
     $aMSERunTimes = array(0 => new Date('2008-08-12 13:00:01'), 1 => new Date('2008-08-12 13:30:01'), 2 => new Date('2008-08-12 14:00:01'));
     // Create an array of valid operation interval values for runnung tests
     $aOperationIntervals = array(30, 60);
     /*-------------------------------------------------------------*/
     /* NO DATA TESTS                                               */
     /*                                                             */
     /* Run tests where with operation intervals of 30 and 60 mins, */
     /* where there is no data in the database, and test that the   */
     /* result is that the MSE will not be run.                     */
     /*-------------------------------------------------------------*/
     foreach ($aMSERunTimes as $key => $oRunDate) {
         // Register the "current" date/time that the MSE is running at
         $oServiceLocator->register('now', $oRunDate);
         foreach ($aOperationIntervals as $operationInterval) {
             // Set the correct operation interval
             $aConf['maintenance']['operationInterval'] = $operationInterval;
             // Prepare the partially mocked instance of the
             // OX_Maintenance_Statistics_Task_SetUpdateRequirements class with
             // the expectations and return values required for the test run
             $oSetUpdateRequirements = new PartialOX_Maintenance_Statistics_Task_SetUpdateRequirements();
             $oSetUpdateRequirements->expectCallCount('_getMaintenanceStatisticsLastRunInfo', 2);
             $oSetUpdateRequirements->expectCallCount('_getEarliestLoggedDeliveryData', 2);
             $oSetUpdateRequirements->expectAt(0, '_getMaintenanceStatisticsLastRunInfo', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI, $oRunDate));
             $oSetUpdateRequirements->setReturnValueAt(0, '_getMaintenanceStatisticsLastRunInfo', null);
             $oSetUpdateRequirements->expectAt(0, '_getEarliestLoggedDeliveryData', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI));
             $oSetUpdateRequirements->setReturnValueAt(0, '_getEarliestLoggedDeliveryData', null);
             $oSetUpdateRequirements->expectAt(1, '_getMaintenanceStatisticsLastRunInfo', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_HOUR, $oRunDate));
             $oSetUpdateRequirements->setReturnValueAt(1, '_getMaintenanceStatisticsLastRunInfo', null);
             $oSetUpdateRequirements->expectAt(1, '_getEarliestLoggedDeliveryData', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_HOUR));
             $oSetUpdateRequirements->setReturnValueAt(1, '_getEarliestLoggedDeliveryData', null);
             // Create the OX_Maintenance_Statistics_Task_SetUpdateRequirements
             // object and run the task
             $oSetUpdateRequirements->__construct($this);
             $oSetUpdateRequirements->run();
             // Test the results of the task run
             $this->assertFalse($oSetUpdateRequirements->oController->updateIntermediate);
             $this->assertFalse($oSetUpdateRequirements->oController->updateFinal);
         }
     }
     /*-------------------------------------------------------------*/
     /* ONLY LOGGED DELIVERY DATA TESTS                             */
     /*                                                             */
     /* Run tests where with operation intervals of 30 and 60 mins, */
     /* where there is only delivery data in the database (i.e. no  */
     /* previous MSE run) and test that the result is that the MSE  */
     /* will be run from the appropriate date/time.                 */
     /*-------------------------------------------------------------*/
     // Set the value that will be returned for the last MSE run
     // update value, based on the earliest logged data, in terms of
     // the operation interval
     $oEarliestLoggedDataDateOI = new Date('2008-08-12 13:29:59');
     // Set the value that will be returned for the last MSE run
     // update value, based on the earliest logged data, in terms of
     // the hour
     $oEarliestLoggedDataDateHour = new Date('2008-08-12 12:59:59');
     foreach ($aMSERunTimes as $key => $oRunDate) {
         // Register the "current" date/time that the MSE is running at
         $oServiceLocator->register('now', $oRunDate);
         foreach ($aOperationIntervals as $operationInterval) {
             // Set the correct operation interval
             $aConf['maintenance']['operationInterval'] = $operationInterval;
             // Prepare the partially mocked instance of the
             // OX_Maintenance_Statistics_Task_SetUpdateRequirements class with
             // the expectations and return values required for the test run
             $oSetUpdateRequirements = new PartialOX_Maintenance_Statistics_Task_SetUpdateRequirements();
             $oSetUpdateRequirements->expectCallCount('_getMaintenanceStatisticsLastRunInfo', 2);
             $oSetUpdateRequirements->expectCallCount('_getEarliestLoggedDeliveryData', 2);
             $oSetUpdateRequirements->expectAt(0, '_getMaintenanceStatisticsLastRunInfo', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI, $oRunDate));
             $oSetUpdateRequirements->setReturnValueAt(0, '_getMaintenanceStatisticsLastRunInfo', null);
             $oSetUpdateRequirements->expectAt(0, '_getEarliestLoggedDeliveryData', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI));
             $oSetUpdateRequirements->setReturnValueAt(0, '_getEarliestLoggedDeliveryData', $oEarliestLoggedDataDateOI);
             $oSetUpdateRequirements->expectAt(1, '_getMaintenanceStatisticsLastRunInfo', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_HOUR, $oRunDate));
             $oSetUpdateRequirements->setReturnValueAt(1, '_getMaintenanceStatisticsLastRunInfo', null);
             $oSetUpdateRequirements->expectAt(1, '_getEarliestLoggedDeliveryData', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_HOUR));
             $oSetUpdateRequirements->setReturnValueAt(1, '_getEarliestLoggedDeliveryData', $oEarliestLoggedDataDateHour);
             // Create the OX_Maintenance_Statistics_Task_SetUpdateRequirements
             // object and run the task
             $oSetUpdateRequirements->__construct($this);
             $oSetUpdateRequirements->run();
             // Test the results of the task run
             if ($key == 0) {
                 // There is no data logged before "now"; therefore, no udpates will be run
                 $this->assertFalse($oSetUpdateRequirements->oController->updateIntermediate);
                 $this->assertFalse($oSetUpdateRequirements->oController->updateFinal);
             } elseif ($key == 1) {
                 // There is logged data before "now", but a complete operation interval
                 // will only have been passed at this stage IF the operation interval is
                 // 30 minutes; in that case, the MSE will update the intermedaite tables;
                 // otherwise, no updates will be run
                 if ($operationInterval == 30) {
                     $this->assertTrue($oSetUpdateRequirements->oController->updateIntermediate);
                     $this->assertFalse($oSetUpdateRequirements->oController->updateFinal);
                 } else {
                     $this->assertFalse($oSetUpdateRequirements->oController->updateIntermediate);
                     $this->assertFalse($oSetUpdateRequirements->oController->updateFinal);
                 }
             } elseif ($key == 2) {
                 // There is logged data before "now", and a complete operation interval
                 // will have been passed at this stage, and the update boundary is on the
                 // hour, so the MSE will update the intermedaite and final tables
                 $this->assertTrue($oSetUpdateRequirements->oController->updateIntermediate);
                 $this->assertTrue($oSetUpdateRequirements->oController->updateFinal);
             }
         }
     }
     /*-------------------------------------------------------------*/
     /* REAL PAST MSE OI RUN ONLY TESTS                             */
     /*                                                             */
     /* Run tests where with operation intervals of 30 and 60 mins, */
     /* where there the MSE has run previously on the basis of the  */
     /* operation interval, but not for the hour, and test that the */
     /* result is that the MSE will be run from the appropriate     */
     /* date/time.                                                  */
     /*-------------------------------------------------------------*/
     // Set the value that will be returned for the last MSE run
     // update value, based on the the operation interval
     $oLastMSERunOI = new Date('2008-08-12 13:29:59');
     // Set the value that will be returned for the last MSE run
     // update value, based on the earliest logged data, in terms of
     // the hour
     $oEarliestLoggedDataDateHour = new Date('2008-08-12 12:59:59');
     foreach ($aMSERunTimes as $key => $oRunDate) {
         // Register the "current" date/time that the MSE is running at
         $oServiceLocator->register('now', $oRunDate);
         foreach ($aOperationIntervals as $operationInterval) {
             // Set the correct operation interval
             $aConf['maintenance']['operationInterval'] = $operationInterval;
             // Prepare the partially mocked instance of the
             // OX_Maintenance_Statistics_Task_SetUpdateRequirements class with
             // the expectations and return values required for the test run
             $oSetUpdateRequirements = new PartialOX_Maintenance_Statistics_Task_SetUpdateRequirements();
             $oSetUpdateRequirements->expectCallCount('_getMaintenanceStatisticsLastRunInfo', 2);
             $oSetUpdateRequirements->expectCallCount('_getEarliestLoggedDeliveryData', 1);
             $oSetUpdateRequirements->expectAt(0, '_getMaintenanceStatisticsLastRunInfo', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI, $oRunDate));
             $oSetUpdateRequirements->setReturnValueAt(0, '_getMaintenanceStatisticsLastRunInfo', $oLastMSERunOI);
             $oSetUpdateRequirements->expectAt(1, '_getMaintenanceStatisticsLastRunInfo', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_HOUR, $oRunDate));
             $oSetUpdateRequirements->setReturnValueAt(1, '_getMaintenanceStatisticsLastRunInfo', null);
             $oSetUpdateRequirements->expectAt(0, '_getEarliestLoggedDeliveryData', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_HOUR));
             $oSetUpdateRequirements->setReturnValueAt(0, '_getEarliestLoggedDeliveryData', $oEarliestLoggedDataDateHour);
             // Create the OX_Maintenance_Statistics_Task_SetUpdateRequirements
             // object and run the task
             $oSetUpdateRequirements->__construct($this);
             $oSetUpdateRequirements->run();
             // Test the results of the task run
             if ($key == 0) {
                 // There is no data logged before "now"; therefore, no udpates will be run
                 $this->assertFalse($oSetUpdateRequirements->oController->updateIntermediate);
                 $this->assertFalse($oSetUpdateRequirements->oController->updateFinal);
             } elseif ($key == 1) {
                 // There is logged data before "now", but a complete operation interval
                 // will only have been passed at this stage IF the operation interval is
                 // 30 minutes; in that case, the MSE will update the intermedaite tables;
                 // otherwise, no updates will be run
                 if ($operationInterval == 30) {
                     $this->assertTrue($oSetUpdateRequirements->oController->updateIntermediate);
                     $this->assertFalse($oSetUpdateRequirements->oController->updateFinal);
                 } else {
                     $this->assertFalse($oSetUpdateRequirements->oController->updateIntermediate);
                     $this->assertFalse($oSetUpdateRequirements->oController->updateFinal);
                 }
             } elseif ($key == 2) {
                 // There is logged data before "now", and a complete operation interval
                 // will have been passed at this stage, and the update boundary is on the
                 // hour, so the MSE will update the intermedaite and final tables
                 $this->assertTrue($oSetUpdateRequirements->oController->updateIntermediate);
                 $this->assertTrue($oSetUpdateRequirements->oController->updateFinal);
             }
         }
     }
     /*-------------------------------------------------------------*/
     /* REAL PAST MSE RUN TESTS                                     */
     /*                                                             */
     /* Run tests where with operation intervals of 30 and 60 mins, */
     /* where there the MSE has run previously, and test that the   */
     /* result is that the MSE will be run from the appropriate     */
     /* date/time.                                                  */
     /*-------------------------------------------------------------*/
     // Set the value that will be returned for the last MSE run
     // update value, based on the the operation interval
     $oLastMSERunOI = new Date('2008-08-12 13:29:59');
     // Set the value that will be returned for the last MSE run
     // update value, based on the the hour
     $oLastMSERunHour = new Date('2008-08-12 12:59:59');
     foreach ($aMSERunTimes as $key => $oRunDate) {
         // Register the "current" date/time that the MSE is running at
         $oServiceLocator->register('now', $oRunDate);
         foreach ($aOperationIntervals as $operationInterval) {
             // Set the correct operation interval
             $aConf['maintenance']['operationInterval'] = $operationInterval;
             // Prepare the partially mocked instance of the
             // OX_Maintenance_Statistics_Task_SetUpdateRequirements class with
             // the expectations and return values required for the test run
             $oSetUpdateRequirements = new PartialOX_Maintenance_Statistics_Task_SetUpdateRequirements();
             $oSetUpdateRequirements->expectCallCount('_getMaintenanceStatisticsLastRunInfo', 2);
             $oSetUpdateRequirements->expectCallCount('_getEarliestLoggedDeliveryData', 0);
             $oSetUpdateRequirements->expectAt(0, '_getMaintenanceStatisticsLastRunInfo', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI, $oRunDate));
             $oSetUpdateRequirements->setReturnValueAt(0, '_getMaintenanceStatisticsLastRunInfo', $oLastMSERunOI);
             $oSetUpdateRequirements->expectAt(1, '_getMaintenanceStatisticsLastRunInfo', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_HOUR, $oRunDate));
             $oSetUpdateRequirements->setReturnValueAt(1, '_getMaintenanceStatisticsLastRunInfo', $oLastMSERunHour);
             // Create the OX_Maintenance_Statistics_Task_SetUpdateRequirements
             // object and run the task
             $oSetUpdateRequirements->__construct($this);
             $oSetUpdateRequirements->run();
             // Test the results of the task run
             if ($key == 0) {
                 // There is no data logged before "now"; therefore, no udpates will be run
                 $this->assertFalse($oSetUpdateRequirements->oController->updateIntermediate);
                 $this->assertFalse($oSetUpdateRequirements->oController->updateFinal);
             } elseif ($key == 1) {
                 // There is logged data before "now", but a complete operation interval
                 // will only have been passed at this stage IF the operation interval is
                 // 30 minutes; in that case, the MSE will update the intermedaite tables;
                 // otherwise, no updates will be run
                 if ($operationInterval == 30) {
                     $this->assertTrue($oSetUpdateRequirements->oController->updateIntermediate);
                     $this->assertFalse($oSetUpdateRequirements->oController->updateFinal);
                 } else {
                     $this->assertFalse($oSetUpdateRequirements->oController->updateIntermediate);
                     $this->assertFalse($oSetUpdateRequirements->oController->updateFinal);
                 }
             } elseif ($key == 2) {
                 // There is logged data before "now", and a complete operation interval
                 // will have been passed at this stage, and the update boundary is on the
                 // hour, so the MSE will update the intermedaite and final tables
                 $this->assertTrue($oSetUpdateRequirements->oController->updateIntermediate);
                 $this->assertTrue($oSetUpdateRequirements->oController->updateFinal);
             }
         }
     }
     // Reset the testing environment
     TestEnv::restoreEnv();
 }
 /**
  * A method to test the create required tables method.
  *
  * Requirements:
  * Test 1: Test with the OA_DB_Table_Core class, using
  *         the banners table.
  */
 function testCreateRequiredTables()
 {
     $conf =& $GLOBALS['_MAX']['CONF'];
     $conf['table']['prefix'] = '';
     $oDbh =& OA_DB::singleton();
     $oTable =& OA_DB_Table_Core::singleton();
     $oTable->createRequiredTables('banners');
     $aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
     $this->assertEqual($aExistingTables[0], 'accounts');
     $this->assertEqual($aExistingTables[1], 'agency');
     $this->assertEqual($aExistingTables[2], 'banners');
     $this->assertEqual($aExistingTables[3], 'campaigns');
     $this->assertEqual($aExistingTables[4], 'clients');
     $oTable->dropTable('accounts');
     $oTable->dropTable('agency');
     $oTable->dropTable('banners');
     $oTable->dropTable('campaigns');
     $oTable->dropTable('clients');
     TestEnv::restoreConfig();
 }
 /**
  * Tests creating/dropping all of the core tables.
  *
  * Requirements:
  * Test 1: Test that all core tables can be created and dropped.
  */
 function testAllCoreTables()
 {
     // Test 1
     $conf =& $GLOBALS['_MAX']['CONF'];
     $conf['table']['prefix'] = '';
     $oDbh =& OA_DB::singleton();
     $oTable =& OA_DB_Table_Core::singleton();
     $oTable->dropAllTables();
     $aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
     if (PEAR::isError($aExistingTables)) {
         // Can't talk to database, test fails!
         $this->assertTrue(false);
     }
     $this->assertEqual(count($aExistingTables), 0);
     $oTable =& OA_DB_Table_Core::singleton();
     $oTable->createAllTables();
     $aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
     foreach ($conf['table'] as $key => $tableName) {
         if ($key == 'prefix' || $key == 'type') {
             continue;
         }
         // Test that the tables exists
         $this->assertTrue(in_array($tableName, $aExistingTables), 'does not exist: ' . $tableName . ' (found in conf file)');
     }
     $oTable->dropAllTables();
     $aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
     if (PEAR::isError($aExistingTables)) {
         // Can't talk to database, test fails!
         $this->assertTrue(false);
     }
     $this->assertEqual(count($aExistingTables), 0);
     // Ensure the singleton is destroyed
     $oTable->destroy();
 }
 /**
  * Tests the _getEarliestLoggedDeliveryData() method.
  */
 function test_getEarliestLoggedDeliveryData()
 {
     // Create a reference to the OpenX configuration, and set it to
     // 15 minutes
     $aConf =& $GLOBALS['_MAX']['CONF'];
     $aConf['maintenance']['operationInterval'] = 15;
     // Prepare the OX_Maintenance_Statistics_Task_SetUpdateRequirements class to test with
     $oSetUpdateRequirements = new OX_Maintenance_Statistics_Task_SetUpdateRequirements();
     // Test 1: There are no deliveryLog group plugins installed, test that null is returned
     $oDate = $oSetUpdateRequirements->_getEarliestLoggedDeliveryData(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI);
     $this->assertNull($oDate);
     // Create the "application_variable" table required for installing the plugin
     $oTables =& OA_DB_Table_Core::singleton();
     $oTables->createTable('application_variable');
     // Setup the default OpenX delivery logging plugin for the test
     TestEnv::installPluginPackage('openXDeliveryLog', false);
     // Test 2: There is no delivery data logged, test that null is returned
     $oDate = $oSetUpdateRequirements->_getEarliestLoggedDeliveryData(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI);
     $this->assertNull($oDate);
     // Ask the appropriate default OpenX delivery logging plugin component
     // to log a click
     require_once MAX_PATH . $aConf['pluginPaths']['plugins'] . '/deliveryLog/oxLogClick/logClick.delivery.php';
     $GLOBALS['_MAX']['deliveryData'] = array('interval_start' => '2008-08-12 14:15:00', 'creative_id' => 1, 'zone_id' => 1);
     Plugin_deliveryLog_oxLogClick_logClick_Delivery_logClick();
     // Test 3: Test with just the one click logged, and ensure that the correct
     //         date/time is returned
     $oDate = $oSetUpdateRequirements->_getEarliestLoggedDeliveryData(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI);
     $this->assertEqual($oDate, new Date('2008-08-12 14:14:59'));
     // Ask the appropriate default OpenX delivery logging plugin component
     // to log a later click
     $GLOBALS['_MAX']['deliveryData'] = array('interval_start' => '2008-08-12 14:30:00', 'creative_id' => 1, 'zone_id' => 1);
     Plugin_deliveryLog_oxLogClick_logClick_Delivery_logClick();
     // Test 4: Test with just the two clicks logged, and ensure that the correct
     //         date/time is returned (i.e. unchanged from the last test)
     $oDate = $oSetUpdateRequirements->_getEarliestLoggedDeliveryData(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI);
     $this->assertEqual($oDate, new Date('2008-08-12 14:14:59'));
     // Ask the appropriate default OpenX delivery logging plugin component
     // to log an earlier click
     $GLOBALS['_MAX']['deliveryData'] = array('interval_start' => '2008-08-12 14:00:00', 'creative_id' => 1, 'zone_id' => 1);
     Plugin_deliveryLog_oxLogClick_logClick_Delivery_logClick();
     // Test 5: Test with just the three clicks logged, and ensure that the correct
     //         date/time is returned (i.e. earlier than the last tests)
     $oDate = $oSetUpdateRequirements->_getEarliestLoggedDeliveryData(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI);
     $this->assertEqual($oDate, new Date('2008-08-12 13:59:59'));
     // Ask the appropriate default OpenX delivery logging plugin component
     // to log an earlier impression
     require_once MAX_PATH . $aConf['pluginPaths']['plugins'] . '/deliveryLog/oxLogImpression/logImpression.delivery.php';
     $GLOBALS['_MAX']['deliveryData'] = array('interval_start' => '2008-08-12 13:45:00', 'creative_id' => 1, 'zone_id' => 1);
     Plugin_deliveryLog_oxLogImpression_logImpression_Delivery_logImpression();
     // Test 6: Test with just the three clicks and one impression logged, and
     //         ensure that the correct date/time is returned (i.e. based on
     //         the earliest data, which is the impression).
     $oDate = $oSetUpdateRequirements->_getEarliestLoggedDeliveryData(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI);
     $this->assertEqual($oDate, new Date('2008-08-12 13:44:59'));
     // Test 7: Re-test, but calling for the date/time returned to be based
     //         on the hour boundary, not the operation interval boundary
     $oDate = $oSetUpdateRequirements->_getEarliestLoggedDeliveryData(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_HOUR);
     $this->assertEqual($oDate, new Date('2008-08-12 12:59:59'));
     // Uninstall the installed plugin
     TestEnv::uninstallPluginPackage('openXDeliveryLog', false);
     // Reset the testing environment
     TestEnv::restoreEnv();
 }
 /**
  * A method to test the main run() method.
  */
 function testRun()
 {
     $aConf =& $GLOBALS['_MAX']['CONF'];
     $aConf['maintenance']['operationInterval'] = 60;
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oFactory = new OX_Dal_Maintenance_Statistics_Factory();
     $oDalMaintenanceStatsticsClassName = $oFactory->deriveClassName();
     // Test 1: Run, with the migration required but with no plugins installed
     $oNowDate = new Date('2008-08-28 09:01:00');
     $oServiceLocator->register('now', $oNowDate);
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oMaintenanceStatistics->updateIntermediate = true;
     $oMaintenanceStatistics->oLastDateIntermediate = new Date('2008-08-28 07:59:59');
     $oMaintenanceStatistics->oUpdateIntermediateToDate = new Date('2008-08-28 08:59:59');
     Mock::generatePartial($oDalMaintenanceStatsticsClassName, 'MockOX_Dal_Maintenance_Statistics_Test_1', array('summariseBucketsRaw', 'summariseBucketsRawSupplementary', 'summariseBucketsAggregate', 'migrateRawRequests', 'migrateRawImpressions', 'migrateRawClicks'));
     $oDal = new MockOX_Dal_Maintenance_Statistics_Test_1($this);
     $oDal->expectNever('summariseBucketsRaw');
     $oDal->expectNever('summariseBucketsRawSupplementary');
     $oDal->expectNever('summariseBucketsAggregate');
     $oDal->expectNever('migrateRawRequests');
     $oDal->expectNever('migrateRawImpressions');
     $oDal->expectNever('migrateRawClicks');
     $oDal->OX_Dal_Maintenance_Statistics();
     $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
     $oSummariseIntermediate = new OX_Maintenance_Statistics_Task_MigrateBucketData();
     $oSummariseIntermediate->run();
     $oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
     $oDal->tally();
     // Create the "application_variable" table required for installing the plugin
     $oTables =& OA_DB_Table_Core::singleton();
     $oTables->createTable('application_variable');
     // Setup the default OpenX delivery logging plugin for the next test
     TestEnv::installPluginPackage('openXDeliveryLog', false);
     // Test 2: Run, with plugins installed, but with the migration not required
     $oNowDate = new Date('2008-08-28 09:01:00');
     $oServiceLocator->register('now', $oNowDate);
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oMaintenanceStatistics->updateIntermediate = false;
     $oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     Mock::generatePartial($oDalMaintenanceStatsticsClassName, 'MockOX_Dal_Maintenance_Statistics_Test_2', array('summariseBucketsRaw', 'summariseBucketsRawSupplementary', 'summariseBucketsAggregate', 'migrateRawRequests', 'migrateRawImpressions', 'migrateRawClicks'));
     $oDal = new MockOX_Dal_Maintenance_Statistics_Test_2($this);
     $oDal->expectNever('summariseBucketsRaw');
     $oDal->expectNever('summariseBucketsRawSupplementary');
     $oDal->expectNever('summariseBucketsAggregate');
     $oDal->expectNever('migrateRawRequests');
     $oDal->expectNever('migrateRawImpressions');
     $oDal->expectNever('migrateRawClicks');
     $oDal->OX_Dal_Maintenance_Statistics();
     $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
     $oSummariseIntermediate = new OX_Maintenance_Statistics_Task_MigrateBucketData();
     $oSummariseIntermediate->run();
     $oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
     $oDal->tally();
     // Test 3: Run, with plugins installed and with the migration required for a single
     //         operation interval
     $oNowDate = new Date('2008-08-28 09:01:00');
     $oServiceLocator->register('now', $oNowDate);
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oMaintenanceStatistics->updateIntermediate = true;
     $oMaintenanceStatistics->oLastDateIntermediate = new Date('2008-08-28 07:59:59');
     $oMaintenanceStatistics->oUpdateIntermediateToDate = new Date('2008-08-28 08:59:59');
     $oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     Mock::generatePartial($oDalMaintenanceStatsticsClassName, 'MockOX_Dal_Maintenance_Statistics_Test_3', array('summariseBucketsRaw', 'summariseBucketsRawSupplementary', 'summariseBucketsAggregate', 'migrateRawRequests', 'migrateRawImpressions', 'migrateRawClicks'));
     $oDal = new MockOX_Dal_Maintenance_Statistics_Test_3($this);
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogConversion', 'logConversion');
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectOnce('summariseBucketsRaw', array($aConf['table']['prefix'] . 'data_intermediate_ad_connection', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogConversion', 'logConversionVariable');
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectOnce('summariseBucketsRawSupplementary', array($aConf['table']['prefix'] . 'data_intermediate_ad_variable_value', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $aMap = array();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogClick', 'logClick');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogImpression', 'logImpression');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogRequest', 'logRequest');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectOnce('summariseBucketsAggregate', array($aConf['table']['prefix'] . 'data_intermediate_ad', $aMap, array('start' => $oStartDate, 'end' => $oEndDate), array('operation_interval' => '60', 'operation_interval_id' => OX_OperationInterval::convertDateToOperationIntervalID($oStartDate), 'interval_start' => "'2008-08-28 08:00:00'", 'interval_end' => "'2008-08-28 08:59:59'", 'creative_id' => 0, 'updated' => "'2008-08-28 09:01:00'")));
     $oDal->expectNever('migrateRawRequests');
     $oDal->expectNever('migrateRawImpressions');
     $oDal->expectNever('migrateRawClicks');
     $oDal->OX_Dal_Maintenance_Statistics();
     $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
     $oSummariseIntermediate = new OX_Maintenance_Statistics_Task_MigrateBucketData();
     $oSummariseIntermediate->run();
     $oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
     $oDal->tally();
     // Test 4: Run, with plugins installed and with the migration required for a single
     //         operation interval + migration of raw data set to occur
     $doApplication_variable = OA_Dal::factoryDO('application_variable');
     $doApplication_variable->name = 'mse_process_raw';
     $doApplication_variable->value = '1';
     $doApplication_variable->insert();
     $oNowDate = new Date('2008-08-28 09:01:00');
     $oServiceLocator->register('now', $oNowDate);
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oMaintenanceStatistics->updateIntermediate = true;
     $oMaintenanceStatistics->oLastDateIntermediate = new Date('2008-08-28 07:59:59');
     $oMaintenanceStatistics->oUpdateIntermediateToDate = new Date('2008-08-28 08:59:59');
     $oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     Mock::generatePartial($oDalMaintenanceStatsticsClassName, 'MockOX_Dal_Maintenance_Statistics_Test_4', array('summariseBucketsRaw', 'summariseBucketsRawSupplementary', 'summariseBucketsAggregate', 'migrateRawRequests', 'migrateRawImpressions', 'migrateRawClicks'));
     $oDal = new MockOX_Dal_Maintenance_Statistics_Test_4($this);
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogConversion', 'logConversion');
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectOnce('summariseBucketsRaw', array($aConf['table']['prefix'] . 'data_intermediate_ad_connection', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogConversion', 'logConversionVariable');
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectOnce('summariseBucketsRawSupplementary', array($aConf['table']['prefix'] . 'data_intermediate_ad_variable_value', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $aMap = array();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogClick', 'logClick');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogImpression', 'logImpression');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogRequest', 'logRequest');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectOnce('summariseBucketsAggregate', array($aConf['table']['prefix'] . 'data_intermediate_ad', $aMap, array('start' => $oStartDate, 'end' => $oEndDate), array('operation_interval' => '60', 'operation_interval_id' => OX_OperationInterval::convertDateToOperationIntervalID($oStartDate), 'interval_start' => "'2008-08-28 08:00:00'", 'interval_end' => "'2008-08-28 08:59:59'", 'creative_id' => 0, 'updated' => "'2008-08-28 09:01:00'")));
     $oDal->expectOnce('migrateRawRequests', array($oStartDate, $oEndDate));
     $oDal->expectOnce('migrateRawImpressions', array($oStartDate, $oEndDate));
     $oDal->expectOnce('migrateRawClicks', array($oStartDate, $oEndDate));
     $oDal->OX_Dal_Maintenance_Statistics();
     $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
     $oSummariseIntermediate = new OX_Maintenance_Statistics_Task_MigrateBucketData();
     $oSummariseIntermediate->run();
     $oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
     $oDal->tally();
     $doApplication_variable = OA_Dal::factoryDO('application_variable');
     $doApplication_variable->name = 'mse_process_raw';
     $doApplication_variable->value = '1';
     $doApplication_variable->find();
     $rows = $doApplication_variable->getRowCount();
     $this->assertEqual($rows, 0);
     // Test 5: Run, with plugins installed and with the migration required for multiple
     //         operation intervals
     $oNowDate = new Date('2008-08-28 11:01:00');
     $oServiceLocator->register('now', $oNowDate);
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oMaintenanceStatistics->updateIntermediate = true;
     $oMaintenanceStatistics->oLastDateIntermediate = new Date('2008-08-28 07:59:59');
     $oMaintenanceStatistics->oUpdateIntermediateToDate = new Date('2008-08-28 10:59:59');
     $oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     Mock::generatePartial($oDalMaintenanceStatsticsClassName, 'MockOX_Dal_Maintenance_Statistics_Test_5', array('summariseBucketsRaw', 'summariseBucketsRawSupplementary', 'summariseBucketsAggregate', 'migrateRawRequests', 'migrateRawImpressions', 'migrateRawClicks'));
     $oDal = new MockOX_Dal_Maintenance_Statistics_Test_5($this);
     $oDal->expectCallCount('summariseBucketsRaw', 3);
     $oDal->expectCallCount('summariseBucketsRawSupplementary', 3);
     $oDal->expectCallCount('summariseBucketsAggregate', 3);
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogConversion', 'logConversion');
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(0, 'summariseBucketsRaw', array($aConf['table']['prefix'] . 'data_intermediate_ad_connection', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oStartDate = new Date('2008-08-28 08:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 10:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(1, 'summariseBucketsRaw', array($aConf['table']['prefix'] . 'data_intermediate_ad_connection', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oStartDate = new Date('2008-08-28 09:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 11:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(2, 'summariseBucketsRaw', array($aConf['table']['prefix'] . 'data_intermediate_ad_connection', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogConversion', 'logConversionVariable');
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(0, 'summariseBucketsRawSupplementary', array($aConf['table']['prefix'] . 'data_intermediate_ad_variable_value', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oStartDate = new Date('2008-08-28 08:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 10:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(1, 'summariseBucketsRawSupplementary', array($aConf['table']['prefix'] . 'data_intermediate_ad_variable_value', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oStartDate = new Date('2008-08-28 09:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 11:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(2, 'summariseBucketsRawSupplementary', array($aConf['table']['prefix'] . 'data_intermediate_ad_variable_value', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $aMap = array();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogClick', 'logClick');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogImpression', 'logImpression');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogRequest', 'logRequest');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(0, 'summariseBucketsAggregate', array($aConf['table']['prefix'] . 'data_intermediate_ad', $aMap, array('start' => $oStartDate, 'end' => $oEndDate), array('operation_interval' => '60', 'operation_interval_id' => OX_OperationInterval::convertDateToOperationIntervalID($oStartDate), 'interval_start' => "'2008-08-28 08:00:00'", 'interval_end' => "'2008-08-28 08:59:59'", 'creative_id' => 0, 'updated' => "'2008-08-28 11:01:00'")));
     $oStartDate = new Date('2008-08-28 08:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 10:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(1, 'summariseBucketsAggregate', array($aConf['table']['prefix'] . 'data_intermediate_ad', $aMap, array('start' => $oStartDate, 'end' => $oEndDate), array('operation_interval' => '60', 'operation_interval_id' => OX_OperationInterval::convertDateToOperationIntervalID($oStartDate), 'interval_start' => "'2008-08-28 09:00:00'", 'interval_end' => "'2008-08-28 09:59:59'", 'creative_id' => 0, 'updated' => "'2008-08-28 11:01:00'")));
     $oStartDate = new Date('2008-08-28 09:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 11:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(2, 'summariseBucketsAggregate', array($aConf['table']['prefix'] . 'data_intermediate_ad', $aMap, array('start' => $oStartDate, 'end' => $oEndDate), array('operation_interval' => '60', 'operation_interval_id' => OX_OperationInterval::convertDateToOperationIntervalID($oStartDate), 'interval_start' => "'2008-08-28 10:00:00'", 'interval_end' => "'2008-08-28 10:59:59'", 'creative_id' => 0, 'updated' => "'2008-08-28 11:01:00'")));
     $oDal->expectNever('migrateRawRequests');
     $oDal->expectNever('migrateRawImpressions');
     $oDal->expectNever('migrateRawClicks');
     $oDal->OX_Dal_Maintenance_Statistics();
     $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
     $oSummariseIntermediate = new OX_Maintenance_Statistics_Task_MigrateBucketData();
     $oSummariseIntermediate->run();
     $oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
     $oDal->tally();
     // Test 6: Run, with plugins installed and with the migration required for multiple
     //         operation intervals + migration of raw data set to occur
     $doApplication_variable = OA_Dal::factoryDO('application_variable');
     $doApplication_variable->name = 'mse_process_raw';
     $doApplication_variable->value = '1';
     $doApplication_variable->insert();
     $oNowDate = new Date('2008-08-28 11:01:00');
     $oServiceLocator->register('now', $oNowDate);
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oMaintenanceStatistics->updateIntermediate = true;
     $oMaintenanceStatistics->oLastDateIntermediate = new Date('2008-08-28 07:59:59');
     $oMaintenanceStatistics->oUpdateIntermediateToDate = new Date('2008-08-28 10:59:59');
     $oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     Mock::generatePartial($oDalMaintenanceStatsticsClassName, 'MockOX_Dal_Maintenance_Statistics_Test_6', array('summariseBucketsRaw', 'summariseBucketsRawSupplementary', 'summariseBucketsAggregate', 'migrateRawRequests', 'migrateRawImpressions', 'migrateRawClicks'));
     $oDal = new MockOX_Dal_Maintenance_Statistics_Test_6($this);
     $oDal->expectCallCount('summariseBucketsRaw', 3);
     $oDal->expectCallCount('summariseBucketsRawSupplementary', 3);
     $oDal->expectCallCount('summariseBucketsAggregate', 3);
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogConversion', 'logConversion');
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(0, 'summariseBucketsRaw', array($aConf['table']['prefix'] . 'data_intermediate_ad_connection', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oStartDate = new Date('2008-08-28 08:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 10:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(1, 'summariseBucketsRaw', array($aConf['table']['prefix'] . 'data_intermediate_ad_connection', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oStartDate = new Date('2008-08-28 09:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 11:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(2, 'summariseBucketsRaw', array($aConf['table']['prefix'] . 'data_intermediate_ad_connection', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogConversion', 'logConversionVariable');
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(0, 'summariseBucketsRawSupplementary', array($aConf['table']['prefix'] . 'data_intermediate_ad_variable_value', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oStartDate = new Date('2008-08-28 08:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 10:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(1, 'summariseBucketsRawSupplementary', array($aConf['table']['prefix'] . 'data_intermediate_ad_variable_value', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oStartDate = new Date('2008-08-28 09:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 11:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(2, 'summariseBucketsRawSupplementary', array($aConf['table']['prefix'] . 'data_intermediate_ad_variable_value', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $aMap = array();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogClick', 'logClick');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogImpression', 'logImpression');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogRequest', 'logRequest');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(0, 'summariseBucketsAggregate', array($aConf['table']['prefix'] . 'data_intermediate_ad', $aMap, array('start' => $oStartDate, 'end' => $oEndDate), array('operation_interval' => '60', 'operation_interval_id' => OX_OperationInterval::convertDateToOperationIntervalID($oStartDate), 'interval_start' => "'2008-08-28 08:00:00'", 'interval_end' => "'2008-08-28 08:59:59'", 'creative_id' => 0, 'updated' => "'2008-08-28 11:01:00'")));
     $oStartDate = new Date('2008-08-28 08:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 10:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(1, 'summariseBucketsAggregate', array($aConf['table']['prefix'] . 'data_intermediate_ad', $aMap, array('start' => $oStartDate, 'end' => $oEndDate), array('operation_interval' => '60', 'operation_interval_id' => OX_OperationInterval::convertDateToOperationIntervalID($oStartDate), 'interval_start' => "'2008-08-28 09:00:00'", 'interval_end' => "'2008-08-28 09:59:59'", 'creative_id' => 0, 'updated' => "'2008-08-28 11:01:00'")));
     $oStartDate = new Date('2008-08-28 09:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 11:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(2, 'summariseBucketsAggregate', array($aConf['table']['prefix'] . 'data_intermediate_ad', $aMap, array('start' => $oStartDate, 'end' => $oEndDate), array('operation_interval' => '60', 'operation_interval_id' => OX_OperationInterval::convertDateToOperationIntervalID($oStartDate), 'interval_start' => "'2008-08-28 10:00:00'", 'interval_end' => "'2008-08-28 10:59:59'", 'creative_id' => 0, 'updated' => "'2008-08-28 11:01:00'")));
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(0, 'migrateRawRequests', array($oStartDate, $oEndDate));
     $oDal->expectAt(0, 'migrateRawImpressions', array($oStartDate, $oEndDate));
     $oDal->expectAt(0, 'migrateRawClicks', array($oStartDate, $oEndDate));
     $oStartDate = new Date('2008-08-28 08:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 10:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(1, 'migrateRawRequests', array($oStartDate, $oEndDate));
     $oDal->expectAt(1, 'migrateRawImpressions', array($oStartDate, $oEndDate));
     $oDal->expectAt(1, 'migrateRawClicks', array($oStartDate, $oEndDate));
     $oStartDate = new Date('2008-08-28 09:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 11:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(2, 'migrateRawRequests', array($oStartDate, $oEndDate));
     $oDal->expectAt(2, 'migrateRawImpressions', array($oStartDate, $oEndDate));
     $oDal->expectAt(2, 'migrateRawClicks', array($oStartDate, $oEndDate));
     $oDal->OX_Dal_Maintenance_Statistics();
     $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
     $oSummariseIntermediate = new OX_Maintenance_Statistics_Task_MigrateBucketData();
     $oSummariseIntermediate->run();
     $oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
     $oDal->tally();
     $doApplication_variable = OA_Dal::factoryDO('application_variable');
     $doApplication_variable->name = 'mse_process_raw';
     $doApplication_variable->value = '1';
     $doApplication_variable->find();
     $rows = $doApplication_variable->getRowCount();
     $this->assertEqual($rows, 0);
     // Uninstall the installed plugins
     TestEnv::uninstallPluginPackage('openXDeliveryLog', false);
     // Reset the testing environment
     TestEnv::restoreEnv();
 }
Example #10
0
 /**
  * Empties all tables and resets all sequences.
  * Note: this method is not transaction safe - it is conceiveable another process could
  * insert data into the tables after they have been truncated but before the sequence is reset.
  *
  */
 static function truncateAllTables()
 {
     $oTable =& OA_DB_Table_Core::singleton();
     $oTable->truncateAllTables();
     $oTable->resetAllSequences();
 }