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() { // Uninstall the openXDeliveryLog plugin TestEnv::uninstallPluginPackage('openXDeliveryLimitations', false); // Clean up the testing environment 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(); }
function testGetDeliveredEcpmCampainImpressionsByAgency() { $this->aIds2 = TestEnv::loadData('data_intermediate_ad_002'); $impressions = 123; $agencyId = $this->aIds2['agency'][0]; $campaignId = $this->aIds2['campaigns'][0]; $day = '2007-04-04'; $oDate = new Date($day . '00:00:00'); $aDelivered = $this->dalData_intermediate_ad->getDeliveredEcpmCampainImpressionsByAgency($agencyId, $oDate); $howMany = 2; $this->assertEqual($aDelivered[$campaignId], $howMany * $impressions); }
/** * 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(); }
/** * Method to test the getAgencyCampaignsDeliveriesToDate method. * * Requirements: * Test 1: Test correct results are returned with no data. * Test 2: Test correct results are returned with single data entry. * Test 3: Test correct results are returned with multiple data entries. */ function testGetAgencyEcpmRemnantCampaignsDeliveriesToDate() { TestEnv::restoreEnv(); $priority = DataObjects_Campaigns::PRIORITY_ECPM; $oMaxDalMaintenance = new OA_Dal_Maintenance_Priority(); list($agencyId1, $agencyId2) = $this->_commonTest($oMaxDalMaintenance, $priority); // Check that there are no results for agency 1 (when checking ecpm deliveries) $result = $oMaxDalMaintenance->getAgencyEcpmRemnantCampaignsDeliveriesToDate($agencyId1); $this->assertTrue(is_array($result)); $this->assertEqual(count($result), 0); // Check that results for agency 2 are the same (when checking ecpm deliveries) $result = $oMaxDalMaintenance->getAgencyEcpmRemnantCampaignsDeliveriesToDate($agencyId2); $this->_testResult($result); DataGenerator::cleanUp(); }
/** * Method to test the getZonesAllocationsByAgencyAndCampaignPriority method. * * Requirements: * Test 1: Test with no data, and ensure no data returned. * Test 2: Test with sample data, and ensure the correct data is returned. */ function testGetZonesAllocationsByAgencyAndCampaignPriority() { $oMaxDalMaintenance = new OA_Dal_Maintenance_Priority(); list($agencyId1, $agencyId2) = $this->_generateData($priority = 5); $priority--; // always bigger priority is summed up // Test 1 $result = $oMaxDalMaintenance->getZonesAllocationsByAgencyAndCampaignPriority($agencyId2, $priority); $this->assertEqual(0, count($result)); // Test 2 $aResult = $oMaxDalMaintenance->getZonesAllocationsByAgencyAndCampaignPriority($agencyId1, $priority); $this->assertEqual(1, count($aResult)); $this->assertEqual(7, $aResult[$this->idZone1]); TestEnv::restoreEnv(); }
/** * Method to test the setMaintenancePriorityLastRunInfo method. * * Requirements: * Test 1: Test with no data in the database, ensure data is correctly stored. * Test 2: Test with previous test data in the database, ensure data is correctly stored. */ function testSetMaintenancePriorityLastRunInfo() { // Test relies on transaction numbers, so ensure fresh database used TestEnv::restoreEnv('dropTmpTables'); $conf = $GLOBALS['_MAX']['CONF']; $oDbh =& OA_DB::singleton(); $oMaxDalMaintenance = new OA_Dal_Maintenance_Priority(); // Test 1 $oStartDate = new Date('2005-06-21 15:00:01'); $oEndDate = new Date('2005-06-21 15:01:01'); $oUpdatedTo = new Date('2005-06-21 15:59:59'); $result = $oMaxDalMaintenance->setMaintenancePriorityLastRunInfo($oStartDate, $oEndDate, $oUpdatedTo, DAL_PRIORITY_UPDATE_ECPM); $this->assertEqual($result, 1); $query = "\n SELECT\n start_run,\n end_run,\n operation_interval,\n duration,\n run_type,\n updated_to\n FROM\n " . $oDbh->quoteIdentifier($conf['table']['prefix'] . $conf['table']['log_maintenance_priority'], true) . "\n WHERE\n log_maintenance_priority_id = 1"; $rc = $oDbh->query($query); $aRow = $rc->fetchRow(); $this->assertEqual($aRow['start_run'], '2005-06-21 15:00:01'); $this->assertEqual($aRow['end_run'], '2005-06-21 15:01:01'); $this->assertEqual($aRow['operation_interval'], $conf['maintenance']['operationInterval']); $this->assertEqual($aRow['duration'], 60); $this->assertEqual($aRow['run_type'], DAL_PRIORITY_UPDATE_ECPM); $this->assertEqual($aRow['updated_to'], '2005-06-21 15:59:59'); // Test 2 $oStartDate = new Date('2005-06-21 16:00:01'); $oEndDate = new Date('2005-06-21 16:01:06'); $oUpdatedTo = new Date('2005-06-21 16:59:59'); $result = $oMaxDalMaintenance->setMaintenancePriorityLastRunInfo($oStartDate, $oEndDate, $oUpdatedTo, DAL_PRIORITY_UPDATE_PRIORITY_COMPENSATION); $this->assertEqual($result, 1); $query = "\n SELECT\n start_run,\n end_run,\n operation_interval,\n duration,\n run_type,\n updated_to\n FROM\n " . $oDbh->quoteIdentifier($conf['table']['prefix'] . $conf['table']['log_maintenance_priority'], true) . "\n WHERE\n log_maintenance_priority_id = 1"; $rc = $oDbh->query($query); $aRow = $rc->fetchRow(); $this->assertEqual($aRow['start_run'], '2005-06-21 15:00:01'); $this->assertEqual($aRow['end_run'], '2005-06-21 15:01:01'); $this->assertEqual($aRow['operation_interval'], $conf['maintenance']['operationInterval']); $this->assertEqual($aRow['duration'], 60); $this->assertEqual($aRow['run_type'], DAL_PRIORITY_UPDATE_ECPM); $this->assertEqual($aRow['updated_to'], '2005-06-21 15:59:59'); $query = "\n SELECT\n start_run,\n end_run,\n operation_interval,\n duration,\n run_type,\n updated_to\n FROM\n " . $oDbh->quoteIdentifier($conf['table']['prefix'] . $conf['table']['log_maintenance_priority'], true) . "\n WHERE\n log_maintenance_priority_id = 2"; $rc = $oDbh->query($query); $aRow = $rc->fetchRow(); $this->assertEqual($aRow['start_run'], '2005-06-21 16:00:01'); $this->assertEqual($aRow['end_run'], '2005-06-21 16:01:06'); $this->assertEqual($aRow['operation_interval'], $conf['maintenance']['operationInterval']); $this->assertEqual($aRow['duration'], 65); $this->assertEqual($aRow['run_type'], DAL_PRIORITY_UPDATE_PRIORITY_COMPENSATION); $this->assertEqual($aRow['updated_to'], '2005-06-21 16:59:59'); DataGenerator::cleanUp(array('log_maintenance_priority')); }
/** * 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(); }
/** * A method to test the getCampaigns method. */ function testGetCampaigns() { /** * @TODO Locate where clean up doesn't happen before this test, and fix! */ TestEnv::restoreEnv(); $da = new OA_Dal_Maintenance_Priority(); $this->_generateStatsOne(); // Test 1 getCampaigns method. $ret = $da->getCampaigns(); $this->assertTrue(is_array($ret)); $this->assertTrue(count($ret) == 5); $campaign = $ret[0]; $this->assertIsA($campaign, 'OX_Maintenance_Priority_Campaign'); $this->assertEqual($campaign->id, 1); $this->assertEqual($campaign->impressionTargetTotal, 0); $this->assertEqual($campaign->clickTargetTotal, 400); $this->assertEqual($campaign->conversionTargetTotal, 0); $this->assertEqual($campaign->impressionTargetDaily, 0); $this->assertEqual($campaign->clickTargetDaily, 0); $this->assertEqual($campaign->conversionTargetDaily, 0); $this->assertEqual($campaign->priority, 3); // Test 2 getCampaignData method. $campaign = $da->getCampaignData(1); $this->assertTrue(is_array($campaign)); $this->assertTrue(count($campaign) == 5); $this->assertTrue(array_key_exists('advertiser_id', $campaign)); $this->assertTrue(array_key_exists('placement_id', $campaign)); $this->assertTrue(array_key_exists('name', $campaign)); $this->assertTrue(array_key_exists('status', $campaign)); $this->assertTrue(array_key_exists('num_children', $campaign)); // Test 3 getCampaignStats method. $ret = $da->getCampaignStats(1); $this->assertTrue(is_array($ret)); $this->assertTrue(count($ret) == 9); $this->assertTrue(array_key_exists('advertiser_id', $ret)); $this->assertTrue(array_key_exists('placement_id', $ret)); $this->assertTrue(array_key_exists('name', $ret)); $this->assertTrue(array_key_exists('status', $ret)); $this->assertTrue(array_key_exists('num_children', $ret)); $this->assertTrue(array_key_exists('sum_requests', $ret)); $this->assertTrue(array_key_exists('sum_views', $ret)); $this->assertTrue(array_key_exists('sum_clicks', $ret)); $this->assertTrue(array_key_exists('sum_conversions', $ret)); DataGenerator::cleanUp(); }
/** * Test convertEncoding() * */ function test_convertEncoding() { // Force client charset to latin1 so that the behaviour is similar to a real latin1 database // even if the database is encoded in utf8. At first we tried to drop the database an recreate // a latin1 encoded database, but PgSQL doesn't allow LATIN1 databases if the locale is set to // UTF-8. $GLOBALS['_MAX']['CONF']['databaseCharset'] = array('checkComplete' => true, 'clientCharset' => 'latin1'); // However MySQL versions < 4.1.2 didn't support charsets, so we don't need to do that // and assume that a database can store any 8bit data (which is in fact true) if ($this->oDbh->dbsyntax == 'mysql') { $aVersion = $this->oDbh->getServerVersion(); if (version_compare($aVersion['native'], '4.1.2', '<')) { $GLOBALS['_MAX']['CONF']['databaseCharset']['clientCharset'] = ''; } } // Set client charset OA_DB::setCharset($this->oDbh); // These tables are required for the encoding migration $aTables = array('acls', 'acls_channel', 'ad_zone_assoc', 'affiliates', 'affiliates_extra', 'agency', 'application_variable', 'banners', 'campaigns', 'channel', 'clients', 'preference', 'session', 'tracker_append', 'trackers', 'userlog', 'variables', 'zones'); // These tables are referenced by schema changes between 515 and 546, therefore need to be created $aOtherTables = array('preference_publisher', 'accounts', 'users', 'account_user_assoc'); //array('preference', 'data_raw_tracker_click', 'data_summary_zone_country_daily', 'data_summary_zone_country_forecast', 'data_summary_zone_country_monthly', 'data_summary_zone_domain_page_daily', 'data_summary_zone_domain_page_forecast', 'data_summary_zone_domain_page_monthly', 'data_summary_zone_site_keyword_daily', 'data_summary_zone_site_keyword_forecast', 'data_summary_zone_site_keyword_monthly', 'data_summary_zone_source_daily', 'data_summary_zone_source_forecast', 'data_summary_zone_source_monthly', 'preference_advertiser', 'preference_publisher'); $this->initDatabase(543, array_merge($aTables, $aOtherTables)); $this->aIds = TestEnv::loadData('encoding_schema_543', 'mdb2schema'); // MD5s verified manually setting the terminal encoding to the right encoding. $expected = array('latin1_utf8' => array(0 => array('campaignid' => $this->aIds['campaigns'][1], 'md5' => '1698982c38317c8c42ae4772bbee8f44'), 1 => array('campaignid' => $this->aIds['campaigns'][2], 'md5' => '317f56003783a2a9284306eb57fe8146'), 2 => array('campaignid' => $this->aIds['campaigns'][3], 'md5' => 'fa419947d425b10bd2485e090f4cae60'), 3 => array('campaignid' => $this->aIds['campaigns'][4], 'md5' => '32395feef462f13071c2a2fe5e44c7c0'), 4 => array('campaignid' => $this->aIds['campaigns'][5], 'md5' => '9932d540cb5b63f264b3f7391577fe93'), 5 => array('campaignid' => $this->aIds['campaigns'][6], 'md5' => 'c6ae927806e0a61f9cd269659a225435')), 'utf8_utf8' => array(0 => array('campaignid' => $this->aIds['campaigns'][1], 'md5' => '1698982c38317c8c42ae4772bbee8f44'), 1 => array('campaignid' => $this->aIds['campaigns'][2], 'md5' => '317f56003783a2a9284306eb57fe8146'), 2 => array('campaignid' => $this->aIds['campaigns'][3], 'md5' => '8c8755d8f519c0245717475757d043f7'), 3 => array('campaignid' => $this->aIds['campaigns'][4], 'md5' => '7269db488f9672cca26d93105a9a2559'), 4 => array('campaignid' => $this->aIds['campaigns'][5], 'md5' => '19397ed80befa5539761afed23c4c27a'), 5 => array('campaignid' => $this->aIds['campaigns'][6], 'md5' => 'a7d508c6c8a494c80e680033cecbc76d'))); $tblCampaigns = $this->oDbh->quoteIdentifier($this->getPrefix() . 'campaigns', true); // Check that the campaign names are correctly created: $query = "SELECT campaignid, campaignname FROM {$tblCampaigns}"; $result = $this->oDbh->queryAll($query); foreach (array_keys($result) as $k) { $result[$k]['md5'] = md5($result[$k]['campaignname']); unset($result[$k]['campaignname']); } $this->assertIdentical($result, $expected['latin1_utf8']); // Upgrade the dataset and ensure that the upgraded campaign names were upgraded correctly: $this->upgradeToVersion(544); // Fields requiring encoding changes should now be correct $query = "SELECT campaignid, campaignname FROM {$tblCampaigns}"; $result = $this->oDbh->queryAll($query); foreach (array_keys($result) as $k) { $result[$k]['md5'] = md5($result[$k]['campaignname']); unset($result[$k]['campaignname']); } $this->assertIdentical($result, $expected['utf8_utf8']); }
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(); }
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 run() method. */ function testRun() { // Create a reference to the OpenX configuration so that settings // can be changed while the tests are running $aConf =& $GLOBALS['_MAX']['CONF']; // Create the database connection and service locator objects $oDbh =& OA_DB::singleton(); $oServiceLocator =& OA_ServiceLocator::instance(); // Create the "log_maintenance_statistics" table required for the tests $oTables =& OA_DB_Table_Core::singleton(); $oTables->createTable('log_maintenance_statistics'); // Create the "controller" OX_Maintenance_Statistics class, and // register in the service locator $oMaintenanceStatistics = new OX_Maintenance_Statistics(); $oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics); // Create a partially mocked instance of the // OX_Maintenance_Statistics_Task_SetUpdateRequirements class Mock::generatePartial('OX_Maintenance_Statistics_Task_SetUpdateRequirements', 'PartialOX_Maintenance_Statistics_Task_SetUpdateRequirements', array('_getMaintenanceStatisticsLastRunInfo', '_getEarliestLoggedDeliveryData')); // Prepare an array of times that the MSE should be run at, to // test the effects of different times and data sets $aMSERunTimes = array(0 => new Date('2008-08-12 13:00:01'), 1 => new Date('2008-08-12 13:30:01'), 2 => new Date('2008-08-12 14:00:01')); // Create an array of valid operation interval values for runnung tests $aOperationIntervals = array(30, 60); /*-------------------------------------------------------------*/ /* NO DATA TESTS */ /* */ /* Run tests where with operation intervals of 30 and 60 mins, */ /* where there is no data in the database, and test that the */ /* result is that the MSE will not be run. */ /*-------------------------------------------------------------*/ foreach ($aMSERunTimes as $key => $oRunDate) { // Register the "current" date/time that the MSE is running at $oServiceLocator->register('now', $oRunDate); foreach ($aOperationIntervals as $operationInterval) { // Set the correct operation interval $aConf['maintenance']['operationInterval'] = $operationInterval; // Prepare the partially mocked instance of the // OX_Maintenance_Statistics_Task_SetUpdateRequirements class with // the expectations and return values required for the test run $oSetUpdateRequirements = new PartialOX_Maintenance_Statistics_Task_SetUpdateRequirements(); $oSetUpdateRequirements->expectCallCount('_getMaintenanceStatisticsLastRunInfo', 2); $oSetUpdateRequirements->expectCallCount('_getEarliestLoggedDeliveryData', 2); $oSetUpdateRequirements->expectAt(0, '_getMaintenanceStatisticsLastRunInfo', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI, $oRunDate)); $oSetUpdateRequirements->setReturnValueAt(0, '_getMaintenanceStatisticsLastRunInfo', null); $oSetUpdateRequirements->expectAt(0, '_getEarliestLoggedDeliveryData', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI)); $oSetUpdateRequirements->setReturnValueAt(0, '_getEarliestLoggedDeliveryData', null); $oSetUpdateRequirements->expectAt(1, '_getMaintenanceStatisticsLastRunInfo', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_HOUR, $oRunDate)); $oSetUpdateRequirements->setReturnValueAt(1, '_getMaintenanceStatisticsLastRunInfo', null); $oSetUpdateRequirements->expectAt(1, '_getEarliestLoggedDeliveryData', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_HOUR)); $oSetUpdateRequirements->setReturnValueAt(1, '_getEarliestLoggedDeliveryData', null); // Create the OX_Maintenance_Statistics_Task_SetUpdateRequirements // object and run the task $oSetUpdateRequirements->__construct($this); $oSetUpdateRequirements->run(); // Test the results of the task run $this->assertFalse($oSetUpdateRequirements->oController->updateIntermediate); $this->assertFalse($oSetUpdateRequirements->oController->updateFinal); } } /*-------------------------------------------------------------*/ /* ONLY LOGGED DELIVERY DATA TESTS */ /* */ /* Run tests where with operation intervals of 30 and 60 mins, */ /* where there is only delivery data in the database (i.e. no */ /* previous MSE run) and test that the result is that the MSE */ /* will be run from the appropriate date/time. */ /*-------------------------------------------------------------*/ // Set the value that will be returned for the last MSE run // update value, based on the earliest logged data, in terms of // the operation interval $oEarliestLoggedDataDateOI = new Date('2008-08-12 13:29:59'); // Set the value that will be returned for the last MSE run // update value, based on the earliest logged data, in terms of // the hour $oEarliestLoggedDataDateHour = new Date('2008-08-12 12:59:59'); foreach ($aMSERunTimes as $key => $oRunDate) { // Register the "current" date/time that the MSE is running at $oServiceLocator->register('now', $oRunDate); foreach ($aOperationIntervals as $operationInterval) { // Set the correct operation interval $aConf['maintenance']['operationInterval'] = $operationInterval; // Prepare the partially mocked instance of the // OX_Maintenance_Statistics_Task_SetUpdateRequirements class with // the expectations and return values required for the test run $oSetUpdateRequirements = new PartialOX_Maintenance_Statistics_Task_SetUpdateRequirements(); $oSetUpdateRequirements->expectCallCount('_getMaintenanceStatisticsLastRunInfo', 2); $oSetUpdateRequirements->expectCallCount('_getEarliestLoggedDeliveryData', 2); $oSetUpdateRequirements->expectAt(0, '_getMaintenanceStatisticsLastRunInfo', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI, $oRunDate)); $oSetUpdateRequirements->setReturnValueAt(0, '_getMaintenanceStatisticsLastRunInfo', null); $oSetUpdateRequirements->expectAt(0, '_getEarliestLoggedDeliveryData', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI)); $oSetUpdateRequirements->setReturnValueAt(0, '_getEarliestLoggedDeliveryData', $oEarliestLoggedDataDateOI); $oSetUpdateRequirements->expectAt(1, '_getMaintenanceStatisticsLastRunInfo', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_HOUR, $oRunDate)); $oSetUpdateRequirements->setReturnValueAt(1, '_getMaintenanceStatisticsLastRunInfo', null); $oSetUpdateRequirements->expectAt(1, '_getEarliestLoggedDeliveryData', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_HOUR)); $oSetUpdateRequirements->setReturnValueAt(1, '_getEarliestLoggedDeliveryData', $oEarliestLoggedDataDateHour); // Create the OX_Maintenance_Statistics_Task_SetUpdateRequirements // object and run the task $oSetUpdateRequirements->__construct($this); $oSetUpdateRequirements->run(); // Test the results of the task run if ($key == 0) { // There is no data logged before "now"; therefore, no udpates will be run $this->assertFalse($oSetUpdateRequirements->oController->updateIntermediate); $this->assertFalse($oSetUpdateRequirements->oController->updateFinal); } elseif ($key == 1) { // There is logged data before "now", but a complete operation interval // will only have been passed at this stage IF the operation interval is // 30 minutes; in that case, the MSE will update the intermedaite tables; // otherwise, no updates will be run if ($operationInterval == 30) { $this->assertTrue($oSetUpdateRequirements->oController->updateIntermediate); $this->assertFalse($oSetUpdateRequirements->oController->updateFinal); } else { $this->assertFalse($oSetUpdateRequirements->oController->updateIntermediate); $this->assertFalse($oSetUpdateRequirements->oController->updateFinal); } } elseif ($key == 2) { // There is logged data before "now", and a complete operation interval // will have been passed at this stage, and the update boundary is on the // hour, so the MSE will update the intermedaite and final tables $this->assertTrue($oSetUpdateRequirements->oController->updateIntermediate); $this->assertTrue($oSetUpdateRequirements->oController->updateFinal); } } } /*-------------------------------------------------------------*/ /* REAL PAST MSE OI RUN ONLY TESTS */ /* */ /* Run tests where with operation intervals of 30 and 60 mins, */ /* where there the MSE has run previously on the basis of the */ /* operation interval, but not for the hour, and test that the */ /* result is that the MSE will be run from the appropriate */ /* date/time. */ /*-------------------------------------------------------------*/ // Set the value that will be returned for the last MSE run // update value, based on the the operation interval $oLastMSERunOI = new Date('2008-08-12 13:29:59'); // Set the value that will be returned for the last MSE run // update value, based on the earliest logged data, in terms of // the hour $oEarliestLoggedDataDateHour = new Date('2008-08-12 12:59:59'); foreach ($aMSERunTimes as $key => $oRunDate) { // Register the "current" date/time that the MSE is running at $oServiceLocator->register('now', $oRunDate); foreach ($aOperationIntervals as $operationInterval) { // Set the correct operation interval $aConf['maintenance']['operationInterval'] = $operationInterval; // Prepare the partially mocked instance of the // OX_Maintenance_Statistics_Task_SetUpdateRequirements class with // the expectations and return values required for the test run $oSetUpdateRequirements = new PartialOX_Maintenance_Statistics_Task_SetUpdateRequirements(); $oSetUpdateRequirements->expectCallCount('_getMaintenanceStatisticsLastRunInfo', 2); $oSetUpdateRequirements->expectCallCount('_getEarliestLoggedDeliveryData', 1); $oSetUpdateRequirements->expectAt(0, '_getMaintenanceStatisticsLastRunInfo', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI, $oRunDate)); $oSetUpdateRequirements->setReturnValueAt(0, '_getMaintenanceStatisticsLastRunInfo', $oLastMSERunOI); $oSetUpdateRequirements->expectAt(1, '_getMaintenanceStatisticsLastRunInfo', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_HOUR, $oRunDate)); $oSetUpdateRequirements->setReturnValueAt(1, '_getMaintenanceStatisticsLastRunInfo', null); $oSetUpdateRequirements->expectAt(0, '_getEarliestLoggedDeliveryData', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_HOUR)); $oSetUpdateRequirements->setReturnValueAt(0, '_getEarliestLoggedDeliveryData', $oEarliestLoggedDataDateHour); // Create the OX_Maintenance_Statistics_Task_SetUpdateRequirements // object and run the task $oSetUpdateRequirements->__construct($this); $oSetUpdateRequirements->run(); // Test the results of the task run if ($key == 0) { // There is no data logged before "now"; therefore, no udpates will be run $this->assertFalse($oSetUpdateRequirements->oController->updateIntermediate); $this->assertFalse($oSetUpdateRequirements->oController->updateFinal); } elseif ($key == 1) { // There is logged data before "now", but a complete operation interval // will only have been passed at this stage IF the operation interval is // 30 minutes; in that case, the MSE will update the intermedaite tables; // otherwise, no updates will be run if ($operationInterval == 30) { $this->assertTrue($oSetUpdateRequirements->oController->updateIntermediate); $this->assertFalse($oSetUpdateRequirements->oController->updateFinal); } else { $this->assertFalse($oSetUpdateRequirements->oController->updateIntermediate); $this->assertFalse($oSetUpdateRequirements->oController->updateFinal); } } elseif ($key == 2) { // There is logged data before "now", and a complete operation interval // will have been passed at this stage, and the update boundary is on the // hour, so the MSE will update the intermedaite and final tables $this->assertTrue($oSetUpdateRequirements->oController->updateIntermediate); $this->assertTrue($oSetUpdateRequirements->oController->updateFinal); } } } /*-------------------------------------------------------------*/ /* REAL PAST MSE RUN TESTS */ /* */ /* Run tests where with operation intervals of 30 and 60 mins, */ /* where there the MSE has run previously, and test that the */ /* result is that the MSE will be run from the appropriate */ /* date/time. */ /*-------------------------------------------------------------*/ // Set the value that will be returned for the last MSE run // update value, based on the the operation interval $oLastMSERunOI = new Date('2008-08-12 13:29:59'); // Set the value that will be returned for the last MSE run // update value, based on the the hour $oLastMSERunHour = new Date('2008-08-12 12:59:59'); foreach ($aMSERunTimes as $key => $oRunDate) { // Register the "current" date/time that the MSE is running at $oServiceLocator->register('now', $oRunDate); foreach ($aOperationIntervals as $operationInterval) { // Set the correct operation interval $aConf['maintenance']['operationInterval'] = $operationInterval; // Prepare the partially mocked instance of the // OX_Maintenance_Statistics_Task_SetUpdateRequirements class with // the expectations and return values required for the test run $oSetUpdateRequirements = new PartialOX_Maintenance_Statistics_Task_SetUpdateRequirements(); $oSetUpdateRequirements->expectCallCount('_getMaintenanceStatisticsLastRunInfo', 2); $oSetUpdateRequirements->expectCallCount('_getEarliestLoggedDeliveryData', 0); $oSetUpdateRequirements->expectAt(0, '_getMaintenanceStatisticsLastRunInfo', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_OI, $oRunDate)); $oSetUpdateRequirements->setReturnValueAt(0, '_getMaintenanceStatisticsLastRunInfo', $oLastMSERunOI); $oSetUpdateRequirements->expectAt(1, '_getMaintenanceStatisticsLastRunInfo', array(OX_DAL_MAINTENANCE_STATISTICS_UPDATE_HOUR, $oRunDate)); $oSetUpdateRequirements->setReturnValueAt(1, '_getMaintenanceStatisticsLastRunInfo', $oLastMSERunHour); // Create the OX_Maintenance_Statistics_Task_SetUpdateRequirements // object and run the task $oSetUpdateRequirements->__construct($this); $oSetUpdateRequirements->run(); // Test the results of the task run if ($key == 0) { // There is no data logged before "now"; therefore, no udpates will be run $this->assertFalse($oSetUpdateRequirements->oController->updateIntermediate); $this->assertFalse($oSetUpdateRequirements->oController->updateFinal); } elseif ($key == 1) { // There is logged data before "now", but a complete operation interval // will only have been passed at this stage IF the operation interval is // 30 minutes; in that case, the MSE will update the intermedaite tables; // otherwise, no updates will be run if ($operationInterval == 30) { $this->assertTrue($oSetUpdateRequirements->oController->updateIntermediate); $this->assertFalse($oSetUpdateRequirements->oController->updateFinal); } else { $this->assertFalse($oSetUpdateRequirements->oController->updateIntermediate); $this->assertFalse($oSetUpdateRequirements->oController->updateFinal); } } elseif ($key == 2) { // There is logged data before "now", and a complete operation interval // will have been passed at this stage, and the update boundary is on the // hour, so the MSE will update the intermedaite and final tables $this->assertTrue($oSetUpdateRequirements->oController->updateIntermediate); $this->assertTrue($oSetUpdateRequirements->oController->updateFinal); } } } // Reset the testing environment TestEnv::restoreEnv(); }
function tearDown() { // Uninstall the openXDeliveryLog plugin TestEnv::uninstallPluginPackage('openXDeliveryLimitations', false); }
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(); }
function _generateStats() { $this->aIds = TestEnv::loadData('data_summary_ad_hourly_001'); $this->agencyId = $this->aIds['agency'][1]; $this->clientId = $this->aIds['clients'][1]; $this->campaignId = $this->aIds['campaigns'][1]; $this->bannerId = $this->aIds['banners'][1]; $this->bannerId2 = $this->aIds['banners'][2]; $this->affiliateId = $this->aIds['affiliates'][1]; $this->zoneId = $this->aIds['zones'][1]; $this->zoneId2 = $this->aIds['zones'][2]; }
/** * 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(); }
/** * Tests creating/dropping all of the MPE temporary tables. * * Requirements: * Test 1: Test that all MPE temporary tables can be created and dropped. */ function testAllMaintenanceStatisticsTables() { $tmpTables = array('tmp_ad_impression', 'tmp_ad_click', 'tmp_tracker_impression_ad_impression_connection', 'tmp_tracker_impression_ad_click_connection', 'tmp_ad_connection'); // Test 1 $conf =& $GLOBALS['_MAX']['CONF']; $conf['table']['prefix'] = ''; $oDbh =& OA_DB::singleton(); foreach ($tmpTables as $tableName) { $query = "SELECT * FROM {$tableName}"; OA::disableErrorHandling(); $result = $oDbh->query($query); OA::enableErrorHandling(); $this->assertEqual(strtolower(get_class($result)), 'mdb2_error'); } $oTable =& OA_DB_Table_Statistics::singleton(); foreach ($tmpTables as $tableName) { $oTable->createTable($tableName); } $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); foreach ($tmpTables as $tableName) { // Test that the table has been created $query = "SELECT * FROM {$tableName}"; $result = $oDbh->query($query); $this->assertTrue($result); // Test that the table can be dropped // Use a different query to overcome MDB2 query buffering $query = "SELECT foo FROM {$tableName}"; OA::disableErrorHandling(); $result = $oDbh->query($query); OA::enableErrorHandling(); $this->assertEqual(strtolower(get_class($result)), 'mdb2_error'); } // Restore the testing environment TestEnv::restoreEnv(); }
function tearDown() { TestEnv::uninstallPluginPackage('openXBannerTypes'); }
/** * Method to test the testSetMaintenanceStatisticsRunReport method. * * Requirements: * Test 1: Test two writes to reports. */ function testSetMaintenanceStatisticsRunReport() { $aConf = $GLOBALS['_MAX']['CONF']; $oDbh =& OA_DB::singleton(); // Create a new OX_Maintenance_Statistics_Task_LogCompletion object $oLogCompletion = new OX_Maintenance_Statistics_Task_LogCompletion(); // Test 1 $report = 'Maintenance run has finished :: Maintenance will run again at XYZ.'; $oLogCompletion->_setMaintenanceStatisticsRunReport($report); $query = "\n SELECT\n timestamp,\n usertype,\n userid,\n action,\n object,\n details\n FROM\n " . $oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['userlog'], true) . "\n WHERE\n userlogid = 1"; $rc = $oDbh->query($query); $aRow = $rc->fetchRow(); $this->assertEqual($aRow['usertype'], phpAds_userMaintenance); $this->assertEqual($aRow['userid'], '0'); $this->assertEqual($aRow['action'], phpAds_actionBatchStatistics); $this->assertEqual($aRow['object'], '0'); $this->assertEqual($aRow['details'], $report); $report = '2nd Maintenance run has finished :: Maintenance will run again at XYZ.'; $oLogCompletion->_setMaintenanceStatisticsRunReport($report); $query = "\n SELECT\n timestamp,\n usertype,\n userid,\n action,\n object,\n details\n FROM\n " . $oDbh->quoteIdentifier($aConf['table']['prefix'] . $aConf['table']['userlog'], true) . "\n WHERE\n userlogid = 2"; $rc = $oDbh->query($query); $aRow = $rc->fetchRow(); $this->assertEqual($aRow['usertype'], phpAds_userMaintenance); $this->assertEqual($aRow['userid'], '0'); $this->assertEqual($aRow['action'], phpAds_actionBatchStatistics); $this->assertEqual($aRow['object'], '0'); $this->assertEqual($aRow['details'], $report); 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(); }
function tearDown() { TestEnv::uninstallPluginPackage('openXDeliveryCacheStore'); }
/** * A method to test the getAllDeliveryLimitationsByTypeId() method. * * Requirements: * Test 1: Test for ad limitations with no data, and ensure null returned * Test 2: Test for channel limitations with no data, and ensure null returned * Test 3: Test with an ad limitation for an ad, but with a different ad id, and * ensure null returned * Test 4: Test with an ad limitation, but with a channel id, and ensure null * returned * Test 5: Test with an ad limitation, but with a bad $type, and ensure null * returned * Test 6: Test with an ad limitation, and ensure values returned * Test 7: Test with a channel limitation, but with an ad id, and ensure null * returned * Test 8: Test with a channel limitation, but with a different channel id, and * ensure null returned * Test 9: Test with a channel limitation, but with a bad $type, and ensure null * returned * Test 10: Test with a channel limitation, and ensure values returned */ function testGetAllDeliveryLimitationsByTypeId() { $aConf = $GLOBALS['_MAX']['CONF']; $oDbh =& OA_DB::singleton(); $oDalMaintenanceCommon = new OA_Dal_Maintenance_Common(); // Test 1 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(1, 'ad'); $this->assertNull($aResult); // Test 2 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(1, 'channel'); $this->assertNull($aResult); $table = $aConf['table']['prefix'] . $aConf['table']['acls']; $query = "\n INSERT INTO\n " . $oDbh->quoteIdentifier($table, true) . "\n (\n bannerid,\n logical,\n type,\n comparison,\n data,\n executionorder\n )\n VALUES\n (?, ?, ?, ?, ?, ?)"; $aTypes = array('integer', 'text', 'text', 'text', 'text', 'integer'); $st = $oDbh->prepare($query, $aTypes, MDB2_PREPARE_MANIP); $aData = array(3, 'and', 'Time:Date', '!=', '2005-05-25', 0); $rows = $st->execute($aData); $aData = array(3, 'and', 'Geo:Country', '==', 'GB', 1); $rows = $st->execute($aData); // Test 3 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(1, 'ad'); $this->assertNull($aResult); // Test 4 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(1, 'channel'); $this->assertNull($aResult); // Test 5 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(3, 'foo'); $this->assertNull($aResult); // Test 6 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(3, 'ad'); $this->assertTrue(is_array($aResult)); $this->assertEqual(count($aResult), 2); $this->assertEqual(count($aResult[0]), 6); $this->assertEqual($aResult[0]['ad_id'], 3); $this->assertEqual($aResult[0]['logical'], 'and'); $this->assertEqual($aResult[0]['type'], 'Time:Date'); $this->assertEqual($aResult[0]['comparison'], '!='); $this->assertEqual($aResult[0]['data'], '2005-05-25'); $this->assertEqual($aResult[0]['executionorder'], 0); $this->assertEqual(count($aResult[1]), 6); $this->assertEqual($aResult[1]['ad_id'], 3); $this->assertEqual($aResult[1]['logical'], 'and'); $this->assertEqual($aResult[1]['type'], 'Geo:Country'); $this->assertEqual($aResult[1]['comparison'], '=='); $this->assertEqual($aResult[1]['data'], 'GB'); $this->assertEqual($aResult[1]['executionorder'], 1); $aCleanupTables = array($aConf['table']['acls']); foreach ($aCleanupTables as $table) { $query = "DELETE FROM {$aConf['table']['prefix']}{$table}"; $oDbh->exec($query); } DataGenerator::resetSequence($aCleanupTables); TestEnv::restoreEnv(); $table = $aConf['table']['prefix'] . $aConf['table']['acls_channel']; $query = "\n INSERT INTO\n " . $oDbh->quoteIdentifier($table, true) . "\n (\n channelid,\n logical,\n type,\n comparison,\n data,\n executionorder\n )\n VALUES\n (?, ?, ?, ?, ?, ?)"; $aTypes = array('integer', 'text', 'text', 'text', 'text', 'integer'); $st = $oDbh->prepare($query, $aTypes, MDB2_PREPARE_MANIP); $aData = array(3, 'and', 'Time:Date', '!=', '2005-05-25', 0); $rows = $st->execute($aData); $aData = array(3, 'and', 'Geo:Country', '==', 'GB', 1); $rows = $st->execute($aData); // Test 7 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(1, 'ad'); $this->assertNull($aResult); // Test 8 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(1, 'channel'); $this->assertNull($aResult); // Test 9 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(3, 'foo'); $this->assertNull($aResult); // Test 10 $aResult = $oDalMaintenanceCommon->getAllDeliveryLimitationsByTypeId(3, 'channel'); $this->assertTrue(is_array($aResult)); $this->assertEqual(count($aResult), 2); $this->assertEqual(count($aResult[0]), 6); $this->assertEqual($aResult[0]['ad_id'], 3); $this->assertEqual($aResult[0]['logical'], 'and'); $this->assertEqual($aResult[0]['type'], 'Time:Date'); $this->assertEqual($aResult[0]['comparison'], '!='); $this->assertEqual($aResult[0]['data'], '2005-05-25'); $this->assertEqual($aResult[0]['executionorder'], 0); $this->assertEqual(count($aResult[1]), 6); $this->assertEqual($aResult[1]['ad_id'], 3); $this->assertEqual($aResult[1]['logical'], 'and'); $this->assertEqual($aResult[1]['type'], 'Geo:Country'); $this->assertEqual($aResult[1]['comparison'], '=='); $this->assertEqual($aResult[1]['data'], 'GB'); $this->assertEqual($aResult[1]['executionorder'], 1); $aCleanupTables = array($aConf['table']['acls_channel']); foreach ($aCleanupTables as $table) { $query = "DELETE FROM {$aConf['table']['prefix']}{$table}"; $oDbh->exec($query); } DataGenerator::resetSequence($aCleanupTables); }
/** * 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(); }