function test_runScript()
 {
     $GLOBALS['_MAX']['CONF']['table']['prefix'] = $this->prefix;
     $oUpgrade = new OA_Upgrade();
     $oUpgrade->initDatabaseConnection();
     $oDbh =& $oUpgrade->oDbh;
     $oTable = new OA_DB_Table();
     $testfile = MAX_PATH . "/etc/changes/tests/data/schema_tables_core_dashboard.xml";
     $oTable->init($testfile);
     $table = 'preference';
     $aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
     if (in_array($this->prefix . $table, $aExistingTables)) {
         $this->assertTrue($oTable->dropTable($this->prefix . $table), 'error dropping ' . $this->prefix . $table);
     }
     $this->assertTrue($oTable->createTable($table), 'error creating ' . $this->prefix . $table);
     $aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
     $this->assertTrue(in_array($this->prefix . $table, $aExistingTables), $this->prefix . $table . ' table not found');
     $this->assertTrue($oUpgrade->runScript('postscript_openads_upgrade_2.3.36-beta-rc1.php'));
     $aExistingColumns = $oDbh->manager->listTableFields($this->prefix . $table);
     $aColumns = array('ad_clicks_sum', 'ad_views_sum', 'ad_clicks_per_second', 'ad_views_per_second', 'ad_cs_data_last_sent', 'ad_cs_data_last_sent', 'ad_cs_data_last_received');
     foreach ($aColumns as $column) {
         $this->assertFalse(in_array($column, $aExistingColumns, $column . ' found in column list'));
     }
     TestEnv::restoreConfig();
     TestEnv::restoreEnv();
 }
 function tearDown()
 {
     if (file_exists(MAX_PATH . '/var/' . OX_getHostName() . '.conf.php')) {
         @unlink(MAX_PATH . '/var/' . OX_getHostName() . '.conf.php');
     }
     $_SERVER['HTTP_HOST'] = $this->host;
     // Resume normal service with regards to the configuration file writer...
     unset($GLOBALS['override_TEST_ENVIRONMENT_RUNNING']);
     TestEnv::restoreConfig();
     parent::tearDown();
 }
 /**
  * The method to test the factory's getRawBucketProcessingStrategy()
  * methiod.
  */
 function testGetRawBucketProcessingStrategy()
 {
     $aConf =& $GLOBALS['_MAX']['CONF'];
     // Test the creation of an edge/aggregate server MySQL strategy class
     $aConf['lb']['enabled'] = true;
     $aConf['database']['type'] = 'mysql';
     $oProcessingStrategy = OX_Extension_DeliveryLog_BucketProcessingStrategyFactory::getRawBucketProcessingStrategy($aConf['database']['type']);
     $this->assertTrue(is_a($oProcessingStrategy, 'OX_Extension_DeliveryLog_RawBucketProcessingStrategyMysql'));
     $aConf['database']['type'] = 'pgsql';
     $oProcessingStrategy = OX_Extension_DeliveryLog_BucketProcessingStrategyFactory::getRawBucketProcessingStrategy($aConf['database']['type']);
     $this->assertTrue(is_a($oProcessingStrategy, 'OX_Extension_DeliveryLog_RawBucketProcessingStrategyPgsql'));
     // Restore the configuration file
     TestEnv::restoreConfig();
 }
 /**
  * A method to test the MAX_Delivery_log_logVariableValues() function.
  */
 function test_MAX_Delivery_log_logVariableValues()
 {
     $aConf =& $GLOBALS['_MAX']['CONF'];
     $aConf['maintenance']['operationInterval'] = 60;
     $GLOBALS['_MAX']['NOW'] = time();
     $oNowDate = new Date($GLOBALS['_MAX']['NOW']);
     // Test to ensure that the openXDeliveryLog plugin's data bucket
     // table does not exist
     $oTable = new OA_DB_Table();
     $tableExists = $oTable->extistsTable($aConf['table']['prefix'] . 'data_bkt_a_var');
     $this->assertFalse($tableExists);
     // Test calling the main logging function without any plugins installed,
     // to ensure that this does not result in any kind of error
     $aVariables = array(55 => array('variable_id' => 55, 'tracker_id' => 1, 'name' => 'fooVar', 'type' => 'string', 'variablecode' => ''), 66 => array('variable_id' => 66, 'tracker_id' => 1, 'name' => 'barVar', 'type' => 'string', 'variablecode' => ''));
     $_GET['fooVar'] = 'foo';
     $_GET['barVar'] = 'bar';
     MAX_Delivery_log_logVariableValues($aVariables, 1, 1, 'singleDB');
     // Install the openXDeliveryLog plugin
     TestEnv::installPluginPackage('openXDeliveryLog', false);
     // Test to ensure that the openXDeliveryLog plugin's data bucket
     // table now does exist
     $tableExists = $oTable->extistsTable($aConf['table']['prefix'] . 'data_bkt_a_var');
     $this->assertTrue($tableExists);
     // Ensure that there are is nothing logged in the data bucket table
     $doData_bkt_a_var = OA_Dal::factoryDO('data_bkt_a_var');
     $doData_bkt_a_var->find();
     $rows = $doData_bkt_a_var->getRowCount();
     $this->assertEqual($rows, 0);
     // Call the variable value logging function
     MAX_Delivery_log_logVariableValues($aVariables, 1, 1, 'singleDB');
     // Ensure that the data was logged correctly
     $doData_bkt_a_var = OA_Dal::factoryDO('data_bkt_a_var');
     $doData_bkt_a_var->find();
     $rows = $doData_bkt_a_var->getRowCount();
     $this->assertEqual($rows, 2);
     $doData_bkt_a_var = OA_Dal::factoryDO('data_bkt_a_var');
     $doData_bkt_a_var->server_conv_id = 1;
     $doData_bkt_a_var->server_raw_ip = 'singleDB';
     $doData_bkt_a_var->tracker_variable_id = 55;
     $doData_bkt_a_var->find();
     $rows = $doData_bkt_a_var->getRowCount();
     $this->assertEqual($rows, 1);
     $doData_bkt_a_var->fetch();
     $this->assertEqual($doData_bkt_a_var->value, 'foo');
     $this->assertEqual($doData_bkt_a_var->date_time, $oNowDate->format('%Y-%m-%d %H:%M:%S'));
     // Uninstall the openXDeliveryLog plugin
     TestEnv::uninstallPluginPackage('openXDeliveryLog', false);
     // Restore the test configuration file
     TestEnv::restoreConfig();
 }
 function test_setAllExtensions()
 {
     $oExtension = new OX_Extension();
     $GLOBALS['_MAX']['CONF']['pluginPaths']['plugins'] = '/lib/OX/tests/data/plugins/';
     $GLOBALS['_MAX']['CONF']['pluginPaths']['packages'] = '/lib/OX/tests/data/plugins/etc/';
     $oExtension->setAllExtensions();
     $aResult = $oExtension->aExtensions;
     $this->assertEqual(count($aResult), 3);
     sort($aResult);
     $this->assertEqual($aResult[0], 'admin');
     $this->assertEqual($aResult[1], 'test');
     $this->assertEqual($aResult[2], 'test1');
     TestEnv::restoreConfig();
 }
 /**
  * A method to test the run() method.
  */
 function testRun()
 {
     $oServiceLocator =& OA_ServiceLocator::instance();
     $aConf['maintenance']['operationInterval'] = 60;
     // Test 1: Test with the bucket data not having been migrated,
     //         and ensure that the DAL calls to de-duplicate and
     //         reject conversions are not made
     // Set the controller class
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     // Mock the MSE DAL used to de-duplicate conversions,
     // and set the expectations of the calls to the DAL
     Mock::generate('OX_Dal_Maintenance_Statistics');
     $oDal = new MockOX_Dal_Maintenance_Statistics($this);
     $oDal->expectNever('manageConversions');
     $oDal->__construct();
     $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
     // Set the controlling class' status and test
     $oManageConversions = new OX_Maintenance_Statistics_Task_ManageConversions();
     $oManageConversions->oController->updateIntermediate = false;
     $oManageConversions->run();
     $oDal->tally();
     // Test 2: Test with the bucket data having been migrated, and
     //         ensure that the DALL calls to de-duplicate and reject
     //         conversions are made correctly
     // Set the controller class
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     // Mock the MSE DAL used to de-duplicate conversions,
     // and set the expectations of the calls to the DAL
     Mock::generate('OX_Dal_Maintenance_Statistics');
     $oDal = new MockOX_Dal_Maintenance_Statistics($this);
     $oDate = new Date('2008-09-08 16:59:59');
     $oDate->addSeconds(1);
     $oDal->expectOnce('manageConversions', array($oDate, new Date('2008-09-08 17:59:59')));
     $oDal->__construct();
     $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
     // Set the controlling class' status and test
     $oManageConversions = new OX_Maintenance_Statistics_Task_ManageConversions();
     $oManageConversions->oController->updateIntermediate = true;
     $oManageConversions->oController->oLastDateIntermediate = new Date('2008-09-08 16:59:59');
     $oManageConversions->oController->oUpdateIntermediateToDate = new Date('2008-09-08 17:59:59');
     $oManageConversions->run();
     $oDal->tally();
     TestEnv::restoreConfig();
 }
 function test_runScript()
 {
     $oUpgrade = new OA_Upgrade();
     $this->oConfiguration = $oUpgrade->oConfiguration;
     $oUpgrade->initDatabaseConnection();
     $oDbh =& $oUpgrade->oDbh;
     $oTable = new OA_DB_Table();
     $table = 'database_action';
     $testfile = MAX_PATH . "/lib/OA/Upgrade/tests/data/{$table}.xml";
     $oTable->init($testfile);
     $this->assertTrue($oTable->dropTable($this->prefix . $table), 'error dropping ' . $this->prefix . $table);
     $this->assertTrue($oTable->createTable($table), 'error creating ' . $this->prefix . $table);
     $aExistingTables = OA_DB_Table::listOATablesCaseSensitive();
     $this->assertTrue(in_array($this->prefix . $table, $aExistingTables), 'old database_action table not found');
     $this->assertTrue($oUpgrade->runScript('prescript_openads_upgrade_2.3.33-beta-rc4.php'));
     TestEnv::restoreConfig();
 }
 function test_cacheMergedMenu()
 {
     Mock::generatePartial('OX_Plugin_ComponentGroupManager', $oMockGroupManager = 'OX_Plugin_ComponentGroupManager' . rand(), array('mergeMenu'));
     $oGroupManager = new $oMockGroupManager($this);
     $oGroupManager->setReturnValue('mergeMenu', true);
     Mock::generatePartial('OX_Extension_admin', $oMockExtensionManager = 'OX_Extension_admin' . rand(), array('_getMenuObjectForAccount', '_getGroupManagerObject'));
     $oMockExtensionManager = new $oMockExtensionManager($this);
     $oMenu = new OA_Admin_Menu('TEST');
     $oMenu->add(new OA_Admin_Menu_Section("test", 'test root', "test-root.php", false, ""));
     $oMockExtensionManager->setReturnValue('_getMenuObjectForAccount', $oMenu);
     $oMockExtensionManager->setReturnValue('_getGroupManagerObject', $oGroupManager);
     OA_Admin_Menu::_clearCache('TEST');
     $this->assertTrue($oMockExtensionManager->_cacheMergedMenu('TEST'));
     $oMenuCache = $oMenu->_loadFromCache('TEST');
     $this->assertTrue(is_a($oMenuCache, 'OA_Admin_Menu'));
     $this->assertEqual(count($oMenuCache->aAllSections), 1);
     $this->assertTrue(array_key_exists('test', $oMenuCache->aAllSections));
     OA_Admin_Menu::_clearCache('TEST');
     TestEnv::restoreConfig();
 }
 function test_cachePreferenceOptions()
 {
     $oExtension = new OX_Extension_Common();
     $GLOBALS['_MAX']['CONF']['pluginPaths']['packages'] = '/lib/OX/Extension/tests/data/';
     $GLOBALS['_MAX']['CONF']['pluginGroupComponents'] = array('testPlugin' => 1);
     $this->_backupCacheFile('PrefOptions_Plugins');
     $oExtension->cachePreferenceOptions();
     $oCache = new OA_Cache('Plugins', 'PrefOptions');
     $oCache->setFileNameProtection(false);
     $aPrefOptions = $oCache->load(true);
     $this->assertIsA($aPrefOptions, 'array');
     $this->assertEqual(count($aPrefOptions), 1);
     $this->assertTrue(isset($aPrefOptions['testPlugin']));
     $this->assertTrue(isset($aPrefOptions['testPlugin']['value']));
     $this->assertTrue(isset($aPrefOptions['testPlugin']['name']));
     $this->assertTrue(isset($aPrefOptions['testPlugin']['perm']));
     $this->assertEqual($aPrefOptions['testPlugin']['name'], 'testPlugin');
     $this->assertEqual($aPrefOptions['testPlugin']['text'], 'Option Text');
     $this->assertEqual($aPrefOptions['testPlugin']['value'], 'account-preferences-plugin.php?group=testPlugin');
     $this->assertEqual(count($aPrefOptions['testPlugin']['perm']), 4);
     $this->_restoreCacheFile('PrefOptions_Plugins');
     TestEnv::restoreConfig();
 }
 function testChangePluginPaths()
 {
     TestEnv::restoreConfig();
     // prepare data
     $oUpgrade = new OA_Upgrade();
     $oUpgrade->oConfiguration = new OA_Upgrade_Config();
     Mock::generatePartial('OA_UpgradePostscript_2_7_31_beta_rc1', $mockName = 'OA_UpgradePostscript_2_7_31_beta_rc1' . rand(), array('logOnly', 'logError'));
     $doMockPostUpgrade = new $mockName($this);
     $doMockPostUpgrade->oUpgrade =& $oUpgrade;
     // delete max section to make a new max section for testing
     unset($doMockPostUpgrade->oUpgrade->oConfiguration->aConfig['pluginPaths']);
     $doMockPostUpgrade->oUpgrade->oConfiguration->aConfig['pluginUpdatesServer'] = array('protocol' => 'test', 'host' => 'test', 'path' => 'test', 'httpPort' => 'test');
     $this->assertNull($doMockPostUpgrade->oUpgrade->oConfiguration->aConfig['pluginPaths']);
     $doMockPostUpgrade->oUpgrade->oConfiguration->aConfig['pluginPaths'] = array('packages' => '/extensions/etc/', 'extensions' => '/extensions/', 'admin' => '/www/admin/plugins/', 'var' => '/var/plugins/', 'plugins' => '/plugins/');
     // check that aConfig pluginPaths section is not null
     $this->assertNotNull($doMockPostUpgrade->oUpgrade->oConfiguration->aConfig['pluginPaths']);
     // Execute
     $doMockPostUpgrade->execute(array($oUpgrade));
     // assert that ['pluginPaths'] and ['pluginUpdatesServer have been upgraded to the correct values
     $this->assertEqual($doMockPostUpgrade->oUpgrade->oConfiguration->aConfig['pluginPaths']['packages'], '/plugins/etc/');
     $this->assertNull($doMockPostUpgrade->oUpgrade->oConfiguration->aConfig['pluginPaths']['extensions']);
     $this->assertEqual($doMockPostUpgrade->oUpgrade->oConfiguration->aConfig['pluginUpdatesServer'], array('protocol' => 'http', 'host' => 'code.openx.org', 'path' => '/openx/plugin-updates', 'httpPort' => '80'));
     TestEnv::restoreConfig();
 }
 /**
  * Tests the saveSummary() method.
  *
  * Requirements:
  * Test 1: Test with no data.
  * Test 2: Test a single day summarisation.
  * Test 3: Test multi-day summarisation.
  */
 function testSaveSummary()
 {
     $aConf =& $GLOBALS['_MAX']['CONF'];
     $oDbh =& OA_DB::singleton();
     $oFactory = new OX_Dal_Maintenance_Statistics_Factory();
     $oDalMaintenanceStatistics = $oFactory->factory();
     // Test 1
     $start = new Date('2004-06-06 12:00:00');
     $end = new Date('2004-06-06 12:29:59');
     $aActionTypes = array('types' => array(0 => 'request', 1 => 'impression', 2 => 'click'), 'connections' => array(1 => MAX_CONNECTION_AD_IMPRESSION, 2 => MAX_CONNECTION_AD_CLICK));
     $oDalMaintenanceStatistics->saveSummary($start, $end, $aActionTypes, 'data_intermediate_ad', 'data_summary_ad_hourly');
     $query = "\n            SELECT\n                COUNT(*) AS number\n            FROM\n                " . $oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['data_summary_ad_hourly'], true);
     $aRow = $oDbh->queryRow($query);
     $this->assertEqual($aRow['number'], 0);
     // Test 2
     // Insert the test data
     $this->_insertTestSaveSummaryPlacement();
     $this->_insertTestSaveSummaryAd();
     $this->_insertTestSaveSummaryZone();
     $query = "\n            INSERT INTO\n                " . $oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['data_intermediate_ad'], true) . "\n                (\n                    date_time, operation_interval, operation_interval_id, interval_start, interval_end,\n                    ad_id, creative_id, zone_id, impressions, clicks, conversions, total_basket_value, total_num_items\n                )\n            VALUES\n                (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
     $aTypes = array('timestamp', 'integer', 'integer', 'timestamp', 'timestamp', 'integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'integer', 'integer');
     $st = $oDbh->prepare($query, $aTypes, MDB2_PREPARE_MANIP);
     $aData = array('2004-06-06 18:00:00', 30, 36, '2004-06-06 18:00:00', '2004-06-06 18:29:59', 1, 1, 1, 1, 1, 1, 1, 0);
     $rows = $st->execute($aData);
     $aData = array('2004-06-06 18:00:00', 30, 36, '2004-06-06 18:00:00', '2004-06-06 18:29:59', 1, 2, 1, 1, 1, 1, 1, 0);
     $rows = $st->execute($aData);
     $aData = array('2004-06-06 18:00:00', 30, 36, '2004-06-06 18:00:00', '2004-06-06 18:29:59', 1, 2, 1, 1, 1, 1, 1, 0);
     $rows = $st->execute($aData);
     $aData = array('2004-06-06 18:00:00', 30, 36, '2004-06-06 18:00:00', '2004-06-06 18:29:59', 2, 1, 1, 1, 1, 0, 0, 0);
     $rows = $st->execute($aData);
     $aData = array('2004-06-06 18:00:00', 30, 36, '2004-06-06 18:00:00', '2004-06-06 18:29:59', 3, 1, 2, 1, 1, 0, 0, 0);
     $rows = $st->execute($aData);
     $aData = array('2004-06-06 18:00:00', 30, 36, '2004-06-06 18:00:00', '2004-06-06 18:29:59', 4, 1, 3, 1, 1, 5, 0, 0);
     $rows = $st->execute($aData);
     $aData = array('2004-06-06 18:00:00', 30, 36, '2004-06-06 18:00:00', '2004-06-06 18:29:59', 4, 1, 4, 1, 1, 5, 0, 0);
     $rows = $st->execute($aData);
     $aData = array('2004-06-06 18:00:00', 30, 36, '2004-06-06 18:00:00', '2004-06-06 18:29:59', 4, 1, 5, 1, 1, 5, 100, 1);
     $rows = $st->execute($aData);
     $aData = array('2004-06-06 18:00:00', 30, 36, '2004-06-06 18:00:00', '2004-06-06 18:29:59', 4, 1, 6, 1, 1, 5, 100, 3);
     $rows = $st->execute($aData);
     // Test
     $start = new Date('2004-06-06 18:00:00');
     $end = new Date('2004-06-06 18:29:59');
     $oDalMaintenanceStatistics->saveSummary($start, $end, $aActionTypes, 'data_intermediate_ad', 'data_summary_ad_hourly');
     $query = "\n            SELECT\n                COUNT(*) AS number\n            FROM\n                " . $oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['data_summary_ad_hourly'], true);
     $aRow = $oDbh->queryRow($query);
     $this->assertEqual($aRow['number'], 8);
     $query = "\n            SELECT\n                *\n            FROM\n                " . $oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['data_summary_ad_hourly'], true) . "\n            WHERE\n                ad_id = 1\n                AND creative_id = 1";
     $aRow = $oDbh->queryRow($query);
     $this->assertEqual($aRow['date_time'], '2004-06-06 18:00:00');
     $this->assertEqual($aRow['zone_id'], 1);
     $this->assertEqual($aRow['impressions'], 1);
     $this->assertEqual($aRow['clicks'], 1);
     $this->assertEqual($aRow['conversions'], 1);
     $this->assertEqual($aRow['total_basket_value'], 1);
     $this->assertEqual($aRow['total_revenue'], 5);
     $query = "\n            SELECT\n                *\n            FROM\n                " . $oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['data_summary_ad_hourly'], true) . "\n            WHERE\n                ad_id = 1\n                AND creative_id = 2";
     $aRow = $oDbh->queryRow($query);
     $this->assertEqual($aRow['date_time'], '2004-06-06 18:00:00');
     $this->assertEqual($aRow['zone_id'], 1);
     $this->assertEqual($aRow['impressions'], 2);
     $this->assertEqual($aRow['clicks'], 2);
     $this->assertEqual($aRow['conversions'], 2);
     $this->assertEqual($aRow['total_basket_value'], 2);
     $this->assertEqual($aRow['total_revenue'], 10);
     $query = "\n            SELECT\n                *\n            FROM\n                " . $oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['data_summary_ad_hourly'], true) . "\n            WHERE\n                ad_id = 2";
     $aRow = $oDbh->queryRow($query);
     $this->assertEqual($aRow['date_time'], '2004-06-06 18:00:00');
     $this->assertEqual($aRow['creative_id'], 1);
     $this->assertEqual($aRow['zone_id'], 1);
     $this->assertEqual($aRow['impressions'], 1);
     $this->assertEqual($aRow['clicks'], 1);
     $this->assertEqual($aRow['conversions'], 0);
     $this->assertEqual($aRow['total_basket_value'], 0);
     $this->assertEqual($aRow['total_revenue'], 2);
     $query = "\n            SELECT\n                *\n            FROM\n                " . $oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['data_summary_ad_hourly'], true) . "\n            WHERE\n                ad_id = 3";
     $aRow = $oDbh->queryRow($query);
     $this->assertEqual($aRow['date_time'], '2004-06-06 18:00:00');
     $this->assertEqual($aRow['creative_id'], 1);
     $this->assertEqual($aRow['zone_id'], 2);
     $this->assertEqual($aRow['impressions'], 1);
     $this->assertEqual($aRow['clicks'], 1);
     $this->assertEqual($aRow['conversions'], 0);
     $this->assertEqual($aRow['total_basket_value'], 0);
     $this->assertEqual($aRow['total_revenue'], 0);
     $query = "\n            SELECT\n                *\n            FROM\n                " . $oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['data_summary_ad_hourly'], true) . "\n            WHERE\n                ad_id = 4\n            ORDER BY\n                zone_id";
     $rc = $oDbh->query($query);
     $this->assertEqual($rc->numRows(), 4);
     $aRow = $rc->fetchRow();
     $this->assertEqual($aRow['date_time'], '2004-06-06 18:00:00');
     $this->assertEqual($aRow['creative_id'], 1);
     $this->assertEqual($aRow['zone_id'], 3);
     $this->assertEqual($aRow['impressions'], 1);
     $this->assertEqual($aRow['clicks'], 1);
     $this->assertEqual($aRow['conversions'], 5);
     $this->assertEqual($aRow['total_basket_value'], 0);
     $this->assertEqual($aRow['total_revenue'], 20);
     $aRow = $rc->fetchRow();
     $this->assertEqual($aRow['date_time'], '2004-06-06 18:00:00');
     $this->assertEqual($aRow['creative_id'], 1);
     $this->assertEqual($aRow['zone_id'], 4);
     $this->assertEqual($aRow['impressions'], 1);
     $this->assertEqual($aRow['clicks'], 1);
     $this->assertEqual($aRow['conversions'], 5);
     $this->assertEqual($aRow['total_basket_value'], 0);
     $this->assertEqual($aRow['total_revenue'], 20);
     $aRow = $rc->fetchRow();
     $this->assertEqual($aRow['date_time'], '2004-06-06 18:00:00');
     $this->assertEqual($aRow['creative_id'], 1);
     $this->assertEqual($aRow['zone_id'], 5);
     $this->assertEqual($aRow['impressions'], 1);
     $this->assertEqual($aRow['clicks'], 1);
     $this->assertEqual($aRow['conversions'], 5);
     $this->assertEqual($aRow['total_basket_value'], 100);
     $this->assertEqual($aRow['total_revenue'], 20);
     $aRow = $rc->fetchRow();
     $this->assertEqual($aRow['date_time'], '2004-06-06 18:00:00');
     $this->assertEqual($aRow['creative_id'], 1);
     $this->assertEqual($aRow['zone_id'], 6);
     $this->assertEqual($aRow['impressions'], 1);
     $this->assertEqual($aRow['clicks'], 1);
     $this->assertEqual($aRow['conversions'], 5);
     $this->assertEqual($aRow['total_basket_value'], 100);
     $this->assertEqual($aRow['total_revenue'], 20);
     TestEnv::restoreEnv();
     // Test 3
     // Insert the test data
     $this->_insertTestSaveSummaryPlacement();
     $this->_insertTestSaveSummaryAd();
     $this->_insertTestSaveSummaryZone();
     $aData = array('2004-06-06 18:00:00', 30, 36, '2004-06-06 18:00:00', '2004-06-06 18:29:59', 1, 1, 1, 1, 1, 1, 1);
     $rows = $st->execute($aData);
     $aData = array('2004-06-07 18:00:00', 30, 36, '2004-06-07 18:00:00', '2004-06-07 18:29:59', 1, 2, 1, 1, 1, 1, 1);
     $rows = $st->execute($aData);
     $aData = array('2004-06-07 18:00:00', 30, 36, '2004-06-07 18:00:00', '2004-06-07 18:29:59', 1, 2, 1, 1, 1, 1, 1);
     $rows = $st->execute($aData);
     $aData = array('2004-06-08 18:00:00', 30, 36, '2004-06-08 18:00:00', '2004-06-08 18:29:59', 2, 1, 1, 1, 1, 0, 0);
     $rows = $st->execute($aData);
     // Test
     $start = new Date('2004-06-06 18:00:00');
     $end = new Date('2004-06-08 18:29:59');
     $oDalMaintenanceStatistics->saveSummary($start, $end, $aActionTypes, 'data_intermediate_ad', 'data_summary_ad_hourly');
     $query = "\n            SELECT\n                COUNT(*) AS number\n            FROM\n                " . $oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['data_summary_ad_hourly'], true);
     $aRow = $oDbh->queryRow($query);
     $this->assertEqual($aRow['number'], 3);
     $query = "\n            SELECT\n                *\n            FROM\n                " . $oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['data_summary_ad_hourly'], true) . "\n            WHERE\n                ad_id = 1\n                AND creative_id = 1";
     $aRow = $oDbh->queryRow($query);
     $this->assertEqual($aRow['date_time'], '2004-06-06 18:00:00');
     $this->assertEqual($aRow['zone_id'], 1);
     $this->assertEqual($aRow['impressions'], 1);
     $this->assertEqual($aRow['clicks'], 1);
     $this->assertEqual($aRow['conversions'], 1);
     $this->assertEqual($aRow['total_basket_value'], 1);
     $this->assertEqual($aRow['total_revenue'], 5);
     $query = "\n            SELECT\n                *\n            FROM\n                " . $oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['data_summary_ad_hourly'], true) . "\n            WHERE\n                ad_id = 1\n                AND creative_id = 2";
     $aRow = $oDbh->queryRow($query);
     $this->assertEqual($aRow['date_time'], '2004-06-07 18:00:00');
     $this->assertEqual($aRow['zone_id'], 1);
     $this->assertEqual($aRow['impressions'], 2);
     $this->assertEqual($aRow['clicks'], 2);
     $this->assertEqual($aRow['conversions'], 2);
     $this->assertEqual($aRow['total_basket_value'], 2);
     $this->assertEqual($aRow['total_revenue'], 10);
     $query = "\n            SELECT\n                *\n            FROM\n                " . $oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['data_summary_ad_hourly'], true) . "\n            WHERE\n                ad_id = 2";
     $aRow = $oDbh->queryRow($query);
     $this->assertEqual($aRow['date_time'], '2004-06-08 18:00:00');
     $this->assertEqual($aRow['creative_id'], 1);
     $this->assertEqual($aRow['zone_id'], 1);
     $this->assertEqual($aRow['impressions'], 1);
     $this->assertEqual($aRow['clicks'], 1);
     $this->assertEqual($aRow['conversions'], 0);
     $this->assertEqual($aRow['total_basket_value'], 0);
     $this->assertEqual($aRow['total_revenue'], 2);
     TestEnv::restoreEnv();
     TestEnv::restoreConfig();
 }
Example #12
0
 /**
  * tests an openads upgrade where a series of upgrade packages may be required
  * the upgrade method will detectOpenXand cycle through the list of upgrade packages
  * executing the upgrade packages in the right order
  * until it runs out of upgrade packages
  * when no more upgrade packages are found
  * the application is stamped with the latest version
  *
  */
 function test_upgradeIncremental()
 {
     $oUpgrade = new OA_Upgrade();
     Mock::generatePartial('OA_Upgrade_Config', $mockConfig = 'OA_Upgrade_Config' . rand(), array('backupConfig', 'mergeConfig', 'setupConfigDatabase', 'setupConfigTable', 'setValue', 'writeConfig', 'getConfigBackupName', 'clearConfigBackupName', 'setBulkValue'));
     $oUpgrade->oConfiguration = new $mockConfig($this);
     $oUpgrade->oConfiguration->setReturnValue('setupConfigDatabase', true);
     $oUpgrade->oConfiguration->setReturnValue('setupConfigTable', true);
     $oUpgrade->oConfiguration->setReturnValue('setValue', true);
     $oUpgrade->oConfiguration->setReturnValue('writeConfig', true);
     $oUpgrade->oConfiguration->expectCallCount('backupConfig', 1);
     $oUpgrade->oConfiguration->setReturnValue('backupConfig', true);
     $oUpgrade->oConfiguration->expectCallCount('mergeConfig', 1);
     $oUpgrade->oConfiguration->setReturnValue('mergeConfig', true);
     $oUpgrade->oConfiguration->expectCallCount('getConfigBackupName', 13);
     for ($i = 0; $i < 13; $i++) {
         $oUpgrade->oConfiguration->setReturnValueAt($i, 'getConfigBackupName', $i . '_old.www.mysite.net.conf.php');
         // drop a fake conf backup
         @copy(MAX_PATH . '/var/test.conf.php', MAX_PATH . '/var/' . $i . '_old.www.mysite.net.conf.php');
     }
     // divert objects to test data
     $oUpgrade->upgradePath = MAX_PATH . '/lib/OA/Upgrade/tests/data/changes/';
     $GLOBALS['_MAX']['CONF']['openads']['installed'] = true;
     $this->_dropTestTable($oUpgrade->oDbh, 'database_action');
     $this->_dropTestTable($oUpgrade->oDbh, 'upgrade_action');
     // just in case of error, lose this so we can continue afresh
     $oUpgrade->_pickupRecoveryFile();
     // fake the versions we are starting with
     $this->_createTestAppVarRecord('oa_version', '2.3.32-beta-rc1');
     // mock the integrity checker
     Mock::generatePartial('OA_DB_Integrity', $mockInteg = 'OA_DB_Integrity' . rand(), array('checkIntegrityQuick'));
     $oUpgrade->oIntegrity = new $mockInteg($this);
     $oUpgrade->oIntegrity->setReturnValue('checkIntegrityQuick', true);
     // do the initial detection
     $this->assertTrue($oUpgrade->detectOpenads());
     // this should identify 12 upgrade packages to be executed
     // (from /lib/OA/Upgrade/tests/data/changes)
     $this->assertEqual(count($oUpgrade->aPackageList), 12, 'wrong number of packages in upgrader package list');
     $this->assertIsA($oUpgrade->oAuditor, 'OA_UpgradeAuditor', 'class mismatch: OA_UpgradeAuditor');
     // perform the upgrade
     $this->assertTrue($oUpgrade->upgrade(), 'upgrade');
     $aAudit = $oUpgrade->oAuditor->queryAuditAllDescending();
     // we should have 13 records in the upgrade_action audit table
     // we should have 13 logfiles in the var folder
     // one for each package plus a version stamp
     $this->assertEqual(count($aAudit), 13, 'wrong number of audit records');
     $aPackageList = $oUpgrade->aPackageList;
     krsort($aPackageList, SORT_NUMERIC);
     foreach ($aAudit as $k => $aRec) {
         $idx = 12 - $k;
         $this->assertEqual($aRec['upgrade_action_id'], $idx + 1, '');
         $this->assertEqual($aRec['confbackup'], $idx . '_old.www.mysite.net.conf.php');
         $this->assertTrue(file_exists(MAX_PATH . '/var/' . $aRec['logfile']));
         @unlink(MAX_PATH . '/var/' . $aRec['logfile']);
         if ($k > 0) {
             $this->assertEqual($aRec['upgrade_name'], $aPackageList[$idx], 'package mismatch: ' . $aRec['upgrade_name'] . ' and ' . $aPackageList[$idx]);
         } else {
             $this->assertEqual($aRec['upgrade_name'], 'openads_version_stamp_' . VERSION, 'wrong package name for version stamp');
         }
     }
     // the application variable should match the code version stamp
     $this->assertEqual($oUpgrade->versionInitialApplication, VERSION, 'wrong initial application version: ' . $oUpgrade->versionInitialApplication);
     //        $this->_deleteTestAppVarRecordAllNames('oa_version');
     $oUpgrade->oConfiguration->tally();
     $oUpgrade->oIntegrity->tally();
     TestEnv::restoreConfig();
 }
 /**
  * Test 1: with lowercase prefix
  * Test 2: with uppercase prefix
  */
 function test_createAuditTable()
 {
     // Test 1
     $GLOBALS['_MAX']['CONF']['table']['prefix'] = 'oa_';
     $oAuditor = $this->_getAuditObject('OA_DB_UpgradeAuditor');
     $this->_dropAuditTable($oAuditor->prefix . $oAuditor->logTable);
     $this->assertTrue($oAuditor->_createAuditTable(), 'failed to createAuditTable');
     $aDBTables = OA_DB_Table::listOATablesCaseSensitive();
     $this->assertTrue(in_array($oAuditor->prefix . $oAuditor->logTable, $aDBTables));
     $this->_dropAuditTable($oAuditor->prefix . $oAuditor->logTable);
     TestEnv::restoreConfig();
     //TestEnv::restoreEnv();
     // Test 2
     $GLOBALS['_MAX']['CONF']['table']['prefix'] = 'OA_';
     $oAuditor = $this->_getAuditObject('OA_DB_UpgradeAuditor');
     $this->_dropAuditTable($oAuditor->prefix . $oAuditor->logTable);
     $this->assertTrue($oAuditor->_createAuditTable(), 'failed to createAuditTable');
     $aDBTables = OA_DB_Table::listOATablesCaseSensitive();
     $this->assertTrue(in_array($oAuditor->prefix . $oAuditor->logTable, $aDBTables));
     $this->_dropAuditTable($oAuditor->prefix . $oAuditor->logTable);
     TestEnv::restoreConfig();
     //TestEnv::restoreEnv();
 }
Example #14
0
 function testGetSequenceName()
 {
     $conf =& $GLOBALS['_MAX']['CONF'];
     $prefix = $conf['table']['prefix'] = 'ox_';
     $oDbh =& OA_DB::singleton();
     if ($oDbh->dbsyntax == 'pgsql') {
         $this->assertEqual(OA_DB::getSequenceName($oDbh, 'x', 'a'), 'ox_x_a_seq');
         $this->assertEqual(OA_DB::getSequenceName($oDbh, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyy', 'a'), 'ox_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx_a_seq');
         $this->assertEqual(OA_DB::getSequenceName($oDbh, 'x', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabb'), 'ox_x_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_seq');
         $this->assertEqual(OA_DB::getSequenceName($oDbh, 'xxxxxxxxxxxxxxxxxxxxxxxxxxy', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaab'), 'ox_xxxxxxxxxxxxxxxxxxxxxxxxxx_aaaaaaaaaaaaaaaaaaaaaaaaaaaaa_seq');
         $this->assertEqual(OA_DB::getSequenceName($oDbh, 'x', 'a', false), 'ox_x_a');
         $this->assertEqual(OA_DB::getSequenceName($oDbh, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyy', 'a', false), 'ox_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx_a');
         $this->assertEqual(OA_DB::getSequenceName($oDbh, 'x', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabb', false), 'ox_x_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
         $this->assertEqual(OA_DB::getSequenceName($oDbh, 'xxxxxxxxxxxxxxxxxxxxxxxxxxy', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaab', false), 'ox_xxxxxxxxxxxxxxxxxxxxxxxxxx_aaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
     } else {
         $this->assertEqual(OA_DB::getSequenceName($oDbh, 'x', 'a'), 'x');
         $this->assertEqual(OA_DB::getSequenceName($oDbh, 'x', 'a', false), 'x');
     }
     TestEnv::restoreConfig();
 }
 /**
  * A private method that tests that preferences have been
  * correctly migrated to settings.
  *
  * @access private
  * @param integer $set The index number of the preference
  *                     set that has been configured.
  */
 function _testMigratePrefsToSettings($set)
 {
     $aConf = $GLOBALS['_MAX']['CONF'];
     // Get the expected results of the migration of preferences to settings
     $aSettingsExpectations = $this->_getSettingsExpectations($set);
     // Test the settings are correct
     foreach ($aSettingsExpectations as $section => $aPair) {
         $this->assertTrue(isset($aConf[$section]), "Section '{$section}' missing");
         foreach ($aPair as $key => $value) {
             $this->assertTrue(isset($aConf[$section][$key]), "Key '{$key}' in section '{$section}' missing");
             $this->assertEqual($aConf[$section][$key], $value, "Incorrect value \$aConf[{$section}][{$key}]: {{$aConf[$section][$key]}} != {{$value}}");
         }
     }
     TestEnv::restoreConfig();
 }
 /**
  * this test calls backup method then immediately rollsback
  * emulating an upgrade error without interrupt (can recover in same session)
  *
  */
 function test_BackupAndRollback_restoreAutoIncrement()
 {
     $oDB_Upgrade = $this->_newDBUpgradeObject();
     $oDB_Upgrade->oAuditor->auditId = 5;
     $oDB_Upgrade->oAuditor->setKeyParams(array('schema_name' => 'tables_core', 'version' => '920', 'timing' => 0));
     $this->_createTestTableAutoInc($oDB_Upgrade->oSchema->db);
     $oDB_Upgrade->aChanges['affected_tables']['constructive'] = array('table1_autoinc');
     OA_DB::setCaseSensitive();
     $aTbl_def_orig = $oDB_Upgrade->oSchema->getDefinitionFromDatabase(array($this->prefix . 'table1_autoinc'));
     OA_DB::disableCaseSensitive();
     $this->assertTrue($oDB_Upgrade->_backup(), '_backup failed');
     $this->assertTrue($oDB_Upgrade->prepRollbackByAuditId(5, $version, $schema), 'prep rollback failed');
     $this->assertIsA($oDB_Upgrade->aRestoreTables, 'array', 'aRestoreTables not an array');
     $this->assertTrue(array_key_exists('table1_autoinc', $oDB_Upgrade->aRestoreTables['tables_core']['920']), 'table not found in aRestoreTables');
     $this->assertTrue(array_key_exists('tablename_backup', $oDB_Upgrade->aRestoreTables['tables_core']['920']['table1_autoinc'][0]), 'backup table name not found for table1_autoinc');
     $this->assertTrue(array_key_exists('table_backup_schema', $oDB_Upgrade->aRestoreTables['tables_core']['920']['table1_autoinc'][0]), 'definition array not found for table1_autoinc');
     $oDB_Upgrade->aDBTables = $oDB_Upgrade->_listTables();
     $table_bak = $oDB_Upgrade->aRestoreTables['tables_core']['920']['table1_autoinc'][0]['tablename_backup'];
     $this->assertTrue($this->_tableExists($table_bak, $oDB_Upgrade->aDBTables), 'backup table not found in database');
     //OA_DB::setQuoteIdentifier();
     OA_DB::setCaseSensitive();
     $aTbl_def_bak = $oDB_Upgrade->oSchema->getDefinitionFromDatabase(array($this->prefix . $table_bak));
     OA_DB::disableCaseSensitive();
     //OA_DB::disabledQuoteIdentifier();
     $aTbl_def_orig = $aTbl_def_orig['tables'][$this->prefix . 'table1_autoinc'];
     $aTbl_def_bak = $aTbl_def_bak['tables'][$this->prefix . $table_bak];
     foreach ($aTbl_def_orig['fields'] as $name => $aType) {
         $this->assertTrue(array_key_exists($name, $aTbl_def_bak['fields']), 'field missing from backup table');
     }
     $oDB_Upgrade->oSchema->db->manager->dropTable($this->prefix . 'table1_autoinc');
     $oDB_Upgrade->aDBTables = $oDB_Upgrade->_listTables();
     $this->assertFalse($this->_tableExists('table1_autoinc', $oDB_Upgrade->aDBTables), 'could not drop test table');
     $this->assertTrue($oDB_Upgrade->rollback(), 'rollback failed');
     $oDB_Upgrade->aDBTables = $oDB_Upgrade->_listTables();
     $this->assertTrue($this->_tableExists('table1_autoinc', $oDB_Upgrade->aDBTables), 'test table was not restored');
     OA_DB::setCaseSensitive();
     $aTbl_def_rest = $oDB_Upgrade->oSchema->getDefinitionFromDatabase(array($this->prefix . 'table1_autoinc'));
     OA_DB::disableCaseSensitive();
     $aTbl_def_rest = $aTbl_def_rest['tables']['table1_autoinc'];
     // also test field definition properties?
     $aDiffs = $oDB_Upgrade->oSchema->compareDefinitions($aTbl_def_orig, $aTbl_def_rest);
     $this->assertEqual(count($aDiffs) == 0, 'differences found in restored table');
     $this->assertFalse($this->_tableExists($table_bak, $oDB_Upgrade->aDBTables), 'backup table was not removed');
     TestEnv::restoreConfig();
     TestEnv::restoreEnv();
 }
 /**
  * A method to test the summariseBucketsRawSupplementary() method.
  */
 function testSummariseBucketsRawSupplementary()
 {
     $aConf =& $GLOBALS['_MAX']['CONF'];
     $aConf['maintenance']['operationInterval'] = 60;
     // Prepare standard test parameters
     $statisticsTableName = $aConf['table']['prefix'] . 'data_intermediate_ad_variable_value';
     $aMigrationDetails = array('method' => 'rawSupplementary', 'masterTable' => $aConf['table']['prefix'] . 'data_intermediate_ad_connection', 'masterTablePrimaryKeys' => array(0 => 'data_intermediate_ad_connection_id'), 'bucketTablePrimaryKeys' => array(0 => 'data_intermediate_ad_connection_id'), 'masterTableKeys' => array(0 => 'server_raw_tracker_impression_id', 1 => 'server_raw_ip'), 'bucketTableKeys' => array(0 => 'server_conv_id', 1 => 'server_ip'), 'masterDateTimeColumn' => 'tracker_date_time', 'bucketTable' => $aConf['table']['prefix'] . 'data_bkt_a_var', 'source' => array(0 => 'tracker_variable_id', 1 => 'value'), 'destination' => array(0 => 'tracker_variable_id', 1 => 'value'));
     $aDates = array('start' => new Date('2008-08-21 09:00:00'), 'end' => new Date('2008-08-21 09:59:59'));
     // Prepare the DAL object
     $oFactory = new OX_Dal_Maintenance_Statistics_Factory();
     $oDalMaintenanceStatistics = $oFactory->factory();
     // Test 1: Test with an incorrect method name in the mapping array
     $savedValue = $aMigrationDetails['method'];
     $aMigrationDetails['method'] = 'foo';
     $result = $oDalMaintenanceStatistics->summariseBucketsRawSupplementary($statisticsTableName, $aMigrationDetails, $aDates);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDARGS);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with migration map method 'foo' != 'rawSupplementary'.");
     $aMigrationDetails['method'] = $savedValue;
     // Test 2: Test with a different number of masterTablePrimaryKeys and bucketTablePrimaryKeys columns
     $savedValue = $aMigrationDetails['masterTablePrimaryKeys'][0];
     unset($aMigrationDetails['masterTablePrimaryKeys'][0]);
     $result = $oDalMaintenanceStatistics->summariseBucketsRawSupplementary($statisticsTableName, $aMigrationDetails, $aDates);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDARGS);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with different number of 'masterTablePrimaryKeys' and 'bucketTablePrimaryKeys' columns.");
     $aMigrationDetails['masterTablePrimaryKeys'][0] = $savedValue;
     // Test 3: Test with a different number of masterTableKeys and bucketTableKeys columns
     $savedValue = $aMigrationDetails['masterTableKeys'][1];
     unset($aMigrationDetails['masterTableKeys'][1]);
     $result = $oDalMaintenanceStatistics->summariseBucketsRawSupplementary($statisticsTableName, $aMigrationDetails, $aDates);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDARGS);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with different number of 'masterTableKeys' and 'bucketTableKeys' columns.");
     $aMigrationDetails['masterTableKeys'][1] = $savedValue;
     // Test 4: Test with a different number of source and destination columns
     $savedValue = $aMigrationDetails['destination'][1];
     unset($aMigrationDetails['destination'][1]);
     $result = $oDalMaintenanceStatistics->summariseBucketsRawSupplementary($statisticsTableName, $aMigrationDetails, $aDates);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDARGS);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with different number of 'source' and 'destination' columns.");
     $aMigrationDetails['destination'][1] = $savedValue;
     // Test 5: Test with date parameters that are not really dates
     $savedValue = $aDates['start'];
     $aDates['start'] = 'foo';
     $result = $oDalMaintenanceStatistics->summariseBucketsRawSupplementary($statisticsTableName, $aMigrationDetails, $aDates);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDARGS);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with invalid start/end date parameters -- not Date objects.");
     $aDates['start'] = $savedValue;
     $savedValue = $aDates['end'];
     $aDates['end'] = 'foo';
     $result = $oDalMaintenanceStatistics->summariseBucketsRawSupplementary($statisticsTableName, $aMigrationDetails, $aDates);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDARGS);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with invalid start/end date parameters -- not Date objects.");
     $aDates['end'] = $savedValue;
     // Test 6: Test with invalid start/end dates
     $savedValue = $aDates['start'];
     $aDates['start'] = new Date('2008-08-21 08:00:00');
     $result = $oDalMaintenanceStatistics->summariseBucketsRawSupplementary($statisticsTableName, $aMigrationDetails, $aDates);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDARGS);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with invalid start/end date parameters -- not operation interval bounds.");
     $aDates['start'] = $savedValue;
     $savedValue = $aDates['end'];
     $aDates['end'] = new Date('2008-08-22 09:59:59');
     $result = $oDalMaintenanceStatistics->summariseBucketsRawSupplementary($statisticsTableName, $aMigrationDetails, $aDates);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDARGS);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with invalid start/end date parameters -- not operation interval bounds.");
     $aDates['end'] = $savedValue;
     // Test 7: Test with an invalid statistics table name
     $savedValue = $statisticsTableName;
     $statisticsTableName = 'foo';
     $result = $oDalMaintenanceStatistics->summariseBucketsRawSupplementary($statisticsTableName, $aMigrationDetails, $aDates);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDREQUEST);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with invalid statistics table 'foo'.");
     $statisticsTableName = $savedValue;
     // Test 8: Test with an invalid master statistics table name
     $savedValue = $aMigrationDetails['masterTable'];
     $aMigrationDetails['masterTable'] = 'foo';
     $result = $oDalMaintenanceStatistics->summariseBucketsRawSupplementary($statisticsTableName, $aMigrationDetails, $aDates);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDREQUEST);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with invalid master table 'foo'.");
     $aMigrationDetails['masterTable'] = $savedValue;
     // Test 9: Test with no data_bkt_a_var table in the database
     $result = $oDalMaintenanceStatistics->summariseBucketsRawSupplementary($statisticsTableName, $aMigrationDetails, $aDates);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDREQUEST);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsRawSupplementary() called with invalid bucket table '{$aConf['table']['prefix']}data_bkt_a_var'.");
     // Install the openXDeliveryLog plugin, which will create the
     // data_bkt_a table required for testing
     TestEnv::installPluginPackage('openXDeliveryLog', false);
     // Test 10: Test with all tables present, but no data
     $result = $oDalMaintenanceStatistics->summariseBucketsRawSupplementary($statisticsTableName, $aMigrationDetails, $aDates);
     $this->assertEqual($result, 0);
     // Insert a conversion into the data_intermediate_ad_connection table
     // in the incorrect operation interval
     $oData_intermediate_ad_connection = OA_Dal::factoryDO('data_intermediate_ad_connection');
     $oData_intermediate_ad_connection->server_raw_tracker_impression_id = 1;
     $oData_intermediate_ad_connection->server_raw_ip = 'localhost';
     $oData_intermediate_ad_connection->tracker_id = 2;
     $oData_intermediate_ad_connection->tracker_date_time = '2008-08-21 08:15:00';
     $oData_intermediate_ad_connection->connection_date_time = '2008-08-21 07:15:00';
     $oData_intermediate_ad_connection->ad_id = 3;
     $oData_intermediate_ad_connection->zone_id = 4;
     $oData_intermediate_ad_connection->tracker_ip_address = '127.0.0.1';
     $oData_intermediate_ad_connection->connection_action = MAX_CONNECTION_AD_CLICK;
     $oData_intermediate_ad_connection->connection_window = 3600;
     $oData_intermediate_ad_connection->connection_status = MAX_CONNECTION_STATUS_APPROVED;
     $oData_intermediate_ad_connection->inside_window = 1;
     $conversionId = DataGenerator::generateOne($oData_intermediate_ad_connection);
     // Test 11: Test with data in the incorrect operation interval
     $result = $oDalMaintenanceStatistics->summariseBucketsRawSupplementary($statisticsTableName, $aMigrationDetails, $aDates);
     $this->assertEqual($result, 0);
     // Insert two conversions into the data_intermediate_ad_connection table
     // in the correct operation interval
     $oData_intermediate_ad_connection = OA_Dal::factoryDO('data_intermediate_ad_connection');
     $oData_intermediate_ad_connection->server_raw_tracker_impression_id = 2;
     $oData_intermediate_ad_connection->server_raw_ip = 'localhost';
     $oData_intermediate_ad_connection->tracker_id = 2;
     $oData_intermediate_ad_connection->tracker_date_time = '2008-08-21 09:15:00';
     $oData_intermediate_ad_connection->connection_date_time = '2008-08-21 08:15:00';
     $oData_intermediate_ad_connection->ad_id = 3;
     $oData_intermediate_ad_connection->zone_id = 4;
     $oData_intermediate_ad_connection->tracker_ip_address = '127.0.0.1';
     $oData_intermediate_ad_connection->connection_action = MAX_CONNECTION_AD_CLICK;
     $oData_intermediate_ad_connection->connection_window = 3600;
     $oData_intermediate_ad_connection->connection_status = MAX_CONNECTION_STATUS_APPROVED;
     $oData_intermediate_ad_connection->inside_window = 1;
     $conversionId1 = DataGenerator::generateOne($oData_intermediate_ad_connection);
     $oData_intermediate_ad_connection = OA_Dal::factoryDO('data_intermediate_ad_connection');
     $oData_intermediate_ad_connection->server_raw_tracker_impression_id = 3;
     $oData_intermediate_ad_connection->server_raw_ip = 'localhost';
     $oData_intermediate_ad_connection->tracker_id = 9;
     $oData_intermediate_ad_connection->tracker_date_time = '2008-08-21 09:16:00';
     $oData_intermediate_ad_connection->connection_date_time = '2008-08-21 08:16:00';
     $oData_intermediate_ad_connection->ad_id = 6;
     $oData_intermediate_ad_connection->zone_id = 7;
     $oData_intermediate_ad_connection->tracker_ip_address = '127.0.0.1';
     $oData_intermediate_ad_connection->connection_action = MAX_CONNECTION_AD_VIEW;
     $oData_intermediate_ad_connection->connection_window = 3600;
     $oData_intermediate_ad_connection->connection_status = MAX_CONNECTION_STATUS_APPROVED;
     $oData_intermediate_ad_connection->inside_window = 1;
     $conversionId2 = DataGenerator::generateOne($oData_intermediate_ad_connection);
     // Test 12: Test with data in the correct operation interval, but
     //          no supplementary data
     $result = $oDalMaintenanceStatistics->summariseBucketsRawSupplementary($statisticsTableName, $aMigrationDetails, $aDates);
     $this->assertEqual($result, 0);
     // Add some supplementary data for the conversions above!
     $oData_bkt_a_var = OA_Dal::factoryDO('data_bkt_a_var');
     $oData_bkt_a_var->server_conv_id = 2;
     $oData_bkt_a_var->server_ip = 'localhost';
     $oData_bkt_a_var->tracker_variable_id = 99;
     $oData_bkt_a_var->value = 'foo';
     DataGenerator::generateOne($oData_bkt_a_var);
     $oData_bkt_a_var = OA_Dal::factoryDO('data_bkt_a_var');
     $oData_bkt_a_var->server_conv_id = 2;
     $oData_bkt_a_var->server_ip = 'localhost';
     $oData_bkt_a_var->tracker_variable_id = 100;
     $oData_bkt_a_var->value = '156.99';
     DataGenerator::generateOne($oData_bkt_a_var);
     $oData_bkt_a_var = OA_Dal::factoryDO('data_bkt_a_var');
     $oData_bkt_a_var->server_conv_id = 3;
     $oData_bkt_a_var->server_ip = 'localhost';
     $oData_bkt_a_var->tracker_variable_id = 15;
     $oData_bkt_a_var->value = '123456789';
     DataGenerator::generateOne($oData_bkt_a_var);
     // Test 12: Test with data in the correct operation interval
     $result = $oDalMaintenanceStatistics->summariseBucketsRawSupplementary($statisticsTableName, $aMigrationDetails, $aDates);
     $this->assertEqual($result, 3);
     $oData_intermediate_ad_variable_value = OA_Dal::factoryDO('data_intermediate_ad_variable_value');
     $oData_intermediate_ad_variable_value->data_intermediate_ad_connection_id = $conversionId1;
     $oData_intermediate_ad_variable_value->find();
     $rows = $oData_intermediate_ad_variable_value->getRowCount();
     $this->assertEqual($rows, 2);
     $oData_intermediate_ad_variable_value = OA_Dal::factoryDO('data_intermediate_ad_variable_value');
     $oData_intermediate_ad_variable_value->data_intermediate_ad_connection_id = $conversionId1;
     $oData_intermediate_ad_variable_value->tracker_variable_id = 99;
     $oData_intermediate_ad_variable_value->find();
     $rows = $oData_intermediate_ad_variable_value->getRowCount();
     $this->assertEqual($rows, 1);
     $oData_intermediate_ad_variable_value->fetch();
     $this->assertEqual($oData_intermediate_ad_variable_value->data_intermediate_ad_connection_id, $conversionId1);
     $this->assertEqual($oData_intermediate_ad_variable_value->tracker_variable_id, 99);
     $this->assertEqual($oData_intermediate_ad_variable_value->value, 'foo');
     $oData_intermediate_ad_variable_value = OA_Dal::factoryDO('data_intermediate_ad_variable_value');
     $oData_intermediate_ad_variable_value->data_intermediate_ad_connection_id = $conversionId1;
     $oData_intermediate_ad_variable_value->tracker_variable_id = 100;
     $oData_intermediate_ad_variable_value->find();
     $rows = $oData_intermediate_ad_variable_value->getRowCount();
     $this->assertEqual($rows, 1);
     $oData_intermediate_ad_variable_value->fetch();
     $this->assertEqual($oData_intermediate_ad_variable_value->data_intermediate_ad_connection_id, $conversionId1);
     $this->assertEqual($oData_intermediate_ad_variable_value->tracker_variable_id, 100);
     $this->assertEqual($oData_intermediate_ad_variable_value->value, '156.99');
     $oData_intermediate_ad_variable_value = OA_Dal::factoryDO('data_intermediate_ad_variable_value');
     $oData_intermediate_ad_variable_value->data_intermediate_ad_connection_id = $conversionId2;
     $oData_intermediate_ad_variable_value->find();
     $rows = $oData_intermediate_ad_variable_value->getRowCount();
     $this->assertEqual($rows, 1);
     $oData_intermediate_ad_variable_value = OA_Dal::factoryDO('data_intermediate_ad_variable_value');
     $oData_intermediate_ad_variable_value->data_intermediate_ad_connection_id = $conversionId2;
     $oData_intermediate_ad_variable_value->tracker_variable_id = 15;
     $oData_intermediate_ad_variable_value->find();
     $rows = $oData_intermediate_ad_variable_value->getRowCount();
     $this->assertEqual($rows, 1);
     $oData_intermediate_ad_variable_value->fetch();
     $this->assertEqual($oData_intermediate_ad_variable_value->data_intermediate_ad_connection_id, $conversionId2);
     $this->assertEqual($oData_intermediate_ad_variable_value->tracker_variable_id, 15);
     $this->assertEqual($oData_intermediate_ad_variable_value->value, '123456789');
     // Clean up generated data
     DataGenerator::cleanUp();
     // Also clean up the data migrated into the statistics table
     $oData_intermediate_ad_variable_value = OA_Dal::factoryDO('data_intermediate_ad_connection');
     $oData_intermediate_ad_variable_value->data_intermediate_ad_connection_id = $conversionId1;
     $oData_intermediate_ad_variable_value->find();
     $oData_intermediate_ad_variable_value->delete();
     $oData_intermediate_ad_variable_value = OA_Dal::factoryDO('data_intermediate_ad_connection');
     $oData_intermediate_ad_variable_value->data_intermediate_ad_connection_id = $conversionId2;
     $oData_intermediate_ad_variable_value->find();
     $oData_intermediate_ad_variable_value->delete();
     // Uninstall the installed plugin
     TestEnv::uninstallPluginPackage('openXDeliveryLog', false);
     // Restore the test environment configuration
     TestEnv::restoreConfig();
 }
 /**
  * A method to test the MAX_Delivery_log_logConversion() function.
  */
 function test_MAX_Delivery_log_logConversion()
 {
     $aConf =& $GLOBALS['_MAX']['CONF'];
     $aConf['maintenance']['operationInterval'] = 60;
     $GLOBALS['_MAX']['NOW'] = time();
     $oNowDate = new Date($GLOBALS['_MAX']['NOW']);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oNowDate);
     $intervalStart = $aDates['start']->format('%Y-%m-%d %H:%M:%S');
     $oConversionDate = new Date();
     $oConversionDate->copy($oNowDate);
     $oConversionDate->subtractSeconds(60);
     $_SERVER['REMOTE_ADDR'] = '127.0.0.99';
     // Test to ensure that the openXDeliveryLog plugin's data bucket
     // table does not exist
     $oTable = new OA_DB_Table();
     $tableExists = $oTable->extistsTable($aConf['table']['prefix'] . 'data_bkt_a');
     $this->assertFalse($tableExists);
     // Test calling the main logging function without any plugins installed,
     // to ensure that this does not result in any kind of error
     $aConversion = array('action_type' => MAX_CONNECTION_AD_CLICK, 'tracker_type' => MAX_CONNECTION_TYPE_SALE, 'status' => MAX_CONNECTION_STATUS_APPROVED, 'cid' => 2, 'zid' => 3, 'dt' => $GLOBALS['_MAX']['NOW'] - 60, 'window' => 60);
     MAX_Delivery_log_logConversion(1, $aConversion);
     // Install the openXDeliveryLog plugin
     TestEnv::installPluginPackage('openXDeliveryLog', false);
     // Test to ensure that the openXDeliveryLog plugin's data bucket
     // table now does exist
     $tableExists = $oTable->extistsTable($aConf['table']['prefix'] . 'data_bkt_a');
     $this->assertTrue($tableExists);
     // Ensure that there are is nothing logged in the data bucket table
     $doData_bkt_a = OA_Dal::factoryDO('data_bkt_a');
     $doData_bkt_a->find();
     $rows = $doData_bkt_a->getRowCount();
     $this->assertEqual($rows, 0);
     // Call the conversion logging function
     $aConversionInfo = MAX_Delivery_log_logConversion(1, $aConversion);
     // Ensure that the data was logged correctly
     $doData_bkt_a = OA_Dal::factoryDO('data_bkt_a');
     $doData_bkt_a->find();
     $rows = $doData_bkt_a->getRowCount();
     $this->assertEqual($rows, 1);
     $doData_bkt_a = OA_Dal::factoryDO('data_bkt_a');
     $doData_bkt_a->server_conv_id = 1;
     $doData_bkt_a->find();
     $rows = $doData_bkt_a->getRowCount();
     $this->assertEqual($rows, 1);
     $doData_bkt_a->fetch();
     $this->assertEqual($doData_bkt_a->server_ip, 'singleDB');
     $this->assertEqual($doData_bkt_a->tracker_id, 1);
     $this->assertEqual($doData_bkt_a->date_time, $oNowDate->format('%Y-%m-%d %H:%M:%S'));
     $this->assertEqual($doData_bkt_a->action_date_time, $oConversionDate->format('%Y-%m-%d %H:%M:%S'));
     $this->assertEqual($doData_bkt_a->creative_id, 2);
     $this->assertEqual($doData_bkt_a->zone_id, 3);
     $this->assertEqual($doData_bkt_a->ip_address, '127.0.0.99');
     $this->assertEqual($doData_bkt_a->action, MAX_CONNECTION_AD_CLICK);
     $this->assertEqual($doData_bkt_a->window, 60);
     $this->assertEqual($doData_bkt_a->status, MAX_CONNECTION_STATUS_APPROVED);
     $this->assertTrue(is_array($aConversionInfo));
     $this->assertTrue(is_array($aConversionInfo['deliveryLog:oxLogConversion:logConversion']));
     $this->assertEqual($aConversionInfo['deliveryLog:oxLogConversion:logConversion']['server_conv_id'], 1);
     $this->assertEqual($aConversionInfo['deliveryLog:oxLogConversion:logConversion']['server_raw_ip'], 'singleDB');
     $aConversion['cid'] = 5;
     // Call the conversion logging function
     $aConversionInfo = MAX_Delivery_log_logConversion(1, $aConversion);
     // Ensure that the data was logged correctly
     $doData_bkt_a = OA_Dal::factoryDO('data_bkt_a');
     $doData_bkt_a->find();
     $rows = $doData_bkt_a->getRowCount();
     $this->assertEqual($rows, 2);
     $doData_bkt_a = OA_Dal::factoryDO('data_bkt_a');
     $doData_bkt_a->server_conv_id = 1;
     $doData_bkt_a->find();
     $rows = $doData_bkt_a->getRowCount();
     $this->assertEqual($rows, 1);
     $doData_bkt_a->fetch();
     $this->assertEqual($doData_bkt_a->server_ip, 'singleDB');
     $this->assertEqual($doData_bkt_a->tracker_id, 1);
     $this->assertEqual($doData_bkt_a->date_time, $oNowDate->format('%Y-%m-%d %H:%M:%S'));
     $this->assertEqual($doData_bkt_a->action_date_time, $oConversionDate->format('%Y-%m-%d %H:%M:%S'));
     $this->assertEqual($doData_bkt_a->creative_id, 2);
     $this->assertEqual($doData_bkt_a->zone_id, 3);
     $this->assertEqual($doData_bkt_a->ip_address, '127.0.0.99');
     $this->assertEqual($doData_bkt_a->action, MAX_CONNECTION_AD_CLICK);
     $this->assertEqual($doData_bkt_a->window, 60);
     $this->assertEqual($doData_bkt_a->status, MAX_CONNECTION_STATUS_APPROVED);
     $doData_bkt_a = OA_Dal::factoryDO('data_bkt_a');
     $doData_bkt_a->server_conv_id = 2;
     $doData_bkt_a->find();
     $rows = $doData_bkt_a->getRowCount();
     $this->assertEqual($rows, 1);
     $doData_bkt_a->fetch();
     $this->assertEqual($doData_bkt_a->server_ip, 'singleDB');
     $this->assertEqual($doData_bkt_a->tracker_id, 1);
     $this->assertEqual($doData_bkt_a->date_time, $oNowDate->format('%Y-%m-%d %H:%M:%S'));
     $this->assertEqual($doData_bkt_a->action_date_time, $oConversionDate->format('%Y-%m-%d %H:%M:%S'));
     $this->assertEqual($doData_bkt_a->creative_id, 5);
     $this->assertEqual($doData_bkt_a->zone_id, 3);
     $this->assertEqual($doData_bkt_a->ip_address, '127.0.0.99');
     $this->assertEqual($doData_bkt_a->action, MAX_CONNECTION_AD_CLICK);
     $this->assertEqual($doData_bkt_a->window, 60);
     $this->assertEqual($doData_bkt_a->status, MAX_CONNECTION_STATUS_APPROVED);
     $this->assertTrue(is_array($aConversionInfo));
     $this->assertTrue(is_array($aConversionInfo['deliveryLog:oxLogConversion:logConversion']));
     $this->assertEqual($aConversionInfo['deliveryLog:oxLogConversion:logConversion']['server_conv_id'], 2);
     $this->assertEqual($aConversionInfo['deliveryLog:oxLogConversion:logConversion']['server_raw_ip'], 'singleDB');
     // Uninstall the openXDeliveryLog plugin
     TestEnv::uninstallPluginPackage('openXDeliveryLog', false);
     // Restore the test configuration file
     TestEnv::restoreConfig();
 }
 function setUp()
 {
     TestEnv::restoreConfig();
 }
 /**
  * A method to test the summariseBucketsAggregate() method.
  */
 function testSummariseBucketsAggregate()
 {
     $aConf =& $GLOBALS['_MAX']['CONF'];
     $aConf['maintenance']['operationInterval'] = 60;
     // Prepare standard test parameters
     $statisticsTableName = $aConf['table']['prefix'] . 'data_intermediate_ad';
     $aMigrationMaps = array(0 => array('method' => 'aggregate', 'bucketTable' => $aConf['table']['prefix'] . 'data_bkt_r', 'dateTimeColumn' => 'interval_start', 'groupSource' => array(0 => 'interval_start', 1 => 'creative_id', 2 => 'zone_id'), 'groupDestination' => array(0 => 'date_time', 1 => 'ad_id', 2 => 'zone_id'), 'sumSource' => array(0 => 'count'), 'sumDestination' => array(0 => 'requests'), 'sumDefault' => array(0 => 0)), 1 => array('method' => 'aggregate', 'bucketTable' => $aConf['table']['prefix'] . 'data_bkt_m', 'dateTimeColumn' => 'interval_start', 'groupSource' => array(0 => 'interval_start', 1 => 'creative_id', 2 => 'zone_id'), 'groupDestination' => array(0 => 'date_time', 1 => 'ad_id', 2 => 'zone_id'), 'sumSource' => array(0 => 'count'), 'sumDestination' => array(0 => 'impressions'), 'sumDefault' => array(0 => 0)), 2 => array('method' => 'aggregate', 'bucketTable' => $aConf['table']['prefix'] . 'data_bkt_c', 'dateTimeColumn' => 'interval_start', 'groupSource' => array(0 => 'interval_start', 1 => 'creative_id', 2 => 'zone_id'), 'groupDestination' => array(0 => 'date_time', 1 => 'ad_id', 2 => 'zone_id'), 'sumSource' => array(0 => 'count'), 'sumDestination' => array(0 => 'clicks'), 'sumDefault' => array(0 => 0)));
     $aDates = array('start' => new Date('2008-08-21 09:00:00'), 'end' => new Date('2008-08-21 09:59:59'));
     // Prepare the DAL object
     $oFactory = new OX_Dal_Maintenance_Statistics_Factory();
     $oDalMaintenanceStatistics = $oFactory->factory();
     $oNowDate = new Date();
     $aExtras = array('operation_interval' => $aConf['maintenance']['operationInterval'], 'operation_interval_id' => OX_OperationInterval::convertDateToOperationIntervalID($aDates['start']), 'interval_start' => $oDalMaintenanceStatistics->oDbh->quote($aDates['start']->format('%Y-%m-%d %H:%M:%S'), 'timestamp') . $oDalMaintenanceStatistics->timestampCastString, 'interval_end' => $oDalMaintenanceStatistics->oDbh->quote($aDates['end']->format('%Y-%m-%d %H:%M:%S'), 'timestamp') . $oDalMaintenanceStatistics->timestampCastString, 'creative_id' => 0, 'updated' => $oDalMaintenanceStatistics->oDbh->quote($oNowDate->format('%Y-%m-%d %H:%M:%S'), 'timestamp') . $oDalMaintenanceStatistics->timestampCastString);
     // Test 1: Test with an incorrect method name in the mapping array
     $savedValue = $aMigrationMaps[0]['method'];
     $aMigrationMaps[0]['method'] = 'foo';
     $result = $oDalMaintenanceStatistics->summariseBucketsAggregate($statisticsTableName, $aMigrationMaps, $aDates, $aExtras);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDARGS);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsAggregate() called with migration map index '0' having method 'foo' != 'aggregate'.");
     $aMigrationMaps[0]['method'] = $savedValue;
     // Test 2: Test with a different number of groupSource and groupDestination columns
     $savedValue = $aMigrationMaps[0]['groupSource'][1];
     unset($aMigrationMaps[0]['groupSource'][1]);
     $result = $oDalMaintenanceStatistics->summariseBucketsAggregate($statisticsTableName, $aMigrationMaps, $aDates, $aExtras);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDARGS);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsAggregate() called with migration map index '0' having different number of 'groupSource' and 'groupDestination' columns.");
     $aMigrationMaps[0]['groupSource'][1] = $savedValue;
     // Test 3: Test with a different number of sumSource and sumDestination columns
     $savedValue = $aMigrationMaps[1]['sumSource'][0];
     unset($aMigrationMaps[1]['sumSource'][0]);
     $result = $oDalMaintenanceStatistics->summariseBucketsAggregate($statisticsTableName, $aMigrationMaps, $aDates, $aExtras);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDARGS);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsAggregate() called with migration map index '1' having different number of 'sumSource' and 'sumDestination' columns.");
     $aMigrationMaps[1]['sumSource'][0] = $savedValue;
     // Test 4: Test with a different number of sumSource and sumDefault columns
     $savedValue = $aMigrationMaps[2]['sumDefault'][0];
     unset($aMigrationMaps[2]['sumDefault'][0]);
     $result = $oDalMaintenanceStatistics->summariseBucketsAggregate($statisticsTableName, $aMigrationMaps, $aDates, $aExtras);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDARGS);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsAggregate() called with migration map index '2' having different number of 'sumSource' and 'sumDefault' columns.");
     $aMigrationMaps[2]['sumDefault'][0] = $savedValue;
     // Test 5: Test with a different groupDestination sets
     $savedValue = $aMigrationMaps[2]['groupDestination'][0];
     $aMigrationMaps[2]['groupDestination'][0] = 'foo';
     $result = $oDalMaintenanceStatistics->summariseBucketsAggregate($statisticsTableName, $aMigrationMaps, $aDates, $aExtras);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDARGS);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsAggregate() called with migration map indexes '0' and '2' having different 'groupDestination' arrays.");
     $aMigrationMaps[2]['groupDestination'][0] = $savedValue;
     // Test 6: Test with date parameters that are not really dates
     $savedValue = $aDates['start'];
     $aDates['start'] = 'foo';
     $result = $oDalMaintenanceStatistics->summariseBucketsAggregate($statisticsTableName, $aMigrationMaps, $aDates, $aExtras);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDARGS);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsAggregate() called with invalid start/end date parameters -- not Date objects.");
     $aDates['start'] = $savedValue;
     $savedValue = $aDates['end'];
     $aDates['end'] = 'foo';
     $result = $oDalMaintenanceStatistics->summariseBucketsAggregate($statisticsTableName, $aMigrationMaps, $aDates, $aExtras);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDARGS);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsAggregate() called with invalid start/end date parameters -- not Date objects.");
     $aDates['end'] = $savedValue;
     // Test 7: Test with invalid start/end dates
     $savedValue = $aDates['start'];
     $aDates['start'] = new Date('2008-08-21 08:00:00');
     $result = $oDalMaintenanceStatistics->summariseBucketsAggregate($statisticsTableName, $aMigrationMaps, $aDates, $aExtras);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDARGS);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsAggregate() called with invalid start/end date parameters -- not operation interval bounds.");
     $aDates['start'] = $savedValue;
     $savedValue = $aDates['end'];
     $aDates['end'] = new Date('2008-08-22 09:59:59');
     $result = $oDalMaintenanceStatistics->summariseBucketsAggregate($statisticsTableName, $aMigrationMaps, $aDates, $aExtras);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDARGS);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsAggregate() called with invalid start/end date parameters -- not operation interval bounds.");
     $aDates['end'] = $savedValue;
     // Test 8: Test with an invalid statistics table name
     $savedValue = $statisticsTableName;
     $statisticsTableName = 'foo';
     $result = $oDalMaintenanceStatistics->summariseBucketsAggregate($statisticsTableName, $aMigrationMaps, $aDates, $aExtras);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDREQUEST);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsAggregate() called with invalid statistics table 'foo'.");
     $statisticsTableName = $savedValue;
     // Test 9: Test with no data_bkt_r table in the database
     $result = $oDalMaintenanceStatistics->summariseBucketsAggregate($statisticsTableName, $aMigrationMaps, $aDates, $aExtras);
     $this->assertTrue(is_a($result, 'PEAR_Error'));
     $this->assertEqual($result->code, MAX_ERROR_INVALIDREQUEST);
     $this->assertEqual($result->message, "OX_Dal_Maintenance_Statistics::summariseBucketsAggregate() called with migration map index '0' having invalid bucket table '{$aConf['table']['prefix']}data_bkt_r'.");
     // Install the openXDeliveryLog plugin, which will create the
     // data_bkt_r, data_bkt_m and data_bkt_c tables required for testing
     TestEnv::installPluginPackage('openXDeliveryLog', false);
     // Test 10: Test with all tables present, but no data
     $result = $oDalMaintenanceStatistics->summariseBucketsAggregate($statisticsTableName, $aMigrationMaps, $aDates, $aExtras);
     $this->assertEqual($result, 0);
     // Insert some data into the data_bkt_r, data_bkt_m and
     // data_bkt_c tables in the incorrect operation interval
     $oData_bkt_r = OA_Dal::factoryDO('data_bkt_r');
     $oData_bkt_r->interval_start = '2008-08-21 08:00:00';
     $oData_bkt_r->creative_id = 1;
     $oData_bkt_r->zone_id = 2;
     $oData_bkt_r->count = 10;
     DataGenerator::generateOne($oData_bkt_r);
     $oData_bkt_m = OA_Dal::factoryDO('data_bkt_m');
     $oData_bkt_m->interval_start = '2008-08-21 08:00:00';
     $oData_bkt_m->creative_id = 1;
     $oData_bkt_m->zone_id = 2;
     $oData_bkt_m->count = 9;
     DataGenerator::generateOne($oData_bkt_m);
     $oData_bkt_c = OA_Dal::factoryDO('data_bkt_c');
     $oData_bkt_c->interval_start = '2008-08-21 08:00:00';
     $oData_bkt_c->creative_id = 1;
     $oData_bkt_c->zone_id = 2;
     $oData_bkt_c->count = 1;
     DataGenerator::generateOne($oData_bkt_c);
     // Test 11: Test with data in the incorrect operation interval
     $result = $oDalMaintenanceStatistics->summariseBucketsAggregate($statisticsTableName, $aMigrationMaps, $aDates, $aExtras);
     $this->assertEqual($result, 0);
     // Insert some data into the data_bkt_r, data_bkt_m and
     // data_bkt_c tables in the incorrect operation interval
     $oData_bkt_r = OA_Dal::factoryDO('data_bkt_r');
     $oData_bkt_r->interval_start = '2008-08-21 09:00:00';
     $oData_bkt_r->creative_id = 1;
     $oData_bkt_r->zone_id = 2;
     $oData_bkt_r->count = 10;
     DataGenerator::generateOne($oData_bkt_r);
     $oData_bkt_m = OA_Dal::factoryDO('data_bkt_m');
     $oData_bkt_m->interval_start = '2008-08-21 09:00:00';
     $oData_bkt_m->creative_id = 1;
     $oData_bkt_m->zone_id = 2;
     $oData_bkt_m->count = 9;
     DataGenerator::generateOne($oData_bkt_m);
     $oData_bkt_c = OA_Dal::factoryDO('data_bkt_c');
     $oData_bkt_c->interval_start = '2008-08-21 09:00:00';
     $oData_bkt_c->creative_id = 1;
     $oData_bkt_c->zone_id = 2;
     $oData_bkt_c->count = 1;
     DataGenerator::generateOne($oData_bkt_c);
     // Test 12: Test with data in the correct operation interval
     $result = $oDalMaintenanceStatistics->summariseBucketsAggregate($statisticsTableName, $aMigrationMaps, $aDates, $aExtras);
     $this->assertEqual($result, 1);
     $oData_intermediate_ad = OA_Dal::factoryDO('data_intermediate_ad');
     $oData_intermediate_ad->find();
     $rows = $oData_intermediate_ad->getRowCount();
     $this->assertEqual($rows, 1);
     $oData_intermediate_ad = OA_Dal::factoryDO('data_intermediate_ad');
     $oData_intermediate_ad->ad_id = 1;
     $oData_intermediate_ad->find();
     $rows = $oData_intermediate_ad->getRowCount();
     $this->assertEqual($rows, 1);
     $oData_intermediate_ad->fetch();
     $this->assertEqual($oData_intermediate_ad->date_time, '2008-08-21 09:00:00');
     $this->assertEqual($oData_intermediate_ad->operation_interval, $aConf['maintenance']['operationInterval']);
     $this->assertEqual($oData_intermediate_ad->operation_interval_id, OX_OperationInterval::convertDateToOperationIntervalID($aDates['start']));
     $this->assertEqual($oData_intermediate_ad->interval_start, '2008-08-21 09:00:00');
     $this->assertEqual($oData_intermediate_ad->interval_end, '2008-08-21 09:59:59');
     $this->assertEqual($oData_intermediate_ad->ad_id, 1);
     $this->assertEqual($oData_intermediate_ad->creative_id, 0);
     $this->assertEqual($oData_intermediate_ad->zone_id, 2);
     $this->assertEqual($oData_intermediate_ad->requests, 10);
     $this->assertEqual($oData_intermediate_ad->impressions, 9);
     $this->assertEqual($oData_intermediate_ad->clicks, 1);
     // Clean up generated data
     DataGenerator::cleanUp();
     // Insert some new data into the data_bkt_r, data_bkt_m and
     // data_bkt_c tables in the incorrect operation interval
     $oData_bkt_r = OA_Dal::factoryDO('data_bkt_r');
     $oData_bkt_r->interval_start = '2008-08-21 09:00:00';
     $oData_bkt_r->creative_id = 2;
     $oData_bkt_r->zone_id = 2;
     $oData_bkt_r->count = 10;
     DataGenerator::generateOne($oData_bkt_r);
     $oData_bkt_m = OA_Dal::factoryDO('data_bkt_m');
     $oData_bkt_m->interval_start = '2008-08-21 09:00:00';
     $oData_bkt_m->creative_id = 2;
     $oData_bkt_m->zone_id = 2;
     $oData_bkt_m->count = 9;
     DataGenerator::generateOne($oData_bkt_m);
     $oData_bkt_c = OA_Dal::factoryDO('data_bkt_c');
     $oData_bkt_c->interval_start = '2008-08-21 09:00:00';
     $oData_bkt_c->creative_id = 2;
     $oData_bkt_c->zone_id = 2;
     $oData_bkt_c->count = 1;
     DataGenerator::generateOne($oData_bkt_c);
     $oData_bkt_r = OA_Dal::factoryDO('data_bkt_r');
     $oData_bkt_r->interval_start = '2008-08-21 09:00:00';
     $oData_bkt_r->creative_id = 11;
     $oData_bkt_r->zone_id = 12;
     $oData_bkt_r->count = 10000;
     DataGenerator::generateOne($oData_bkt_r);
     $oData_bkt_m = OA_Dal::factoryDO('data_bkt_m');
     $oData_bkt_m->interval_start = '2008-08-21 09:00:00';
     $oData_bkt_m->creative_id = 11;
     $oData_bkt_m->zone_id = 12;
     $oData_bkt_m->count = 9960;
     DataGenerator::generateOne($oData_bkt_m);
     $oData_bkt_c = OA_Dal::factoryDO('data_bkt_c');
     $oData_bkt_c->interval_start = '2008-08-21 09:00:00';
     $oData_bkt_c->creative_id = 11;
     $oData_bkt_c->zone_id = 12;
     $oData_bkt_c->count = 500;
     DataGenerator::generateOne($oData_bkt_c);
     // Test 13: Test with new data in the correct operation interval
     $result = $oDalMaintenanceStatistics->summariseBucketsAggregate($statisticsTableName, $aMigrationMaps, $aDates, $aExtras);
     $this->assertEqual($result, 2);
     $oData_intermediate_ad = OA_Dal::factoryDO('data_intermediate_ad');
     $oData_intermediate_ad->find();
     $rows = $oData_intermediate_ad->getRowCount();
     $this->assertEqual($rows, 3);
     $oData_intermediate_ad = OA_Dal::factoryDO('data_intermediate_ad');
     $oData_intermediate_ad->ad_id = 1;
     $oData_intermediate_ad->find();
     $rows = $oData_intermediate_ad->getRowCount();
     $this->assertEqual($rows, 1);
     $oData_intermediate_ad->fetch();
     $this->assertEqual($oData_intermediate_ad->date_time, '2008-08-21 09:00:00');
     $this->assertEqual($oData_intermediate_ad->operation_interval, $aConf['maintenance']['operationInterval']);
     $this->assertEqual($oData_intermediate_ad->operation_interval_id, OX_OperationInterval::convertDateToOperationIntervalID($aDates['start']));
     $this->assertEqual($oData_intermediate_ad->interval_start, '2008-08-21 09:00:00');
     $this->assertEqual($oData_intermediate_ad->interval_end, '2008-08-21 09:59:59');
     $this->assertEqual($oData_intermediate_ad->ad_id, 1);
     $this->assertEqual($oData_intermediate_ad->creative_id, 0);
     $this->assertEqual($oData_intermediate_ad->zone_id, 2);
     $this->assertEqual($oData_intermediate_ad->requests, 10);
     $this->assertEqual($oData_intermediate_ad->impressions, 9);
     $this->assertEqual($oData_intermediate_ad->clicks, 1);
     $oData_intermediate_ad = OA_Dal::factoryDO('data_intermediate_ad');
     $oData_intermediate_ad->ad_id = 2;
     $oData_intermediate_ad->find();
     $rows = $oData_intermediate_ad->getRowCount();
     $this->assertEqual($rows, 1);
     $oData_intermediate_ad->fetch();
     $this->assertEqual($oData_intermediate_ad->date_time, '2008-08-21 09:00:00');
     $this->assertEqual($oData_intermediate_ad->operation_interval, $aConf['maintenance']['operationInterval']);
     $this->assertEqual($oData_intermediate_ad->operation_interval_id, OX_OperationInterval::convertDateToOperationIntervalID($aDates['start']));
     $this->assertEqual($oData_intermediate_ad->interval_start, '2008-08-21 09:00:00');
     $this->assertEqual($oData_intermediate_ad->interval_end, '2008-08-21 09:59:59');
     $this->assertEqual($oData_intermediate_ad->ad_id, 2);
     $this->assertEqual($oData_intermediate_ad->creative_id, 0);
     $this->assertEqual($oData_intermediate_ad->zone_id, 2);
     $this->assertEqual($oData_intermediate_ad->requests, 10);
     $this->assertEqual($oData_intermediate_ad->impressions, 9);
     $this->assertEqual($oData_intermediate_ad->clicks, 1);
     $oData_intermediate_ad = OA_Dal::factoryDO('data_intermediate_ad');
     $oData_intermediate_ad->ad_id = 11;
     $oData_intermediate_ad->find();
     $rows = $oData_intermediate_ad->getRowCount();
     $this->assertEqual($rows, 1);
     $oData_intermediate_ad->fetch();
     $this->assertEqual($oData_intermediate_ad->date_time, '2008-08-21 09:00:00');
     $this->assertEqual($oData_intermediate_ad->operation_interval, $aConf['maintenance']['operationInterval']);
     $this->assertEqual($oData_intermediate_ad->operation_interval_id, OX_OperationInterval::convertDateToOperationIntervalID($aDates['start']));
     $this->assertEqual($oData_intermediate_ad->interval_start, '2008-08-21 09:00:00');
     $this->assertEqual($oData_intermediate_ad->interval_end, '2008-08-21 09:59:59');
     $this->assertEqual($oData_intermediate_ad->ad_id, 11);
     $this->assertEqual($oData_intermediate_ad->creative_id, 0);
     $this->assertEqual($oData_intermediate_ad->zone_id, 12);
     $this->assertEqual($oData_intermediate_ad->requests, 10000);
     $this->assertEqual($oData_intermediate_ad->impressions, 9960);
     $this->assertEqual($oData_intermediate_ad->clicks, 500);
     // Clean up generated data
     DataGenerator::cleanUp();
     // Also clean up the data migrated into the statistics table
     $oData_intermediate_ad = OA_Dal::factoryDO('data_intermediate_ad');
     $oData_intermediate_ad->data_intermediate_ad_id = 1;
     $oData_intermediate_ad->find();
     $oData_intermediate_ad->delete();
     $oData_intermediate_ad = OA_Dal::factoryDO('data_intermediate_ad');
     $oData_intermediate_ad->data_intermediate_ad_id = 2;
     $oData_intermediate_ad->find();
     $oData_intermediate_ad->delete();
     $oData_intermediate_ad = OA_Dal::factoryDO('data_intermediate_ad');
     $oData_intermediate_ad->data_intermediate_ad_id = 3;
     $oData_intermediate_ad->find();
     $oData_intermediate_ad->delete();
     // Uninstall the installed plugin
     TestEnv::uninstallPluginPackage('openXDeliveryLog', false);
     // Restore the test environment configuration
     TestEnv::restoreConfig();
 }
 function tearDown()
 {
     TestEnv::restoreConfig();
 }
 function test_installPackage()
 {
     Mock::generatePartial('OX_Extension', $oMockExtension = 'OX_Extension' . rand(), array('_instantiateClass', 'runTasksPluginPostInstallation', 'runTasksPluginPreInstallation'));
     $oExtension = new $oMockExtension($this);
     Mock::generatePartial('OX_PluginManager', $oMockManager = 'OX_PluginManager' . rand(), array('_instantiateClass', 'unpackPlugin', '_installComponentGroups', '_registerPackage', '_uninstallComponentGroups', '_auditInit', '_auditSetKeys', '_auditStart', '_auditUpdate', '_auditSetID', 'enablePackage'));
     $oManager = new $oMockManager($this);
     $oManager->setReturnValue('_auditStart', true);
     $oManager->setReturnValue('_uninstallComponentGroups', true);
     $oManager->setReturnValue('_instantiateClass', $oExtension);
     $oManager->expectCallCount('_instantiateClass', 1);
     $oManager->setReturnValue('enablePackage', true);
     $oManager->expectCallCount('enablePackage', 0);
     // Test 1 - package unpack error
     $oManager->setReturnValueAt(0, 'unpackPlugin', false);
     $aFile = array('tmp_name' => MAX_PATH . $this->testpathData . 'testParsePluginFull.xml', 'name' => 'testParsePluginFull.xml');
     $this->assertFalse($oManager->installPackage($aFile));
     // Test 2 - plugin installation error
     $oManager->setReturnValueAt(1, 'unpackPlugin', true);
     $oManager->setReturnValueAt(0, '_installComponentGroups', false);
     $aFile = array('tmp_name' => MAX_PATH . $this->testpathData . 'testParsePluginFull.xml', 'name' => 'testParsePluginFull.xml');
     $this->assertFalse($oManager->installPackage($aFile));
     // Test 3 - register settings error
     $oManager->setReturnValueAt(2, 'unpackPlugin', true);
     $oManager->setReturnValueAt(1, '_installComponentGroups', true);
     $oManager->setReturnValueAt(0, '_registerPackage', false);
     $aFile = array('tmp_name' => MAX_PATH . $this->testpathData . 'testParsePluginFull.xml', 'name' => 'testParsePluginFull.xml');
     $this->assertFalse($oManager->installPackage($aFile));
     // Test 4 - success
     $oManager->setReturnValueAt(3, 'unpackPlugin', true);
     $oManager->setReturnValueAt(2, '_installComponentGroups', true);
     $oManager->setReturnValueAt(1, '_registerPackage', true);
     $aFile = array('tmp_name' => MAX_PATH . $this->testpathData . 'testParsePluginFull.xml', 'name' => 'testParsePluginFull.xml');
     // Disable auto-enable for this one (brings enablePackage call count down to 2
     $GLOBALS['_MAX']['CONF']['pluginSettings']['enableOnInstall'] = false;
     $this->assertTrue($oManager->installPackage($aFile));
     $oManager->expectCallCount('unpackPlugin', 4);
     $oManager->expectCallCount('_installComponentGroups', 3);
     $oManager->expectCallCount('_registerPackage', 2);
     $oManager->tally();
     TestEnv::restoreConfig();
 }
 /**
  * A method to test when there are old format raw requests,
  * impressions and clicks, in the operation interval being
  * migrated.
  */
 function testSimpleValidData()
 {
     $aConf =& $GLOBALS['_MAX']['CONF'];
     $aConf['maintenance']['operationInterval'] = 60;
     // Prepare an array of the required tables used in testing
     $aTables = array($aConf['table']['prefix'] . $aConf['table']['data_raw_ad_request'] => $aConf['table']['prefix'] . 'data_bkt_r', $aConf['table']['prefix'] . $aConf['table']['data_raw_ad_impression'] => $aConf['table']['prefix'] . 'data_bkt_m', $aConf['table']['prefix'] . $aConf['table']['data_raw_ad_click'] => $aConf['table']['prefix'] . 'data_bkt_c');
     // Install the openXDeliveryLog plugin, which will create the
     // data bucket tables required for testing
     TestEnv::installPluginPackage('openXDeliveryLog', false);
     // Ensure that there are no old format raw data
     foreach ($aTables as $rawTable => $bucketTable) {
         $query = "\n                SELECT\n                    COUNT(*) AS count\n                FROM\n                    " . $this->oDbh->quoteIdentifier($rawTable, true);
         $rsResult = $this->oDbh->query($query);
         $this->assertNotA($rsReults, 'PEAR_Error');
         $rows = $rsResult->numRows();
         $this->assertEqual($rows, 1);
         $aRow = $rsResult->fetchRow();
         $this->assertEqual($aRow['count'], 0);
     }
     // Ensure that there are no new format bucket data
     foreach ($aTables as $rawTable => $bucketTable) {
         $query = "\n                SELECT\n                    COUNT(*) AS count\n                FROM\n                    " . $this->oDbh->quoteIdentifier($bucketTable, true);
         $rsResult = $this->oDbh->query($query);
         $this->assertNotA($rsReults, 'PEAR_Error');
         $rows = $rsResult->numRows();
         $this->assertEqual($rows, 1);
         $aRow = $rsResult->fetchRow();
         $this->assertEqual($aRow['count'], 0);
     }
     // Insert some old style raw data in an operation interval
     // that will be migrated
     foreach ($aTables as $rawTable => $bucketTable) {
         $query = "\n                INSERT INTO\n                    " . $this->oDbh->quoteIdentifier($rawTable, true) . "\n                    (\n                        date_time,\n                        ad_id,\n                        creative_id,\n                        zone_id\n                    )\n                VALUES\n                    (\n                        '2009-01-09 12:30:00',\n                        1,\n                        0,\n                        1\n                    )";
         $this->oDbh->exec($query);
     }
     // Ensure that the old format raw data was inserted correctly
     foreach ($aTables as $rawTable => $bucketTable) {
         $query = "\n                SELECT\n                    COUNT(*) AS count\n                FROM\n                    " . $this->oDbh->quoteIdentifier($rawTable, true);
         $rsResult = $this->oDbh->query($query);
         $this->assertNotA($rsReults, 'PEAR_Error');
         $rows = $rsResult->numRows();
         $this->assertEqual($rows, 1);
         $aRow = $rsResult->fetchRow();
         $this->assertEqual($aRow['count'], 1);
     }
     // Run the migration of raw data DAL code for a given OI
     $oStart = new Date('2009-01-09 12:00:00');
     $oEnd = new Date('2009-01-09 12:59:59');
     $this->oDal->migrateRawRequests($oStart, $oEnd);
     $this->oDal->migrateRawImpressions($oStart, $oEnd);
     $this->oDal->migrateRawClicks($oStart, $oEnd);
     // Test that the data was migrated correctly
     foreach ($aTables as $rawTable => $bucketTable) {
         $query = "\n                SELECT\n                    COUNT(*) AS count\n                FROM\n                    " . $this->oDbh->quoteIdentifier($bucketTable, true);
         $rsResult = $this->oDbh->query($query);
         $this->assertNotA($rsReults, 'PEAR_Error');
         $rows = $rsResult->numRows();
         $this->assertEqual($rows, 1);
         $aRow = $rsResult->fetchRow();
         $this->assertEqual($aRow['count'], 1);
         $query = "\n                SELECT\n                    *\n                FROM\n                    " . $this->oDbh->quoteIdentifier($bucketTable, true);
         $rsResult = $this->oDbh->query($query);
         $this->assertNotA($rsReults, 'PEAR_Error');
         $rows = $rsResult->numRows();
         $this->assertEqual($rows, 1);
         $aRow = $rsResult->fetchRow();
         $this->assertEqual($aRow['interval_start'], '2009-01-09 12:00:00');
         $this->assertEqual($aRow['creative_id'], 1);
         $this->assertEqual($aRow['zone_id'], 1);
         $this->assertEqual($aRow['count'], 1);
     }
     // Uninstall the installed plugin
     TestEnv::uninstallPluginPackage('openXDeliveryLog', false);
     // Restore the test environment configuration
     TestEnv::restoreConfig();
 }
 /**
  * A method to test the MAX_Delivery_log_getArrGetVariable() function.
  *
  * Requirements:
  * Test 1: Test with a bad config name, and ensure an empty array is returned.
  * Test 2: Test with no request value defined, and ensure an empty array is
  *         returned.
  * Test 3: Test with a request value defined, and ensure an array of that
  *         value is returned.
  * Test 4: Test with a "multiple item" request value defined, and ensure an
  *         array of the values is returned.
  */
 function test_MAX_Delivery_log_getArrGetVariable()
 {
     // Test 1
     $aReturn = MAX_Delivery_log_getArrGetVariable('foo');
     $this->assertTrue(is_array($aReturn));
     $this->assertTrue(empty($aReturn));
     // Test 2
     $conf =& $GLOBALS['_MAX']['CONF'];
     $conf['var']['blockAd'] = 'MAXBLOCK';
     unset($_GET['MAXBLOCK']);
     $aReturn = MAX_Delivery_log_getArrGetVariable('blockAd');
     $this->assertTrue(is_array($aReturn));
     $this->assertTrue(empty($aReturn));
     // Test 3
     $conf =& $GLOBALS['_MAX']['CONF'];
     $conf['var']['blockAd'] = 'MAXBLOCK';
     $_GET['MAXBLOCK'] = 1;
     $aReturn = MAX_Delivery_log_getArrGetVariable('blockAd');
     $this->assertTrue(is_array($aReturn));
     $this->assertFalse(empty($aReturn));
     $this->assertEqual(count($aReturn), 1);
     $this->assertEqual($aReturn[0], 1);
     // Test 3
     $conf =& $GLOBALS['_MAX']['CONF'];
     $conf['var']['blockAd'] = 'MAXBLOCK';
     $_GET['MAXBLOCK'] = 1 . $GLOBALS['_MAX']['MAX_DELIVERY_MULTIPLE_DELIMITER'] . 5;
     $aReturn = MAX_Delivery_log_getArrGetVariable('blockAd');
     $this->assertTrue(is_array($aReturn));
     $this->assertFalse(empty($aReturn));
     $this->assertEqual(count($aReturn), 2);
     $this->assertEqual($aReturn[0], 1);
     $this->assertEqual($aReturn[1], 5);
     // Reset the configuration
     TestEnv::restoreConfig();
 }
 function test_getListOfRegisteredComponentsForHook()
 {
     $GLOBALS['_MAX']['CONF']['pluginPaths']['packages'] = '/lib/OX/Plugin/tests/data/plugins/etc/';
     $GLOBALS['_MAX']['CONF']['pluginPaths']['admin'] = '/lib/OX/Plugin/tests/data/www/admin/plugins/';
     $GLOBALS['_MAX']['CONF']['plugins'] = array('testPluginPackage' => 1);
     $GLOBALS['_MAX']['CONF']['pluginGroupComponents'] = array('testPlugin' => 1);
     require_once LIB_PATH . '/Extension/ExtensionCommon.php';
     //generate test cache
     $oExtension = new OX_Extension_Common();
     $oExtension->cacheComponentHooks();
     $aHooks = OX_Component::getListOfRegisteredComponentsForHook('duringTest');
     $this->assertIsA($aHooks, 'array');
     $this->assertEqual(count($aHooks), 1);
     $this->assertEqual($aHooks[0], 'admin:testPlugin:testPlugin');
     //remove cache
     unset($GLOBALS['_MAX']['ComponentHooks']);
     $oCache = new OA_Cache('Plugins', 'ComponentHooks');
     $oCache->setFileNameProtection(false);
     $oCache->clear();
     //should auto regenerate cache
     $aHooks = OX_Component::getListOfRegisteredComponentsForHook('duringTest');
     $this->assertIsA($aHooks, 'array');
     $this->assertEqual(count($aHooks), 1);
     $this->assertEqual($aHooks[0], 'admin:testPlugin:testPlugin');
     //cache file should be regenerated
     $aAllHooks = $oCache->load();
     $this->assertEqual($aHooks, $aAllHooks['duringTest']);
     TestEnv::restoreConfig();
     $oCache->clear();
 }
 /**
  * A method to test the MAX_Delivery_log_logAdRequest(),
  * MAX_Delivery_log_logAdImpression() and MAX_Delivery_log_logAdClick()
  * functions.
  */
 function testRequestImpressionClickFunction()
 {
     $aConf =& $GLOBALS['_MAX']['CONF'];
     $aConf['maintenance']['operationInterval'] = 60;
     $GLOBALS['_MAX']['NOW'] = time();
     $oNowDate = new Date($GLOBALS['_MAX']['NOW']);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oNowDate);
     $intervalStart = $aDates['start']->format('%Y-%m-%d %H:%M:%S');
     $aTables = array('MAX_Delivery_log_logAdRequest' => 'data_bkt_r', 'MAX_Delivery_log_logAdImpression' => 'data_bkt_m', 'MAX_Delivery_log_logAdClick' => 'data_bkt_c');
     foreach ($aTables as $function => $table) {
         // Test to ensure that the openXDeliveryLog plugin's data bucket
         // table does not exist
         $oTable = new OA_DB_Table();
         $tableExists = $oTable->extistsTable($aConf['table']['prefix'] . $table);
         $this->assertFalse($tableExists);
         // Test calling the main logging function without any plugins installed,
         // to ensure that this does not result in any kind of error
         unset($GLOBALS['_MAX']['deliveryData']['Plugin_deliveryDataPrepare_oxDeliveryDataPrepare_dataCommon']);
         call_user_func_array($function, array(1, 1));
     }
     // Install the openXDeliveryLog plugin
     TestEnv::installPluginPackage('openXDeliveryLog', false);
     foreach ($aTables as $function => $table) {
         // Test to ensure that the openXDeliveryLog plugin's data bucket
         // table now does exist
         $tableExists = $oTable->extistsTable($aConf['table']['prefix'] . $table);
         $this->assertTrue($tableExists);
         // Ensure that there are is nothing logged in the data bucket table
         $doData_bkt = OA_Dal::factoryDO($table);
         $doData_bkt->find();
         $rows = $doData_bkt->getRowCount();
         $this->assertEqual($rows, 0);
         // Call the main logging function
         unset($GLOBALS['_MAX']['deliveryData']['Plugin_deliveryDataPrepare_oxDeliveryDataPrepare_dataCommon']);
         call_user_func_array($function, array(1, 1));
         // Ensure that the data was logged correctly
         $doData_bkt = OA_Dal::factoryDO($table);
         $doData_bkt->find();
         $rows = $doData_bkt->getRowCount();
         if ($table == 'data_bkt_r') {
             // Request logging is disabled by default. Nothing should have been logged by now
             $this->assertEqual($rows, 0);
             // Enable it
             $GLOBALS['_MAX']['CONF']['logging']['adRequests'] = true;
             unset($GLOBALS['_MAX']['deliveryData']['Plugin_deliveryDataPrepare_oxDeliveryDataPrepare_dataCommon']);
             call_user_func_array($function, array(1, 1));
             // Now ensure that the data was logged correctly
             $doData_bkt->find();
             $rows = $doData_bkt->getRowCount();
         }
         $this->assertEqual($rows, 1);
         $doData_bkt = OA_Dal::factoryDO($table);
         $doData_bkt->creative_id = 1;
         $doData_bkt->zone_id = 1;
         $doData_bkt->find();
         $rows = $doData_bkt->getRowCount();
         $this->assertEqual($rows, 1);
         $doData_bkt->fetch();
         $this->assertEqual($doData_bkt->count, 1);
         $this->assertEqual($doData_bkt->interval_start, $intervalStart);
         // Call the main logging function again
         unset($GLOBALS['_MAX']['deliveryData']['Plugin_deliveryDataPrepare_oxDeliveryDataPrepare_dataCommon']);
         call_user_func_array($function, array(1, 1));
         // Ensure that the data was logged correctly
         $doData_bkt = OA_Dal::factoryDO($table);
         $doData_bkt->find();
         $rows = $doData_bkt->getRowCount();
         $this->assertEqual($rows, 1);
         $doData_bkt = OA_Dal::factoryDO($table);
         $doData_bkt->creative_id = 1;
         $doData_bkt->zone_id = 1;
         $doData_bkt->find();
         $rows = $doData_bkt->getRowCount();
         $this->assertEqual($rows, 1);
         $doData_bkt->fetch();
         $this->assertEqual($doData_bkt->count, 2);
         $this->assertEqual($doData_bkt->interval_start, $intervalStart);
         // Call the main logging function again, but with a differen
         // creative/zone pair
         unset($GLOBALS['_MAX']['deliveryData']['Plugin_deliveryDataPrepare_oxDeliveryDataPrepare_dataCommon']);
         call_user_func_array($function, array(2, 1));
         // Ensure that the data was logged correctly
         $doData_bkt = OA_Dal::factoryDO($table);
         $doData_bkt->find();
         $rows = $doData_bkt->getRowCount();
         $this->assertEqual($rows, 2);
         $doData_bkt = OA_Dal::factoryDO($table);
         $doData_bkt->creative_id = 1;
         $doData_bkt->zone_id = 1;
         $doData_bkt->find();
         $rows = $doData_bkt->getRowCount();
         $this->assertEqual($rows, 1);
         $doData_bkt->fetch();
         $this->assertEqual($doData_bkt->count, 2);
         $this->assertEqual($doData_bkt->interval_start, $intervalStart);
         $doData_bkt = OA_Dal::factoryDO($table);
         $doData_bkt->creative_id = 2;
         $doData_bkt->zone_id = 1;
         $doData_bkt->find();
         $rows = $doData_bkt->getRowCount();
         $this->assertEqual($rows, 1);
         $doData_bkt->fetch();
         $this->assertEqual($doData_bkt->count, 1);
         $this->assertEqual($doData_bkt->interval_start, $intervalStart);
     }
     // Uninstall the openXDeliveryLog plugin
     TestEnv::uninstallPluginPackage('openXDeliveryLog', false);
     // Restore the test configuration file
     TestEnv::restoreConfig();
 }
 function test_writeConfig()
 {
     TestEnv::restoreConfig();
     // TEST 1
     $hostAdmin = 'admin.mydomain.net';
     $_SERVER['HTTP_HOST'] = $hostDelivery = 'delivery.mydomain.net';
     $fileDefault = MAX_PATH . '/var/default.conf.php';
     $fileFake = MAX_PATH . '/var/' . $hostAdmin . '.conf.php';
     $fileReal = MAX_PATH . '/var/' . $hostDelivery . '.conf.php';
     if (file_exists($fileDefault)) {
         @copy($fileDefault, $fileDefault . '.bak');
         @unlink($fileDefault);
     }
     @unlink($fileReal);
     @unlink($fileFake);
     $oConf = new OA_Upgrade_Config();
     // Build the local conf array manually.
     $aConfig['webpath']['admin'] = $hostAdmin;
     $aConfig['webpath']['delivery'] = $hostDelivery;
     $aConfig['webpath']['deliverySSL'] = $hostDelivery;
     $oConf->setupConfigWebPath($aConfig['webpath']);
     $this->assertTrue($oConf->writeConfig(), 'Error writing config file');
     $this->assertTrue(file_exists($fileReal), 'Real config file does not exist');
     $this->assertTrue(file_exists($fileFake), 'Fake config file does not exist');
     $aRealConfig = @parse_ini_file($fileReal, true);
     $this->assertEqual($oConf->aConfig, $aRealConfig, 'Delivery config has incorrect values');
     $this->assertFalse(isset($aRealConfig['realConfig']));
     $this->assertTrue(isset($aRealConfig['openads']));
     $this->assertEqual($aRealConfig['openads']['installed'], 1);
     $this->assertEqual($aRealConfig['webpath']['admin'], $hostAdmin);
     $this->assertEqual($aRealConfig['webpath']['delivery'], $hostDelivery);
     $this->assertEqual($aRealConfig['webpath']['deliverySSL'], $hostDelivery);
     $aFakeConfig = @parse_ini_file($fileFake, true);
     $this->assertTrue(isset($aFakeConfig['realConfig']));
     $this->assertTrue($aFakeConfig['realConfig'], $hostDelivery);
     // default.conf.php only gets created if no other foreign confs exist
     if (file_exists($fileDefault)) {
         $aDefConfig = @parse_ini_file($fileDefault, true);
         $this->assertTrue(isset($aDefConfig['realConfig']));
         $this->assertTrue($aDefConfig['realConfig'], $hostDelivery);
         @unlink($fileDefault);
     }
     // Clean up
     @unlink($fileReal);
     @unlink($fileFake);
     TestEnv::restoreConfig();
     // TEST 2  : reverse the hosts
     $hostAdmin = 'admin.mydomain.net';
     $hostDelivery = 'delivery.mydomain.net';
     $fileReal = MAX_PATH . '/var/' . $hostAdmin . '.conf.php';
     $fileFake = MAX_PATH . '/var/' . $hostDelivery . '.conf.php';
     @unlink($fileAdmin);
     @unlink($fileDelivery);
     $oConf = new OA_Upgrade_Config();
     // Build the local conf array manually.
     $aConfig['webpath']['admin'] = $hostDelivery;
     $aConfig['webpath']['delivery'] = $hostAdmin;
     $aConfig['webpath']['deliverySSL'] = $hostAdmin;
     $oConf->setupConfigWebPath($aConfig['webpath']);
     $this->assertTrue($oConf->writeConfig(), 'Error writing config file');
     $this->assertTrue(file_exists($fileReal), 'Real config file does not exist');
     $this->assertTrue(file_exists($fileFake), 'Fake config file does not exist');
     $aRealConfig = @parse_ini_file($fileReal, true);
     $this->assertEqual($oConf->aConfig, $aRealConfig, 'Real config has incorrect values');
     $this->assertFalse(isset($aRealConfig['realConfig']));
     $this->assertTrue(isset($aRealConfig['openads']));
     $this->assertEqual($aRealConfig['openads']['installed'], 1);
     $this->assertEqual($aRealConfig['webpath']['admin'], $hostDelivery);
     $this->assertEqual($aRealConfig['webpath']['delivery'], $hostAdmin);
     $this->assertEqual($aRealConfig['webpath']['deliverySSL'], $hostAdmin);
     $aFakeConfig = @parse_ini_file($fileFake, true);
     $this->assertTrue(isset($aFakeConfig['realConfig']));
     $this->assertTrue($aFakeConfig['realConfig'], $hostAdmin);
     // default.conf.php only gets created if no other foreign confs exist
     if (file_exists($fileDefault)) {
         $aDefConfig = @parse_ini_file($fileDefault, true);
         $this->assertTrue(isset($aDefConfig['realConfig']));
         $this->assertTrue($aDefConfig['realConfig'], $hostAdmin);
         @unlink($fileDefault);
         @copy($fileDefault . '.bak', $fileDefault);
         @unlink($fileDefault . '.bak');
     }
     // Clean up
     @unlink($fileReal);
     @unlink($fileFake);
     TestEnv::restoreConfig();
 }
 /**
  * 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();
 }
 /**
  * A method to test the getProcessLastRunInfo() method.
  *
  * Requirements:
  * Test 1: Test with invalid data, and ensure false is returned.
  * Test 2: Test with no data in the database and ensure null is returned.
  * Test 3: Test with bad table and column names, and ensure false is returned.
  * Test 4: Test that the correct values are returned from data_ tables.
  * Test 5: Test that the correct values are returned from log_ tables.
  */
 function testGetProcessLastRunInfo()
 {
     $aConf =& $GLOBALS['_MAX']['CONF'];
     $oDbh =& OA_DB::singleton();
     $log_maintenance_priority = $aConf['table']['prefix'] . $aConf['table']['log_maintenance_priority'];
     $data_raw_ad_impression = $aConf['table']['prefix'] . $aConf['table']['data_raw_ad_impression'];
     $oDalMaintenanceCommon = new OA_Dal_Maintenance_Common();
     // Test 1
     $result = $oDalMaintenanceCommon->getProcessLastRunInfo($aConf['table']['log_maintenance_priority'], 'foo', null, 'start_run', array());
     $this->assertFalse($result);
     $result = $oDalMaintenanceCommon->getProcessLastRunInfo($aConf['table']['log_maintenance_priority'], array(), null, 'start_run', 'foo');
     $this->assertFalse($result);
     // Test 2
     $result = $oDalMaintenanceCommon->getProcessLastRunInfo($aConf['table']['log_maintenance_priority']);
     $this->assertNull($result);
     $result = $oDalMaintenanceCommon->getProcessLastRunInfo($aConf['table']['log_maintenance_priority'], array(), null, 'start_run', array('tableName' => $aConf['table']['data_raw_ad_impression'], 'type' => 'hour'));
     $this->assertNull($result);
     // Test 3
     RV::disableErrorHandling();
     $result = $oDalMaintenanceCommon->getProcessLastRunInfo('foo', array(), null, 'start_run', array());
     $this->assertFalse($result);
     $result = $oDalMaintenanceCommon->getProcessLastRunInfo($aConf['table']['log_maintenance_priority'], array('foo'), null, 'start_run', array());
     $this->assertFalse($result);
     $result = $oDalMaintenanceCommon->getProcessLastRunInfo($aConf['table']['log_maintenance_priority'], array(), null, 'start_run', array('tableName' => 'foo', 'type' => 'hour'));
     $this->assertFalse($result);
     RV::enableErrorHandling();
     // Test 4
     $query = "\n            INSERT INTO\n                " . $oDbh->quoteIdentifier($data_raw_ad_impression, true) . "\n                (\n                    date_time,\n                    ad_id,\n                    creative_id,\n                    zone_id\n                )\n            VALUES\n                (\n                    '2006-10-06 08:53:42',\n                    1,\n                    1,\n                    1\n                )";
     $rows = $oDbh->exec($query);
     $aResult = $oDalMaintenanceCommon->getProcessLastRunInfo($aConf['table']['log_maintenance_priority'], array('operation_interval'), null, 'start_run', array('tableName' => $aConf['table']['data_raw_ad_impression'], 'type' => 'hour'));
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 1);
     $this->assertEqual($aResult['updated_to'], '2006-10-06 07:59:59');
     $query = "\n            INSERT INTO\n                " . $oDbh->quoteIdentifier($data_raw_ad_impression, true) . "\n                (\n                    date_time,\n                    ad_id,\n                    creative_id,\n                    zone_id\n                )\n            VALUES\n                (\n                    '2006-10-06 09:53:42',\n                    1,\n                    1,\n                    1\n                )";
     $rows = $oDbh->exec($query);
     $aResult = $oDalMaintenanceCommon->getProcessLastRunInfo($aConf['table']['log_maintenance_priority'], array('operation_interval'), null, 'start_run', array('tableName' => $aConf['table']['data_raw_ad_impression'], 'type' => 'hour'));
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 1);
     $this->assertEqual($aResult['updated_to'], '2006-10-06 07:59:59');
     $aConf['maintenance']['operationInterval'] = 60;
     $aResult = $oDalMaintenanceCommon->getProcessLastRunInfo($aConf['table']['log_maintenance_priority'], array('operation_interval'), null, 'start_run', array('tableName' => $aConf['table']['data_raw_ad_impression'], 'type' => 'hour'));
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 1);
     $this->assertEqual($aResult['updated_to'], '2006-10-06 07:59:59');
     $aResult = $oDalMaintenanceCommon->getProcessLastRunInfo($aConf['table']['log_maintenance_priority'], array('operation_interval'), null, 'start_run', array('tableName' => $aConf['table']['data_raw_ad_impression'], 'type' => 'oi'));
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 1);
     $this->assertEqual($aResult['updated_to'], '2006-10-06 07:59:59');
     $aConf['maintenance']['operationInterval'] = 30;
     $aResult = $oDalMaintenanceCommon->getProcessLastRunInfo($aConf['table']['log_maintenance_priority'], array('operation_interval'), null, 'start_run', array('tableName' => $aConf['table']['data_raw_ad_impression'], 'type' => 'hour'));
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 1);
     $this->assertEqual($aResult['updated_to'], '2006-10-06 07:59:59');
     $aResult = $oDalMaintenanceCommon->getProcessLastRunInfo($aConf['table']['log_maintenance_priority'], array('operation_interval'), null, 'start_run', array('tableName' => $aConf['table']['data_raw_ad_impression'], 'type' => 'oi'));
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 1);
     $this->assertEqual($aResult['updated_to'], '2006-10-06 08:29:59');
     TestEnv::restoreConfig();
     TestEnv::restoreEnv();
     // Test 5
     $query = "\n            INSERT INTO\n                " . $oDbh->quoteIdentifier($log_maintenance_priority, true) . "\n                (\n                    start_run,\n                    end_run,\n                    operation_interval,\n                    duration,\n                    run_type,\n                    updated_to\n                )\n            VALUES\n                (\n                    '2006-10-06 12:07:01',\n                    '2006-10-06 12:10:01',\n                    60,\n                    180,\n                    1,\n                    '2006-10-06 11:59:59'\n                )";
     $rows = $oDbh->exec($query);
     $aResult = $oDalMaintenanceCommon->getProcessLastRunInfo($aConf['table']['log_maintenance_priority'], array('operation_interval', 'run_type'), null, 'start_run', array('tableName' => $aConf['table']['data_raw_ad_impression'], 'type' => 'hour'));
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 3);
     $this->assertEqual($aResult['updated_to'], '2006-10-06 11:59:59');
     $this->assertEqual($aResult['operation_interval'], 60);
     $this->assertEqual($aResult['run_type'], 1);
     $query = "\n            INSERT INTO\n                " . $oDbh->quoteIdentifier($log_maintenance_priority, true) . "\n                (\n                    start_run,\n                    end_run,\n                    operation_interval,\n                    duration,\n                    run_type,\n                    updated_to\n                )\n            VALUES\n                (\n                    '2006-10-06 11:07:01',\n                    '2006-10-06 11:10:01',\n                    60,\n                    180,\n                    0,\n                    '2006-10-06 20:59:59'\n                )";
     $rows = $oDbh->exec($query);
     $aResult = $oDalMaintenanceCommon->getProcessLastRunInfo($aConf['table']['log_maintenance_priority'], array('operation_interval', 'run_type'), null, 'start_run', array('tableName' => $aConf['table']['data_raw_ad_impression'], 'type' => 'hour'));
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 3);
     $this->assertEqual($aResult['updated_to'], '2006-10-06 11:59:59');
     $this->assertEqual($aResult['operation_interval'], 60);
     $this->assertEqual($aResult['run_type'], 1);
     $aResult = $oDalMaintenanceCommon->getProcessLastRunInfo($aConf['table']['log_maintenance_priority'], array('operation_interval', 'run_type'), null, 'updated_to', array('tableName' => $aConf['table']['data_raw_ad_impression'], 'type' => 'hour'));
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 3);
     $this->assertEqual($aResult['updated_to'], '2006-10-06 20:59:59');
     $this->assertEqual($aResult['operation_interval'], 60);
     $this->assertEqual($aResult['run_type'], 0);
     $aResult = $oDalMaintenanceCommon->getProcessLastRunInfo($aConf['table']['log_maintenance_priority'], array('operation_interval', 'run_type'), 'WHERE run_type = 0', 'start_run', array('tableName' => $aConf['table']['data_raw_ad_impression'], 'type' => 'hour'));
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 3);
     $this->assertEqual($aResult['updated_to'], '2006-10-06 20:59:59');
     $this->assertEqual($aResult['operation_interval'], 60);
     $this->assertEqual($aResult['run_type'], 0);
     TestEnv::restoreEnv();
 }
 function test_getPackageDiagnostics()
 {
     $oPkgMgr = new OX_PluginManager();
     $file = MAX_PATH . $this->testpathData . 'zipDiagnosticTest/testPluginPackage.zip';
     unset($GLOBALS['_MAX']['CONF']['plugins']['testPluginPackage']);
     unset($GLOBALS['_MAX']['CONF']['pluginGroupComponents']['testPlugin001']);
     //install
     $this->assertTrue($oPkgMgr->installPackage(array('tmp_name' => $file, 'name' => 'testPluginPackage.zip')));
     if (count($oPkgMgr->aErrors)) {
         foreach ($oPkgMgr->aErrors as $error) {
             $this->fail($error);
         }
     }
     $aResultGood = $oPkgMgr->getPackageDiagnostics('testPluginPackage');
     $this->assertFalse($aResultGood['plugin']['error']);
     unlink(MAX_PATH . $oPkgMgr->pathPluginsAdmin . 'testPlugin001/' . 'testPlugin-common.php');
     $oPkgMgr->_unregisterSettings('testPlugin001', false);
     unset($GLOBALS['_MAX']['CONF']['testPlugin001']);
     unset($GLOBALS['_MAX']['CONF']['testPlugin001']['setting1']);
     $oPkgMgr->_unregisterPluginVersion('testPlugin001');
     $oPkgMgr->_unregisterSchemaVersion('testPlugin001');
     $oPkgMgr->_unregisterPreferences('testPlugin001', $aResultGood['groups'][0]['install']['config']['preferences']);
     $oPkgMgr->_dropTables('testPlugin', $aResultGood['groups'][0]['install']['database']['mdb2schema']);
     $aResultBad = $oPkgMgr->getPackageDiagnostics('testPluginPackage');
     $this->assertTrue($aResultBad['groups'][1]['error']);
     //uninstall
     $this->assertTrue($oPkgMgr->uninstallPackage('testPluginPackage'));
     TestEnv::restoreConfig();
 }