/**
  * A method to test the saveAllocatedImpressions method.
  */
 function testSaveAllocatedImpressions()
 {
     $oDbh =& OA_DB::singleton();
     $oDal = new OA_Dal_Maintenance_Priority();
     // Create the required temporary table for the tests
     $oTable =& OA_DB_Table_Priority::singleton();
     $oTable->createTable('tmp_ad_zone_impression');
     // Prepare the test data
     $aData = array(array('ad_id' => 56, 'zone_id' => 11, 'required_impressions' => 9997, 'requested_impressions' => 9000), array('ad_id' => 56, 'zone_id' => 12, 'required_impressions' => 24, 'requested_impressions' => 24));
     $result = $oDal->saveAllocatedImpressions($aData);
     $query = "SELECT * FROM " . $oDbh->quoteIdentifier('tmp_ad_zone_impression', true) . " ORDER BY ad_id, zone_id";
     $rc = $oDbh->query($query);
     $result = $rc->fetchAll();
     $this->assertTrue(is_array($result));
     $this->assertTrue(count($result) == 2);
     $tmp = $result[0];
     $this->assertTrue(array_key_exists('ad_id', $tmp));
     $this->assertEqual($tmp['ad_id'], 56);
     $this->assertTrue(array_key_exists('zone_id', $tmp));
     $this->assertEqual($tmp['zone_id'], 11);
     $this->assertTrue(array_key_exists('required_impressions', $tmp));
     $this->assertEqual($tmp['required_impressions'], 9997);
     $this->assertTrue(array_key_exists('requested_impressions', $tmp));
     $this->assertEqual($tmp['requested_impressions'], 9000);
     $tmp = $result[1];
     $this->assertTrue(array_key_exists('ad_id', $tmp));
     $this->assertEqual($tmp['ad_id'], 56);
     $this->assertTrue(array_key_exists('zone_id', $tmp));
     $this->assertEqual($tmp['zone_id'], 12);
     $this->assertTrue(array_key_exists('required_impressions', $tmp));
     $this->assertEqual($tmp['required_impressions'], 24);
     $this->assertTrue(array_key_exists('requested_impressions', $tmp));
     $this->assertEqual($tmp['requested_impressions'], 24);
     TestEnv::dropTempTables();
 }
 /**
  * A method to test the getEcpmAgenciesIds method.
  */
 function testGetEcpmAgenciesIds()
 {
     $this->_generateTestData();
     $da = new OA_Dal_Maintenance_Priority();
     $ret = $da->getEcpmAgenciesIds();
     $this->assertEqual($this->aExpectedData, $ret);
     DataGenerator::cleanUp();
 }
 /**
  * A method to test the getCampaignsInfoByAgencyId method.
  */
 function testGetCampaignsInfoByAgencyIdAndPriority()
 {
     list($agencyId1, $agencyId2) = $this->_generateAgencyCampaigns($priority = 4, 1);
     $da = new OA_Dal_Maintenance_Priority();
     // Test 1 getCampaignsInfoByAgencyId method.
     $ret = $da->getCampaignsInfoByAgencyIdAndPriority($agencyId1, $priority);
     $this->checkTestResults($ret, $this->firsCampaignId, $this->firsAdId);
     // Test 2 getCampaignsInfoByAgencyId method.
     $ret = $da->getCampaignsInfoByAgencyIdAndPriority($agencyId2, $priority);
     $this->checkTestResults($ret, $this->secondCampaignId, $this->secondAdId);
     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();
 }
 /**
  * A method for testing the obtainPriorityLock and
  * releasePriorityLock methods.
  *
  * @TODO Complete testing using a separate client connection to
  *       ensure locking works.
  */
 function testLocking()
 {
     $oDbh =& OA_DB::singleton();
     $oDal = new OA_Dal_Maintenance_Priority();
     // Try to get the lock
     $result = $oDal->obtainPriorityLock();
     $this->assertTrue($result);
     // Try to get the lock again, with a brand new connection,
     // and ensure that the lock is NOT obtained
     // Release the lock
     $result = $oDal->releasePriorityLock();
     $this->assertTrue($result);
     // Try to get the lock again with the new connection, and
     // ensure the lock IS obtained
     // Release the lock from the new connection
 }
 /**
  * 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();
 }
 /**
  * Method to test the updateEcpmPriorities method.
  */
 function testUpdateEcpmPriorities()
 {
     $conf = $GLOBALS['_MAX']['CONF'];
     $oDal = new OA_Dal_Maintenance_Priority();
     // set up ad_zone_assoc records
     $this->addAdZoneAssoc($adId1 = 1, $zoneId1 = 1, 0.1);
     $this->addAdZoneAssoc($adId1 = 1, $zoneId2 = 2, 0.2);
     $this->addAdZoneAssoc($adId2 = 2, $zoneId3 = 3, 0.3);
     $this->addAdZoneAssoc($adId4 = 4, $zoneId4 = 4, $priority44 = 0.4);
     $aData = array($adId1 => array($zoneId1 => $priority11 = 0.11, $zoneId2 => $priority12 = 0.12), $adId2 => array($zoneId3 => $priority23 = 0.23));
     $ret = $oDal->updateEcpmPriorities($aData);
     $this->assertTrue($ret);
     $this->checkPriority($adId1, $zoneId1, $priority11);
     $this->checkPriority($adId1, $zoneId2, $priority12);
     $this->checkPriority($adId2, $zoneId3, $priority23);
     // Check that this priority didn't change
     $this->checkPriority($adId4, $zoneId4, $priority44);
     DataGenerator::cleanUp();
 }
 /**
  * Method to test the updateCampaignsEcpms method.
  */
 function testUpdateCampaignsEcpms()
 {
     $conf = $GLOBALS['_MAX']['CONF'];
     $oDal = new OA_Dal_Maintenance_Priority();
     $aOldEcpms = array('0.1', '0.2', '0.3', '0.4', '0.5');
     $aCampaignsIds = array();
     foreach ($aOldEcpms as $ecpm) {
         $aCampaignsEcpms[$this->addCampaign($ecpm)] = $ecpm;
     }
     $testCampaignId = $this->addCampaign($testEcpm = '0.9');
     foreach ($aCampaignsEcpms as $campaignId => $ecpm) {
         $aCampaignsEcpms[$campaignId] += '0.01';
     }
     // update eCPMs
     $oDal->updateCampaignsEcpms($aCampaignsEcpms);
     // test that ecpms were correctly updates
     foreach ($aCampaignsEcpms as $campaignId => $ecpm) {
         $this->checkEcpm($campaignId, $ecpm);
     }
     // test that existing ecpms weren't changed
     $this->checkEcpm($testCampaignId, $testEcpm);
     DataGenerator::cleanUp();
 }
 /**
  * A method to be run before all tests.
  */
 function setUp()
 {
     // Set up the configuration array to have an operation interval
     // of 60 minutes, and set the timezone to GMT
     $aConf =& $GLOBALS['_MAX']['CONF'];
     $aConf['maintenance']['operationInteval'] = 60;
     OA_setTimeZone('GMT');
     //setTimeZoneLocation($aConf['timezone']['location']);
     // Set up the database handler object
     $this->oDbh =& OA_DB::singleton();
     // Set up the service locator object
     $this->oServiceLocator =& OA_ServiceLocator::instance();
     // Discover the number of operation intervals per week
     $this->intervalsPerWeek = OX_OperationInterval::operationIntervalsPerWeek();
     // This test was written with a ZONE_FORECAST_DEFAULT_ZONE_IMPRESSIONS value of 10 in mind.
     OA_Dal_Maintenance_Priority::$ZONE_FORECAST_DEFAULT_ZONE_IMPRESSIONS = 10;
 }
 /**
  * Method to test the getAllZonesWithAllocInv 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 DEPRECATED_testGetAllZonesWithAllocInv()
 {
     $conf = $GLOBALS['_MAX']['CONF'];
     $oDbh =& OA_DB::singleton();
     $oMaxDalMaintenance = new OA_Dal_Maintenance_Priority();
     // Create the required temporary table for the tests
     $oTable =& OA_DB_Table_Priority::singleton();
     $oTable->createTable('tmp_ad_zone_impression');
     $tableTmp = $oDbh->quoteIdentifier('tmp_ad_zone_impression', true);
     // Test 1
     $result =& $oMaxDalMaintenance->getAllZonesWithAllocInv();
     $this->assertEqual(count($result), 0);
     // Test 2
     $query = "\n            INSERT INTO\n                {$tableTmp}\n                (\n                    ad_id,\n                    zone_id,\n                    required_impressions,\n                    requested_impressions\n                )\n            VALUES\n                (\n                    1,\n                    1,\n                    2,\n                    3\n                )";
     $rows = $oDbh->exec($query);
     $query = "\n            INSERT INTO\n                {$tableTmp}\n                (\n                    ad_id,\n                    zone_id,\n                    required_impressions,\n                    requested_impressions\n                )\n            VALUES\n                (\n                    1,\n                    2,\n                    4,\n                    5\n                )";
     $rows = $oDbh->exec($query);
     $query = "\n            INSERT INTO\n                {$tableTmp}\n                (\n                    ad_id,\n                    zone_id,\n                    required_impressions,\n                    requested_impressions\n                )\n            VALUES\n                (\n                    2,\n                    2,\n                    6,\n                    7\n                )";
     $rows = $oDbh->exec($query);
     $result =& $oMaxDalMaintenance->getAllZonesWithAllocInv();
     $this->assertEqual(count($result), 3);
     $this->assertEqual($result[0]['zone_id'], 1);
     $this->assertEqual($result[0]['ad_id'], 1);
     $this->assertEqual($result[0]['required_impressions'], 2);
     $this->assertEqual($result[0]['requested_impressions'], 3);
     $this->assertEqual($result[1]['zone_id'], 2);
     $this->assertEqual($result[1]['ad_id'], 1);
     $this->assertEqual($result[1]['required_impressions'], 4);
     $this->assertEqual($result[1]['requested_impressions'], 5);
     $this->assertEqual($result[2]['zone_id'], 2);
     $this->assertEqual($result[2]['ad_id'], 2);
     $this->assertEqual($result[2]['required_impressions'], 6);
     $this->assertEqual($result[2]['requested_impressions'], 7);
     TestEnv::dropTempTables();
 }
 /**
  * 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));
     // Test 4 getTimezoneForCampaign method
     $oTz = $da->getTimezoneForCampaign(1);
     $this->assertIsA($oTz, 'Date_TimeZone');
     $this->assertEqual($oTz->getID(), 'UTC');
     $doPreferences = OA_Dal::factoryDO('preferences');
     $doPreferences->preference_name = 'timezone';
     $doPreferences->account_type = OA_ACCOUNT_MANAGER;
     $preferenceId = DataGenerator::generateOne($doPreferences);
     $doAccount_Preference_Assoc = OA_Dal::factoryDO('account_preference_assoc');
     $doAccount_Preference_Assoc->account_id = 3;
     $doAccount_Preference_Assoc->preference_id = $preferenceId;
     $doAccount_Preference_Assoc->value = 'Europe/Rome';
     DataGenerator::generateOne($doAccount_Preference_Assoc);
     $oTz = $da->getTimezoneForCampaign(5);
     $this->assertIsA($oTz, 'Date_TimeZone');
     $this->assertEqual($oTz->getID(), 'Europe/Rome');
     // Test cache
     $doAccount_Preference_Assoc = OA_Dal::factoryDO('account_preference_assoc');
     $doAccount_Preference_Assoc->account_id = 3;
     $doAccount_Preference_Assoc->preference_id = $preferenceId;
     $doAccount_Preference_Assoc->value = 'Europe/Berlin';
     $doAccount_Preference_Assoc->update();
     $oTz = $da->getTimezoneForCampaign(5);
     $this->assertIsA($oTz, 'Date_TimeZone');
     $this->assertEqual($oTz->getID(), 'Europe/Rome');
     DataGenerator::cleanUp();
 }
 /**
  * Method to test the getPreviousAdDeliveryInfo method.
  *
  * Requirements:
  * Test 1:   Test with no Date registered in the service locator, ensure false returned.
  * Test 2:   Test with a Date registered in the service locator, no data in the database,
  *           and ensure no data is returned.
  *
  * Test 3:   Test with ONLY impression data, but NOT in the previous OI, and ensure no
  *           data is returned.
  * Test 4:   Test with ONLY impression data, in the previous OI, and ensure that ONLY
  *           data relating to the impressions is returned.
  * Test 5:   Test with ONLY impression data, in the 2nd previous OI, and ensure that
  *           no data is returned.
  * Test 5a:  Re-test with ONLY impression data, in the 2nd previous OI, but pass in the
  *           ad/zone pair, and ensure that no data is returned.
  *
  * Test 6:   Test with ONLY prioritisation data, but NOT in the previous OI, and
  *           ensure no data is returned.
  * Test 7:   Test with ONLY prioritisation data, in the previous OI, and ensure that
  *           ONLY data relating to the prioritisation is returned.
  * Test 8:   Test with ONLY prioritisation data, in the 2nd previous OI, and ensure no
  *           data is returned.
  * Test 8a:  Re-test with ONLY prioritisation data, in the 2nd previous OI, but pass in
  *           the ad/zone pair, and ensure that ONLY data relating to the prioritisation
  *           is returned.
  *
  * Test 9:   Test with BOTH impressions data NOT in the previous OI, and prioritisation
  *           data NOT in the previous OI, and ensure no data is returned.
  * Test 10:  Test with BOTH impressions data NOT in the previous OI, and prioritisation
  *           data in the previous OI, and ensure ONLY data relating to the prioritisation
  *           is returned.
  * Test 11:  Test with BOTH impressions data NOT in the previous OI, and prioritisation
  *           data in the 2nd previous OI, and ensure no data is returned.
  * Test 11a: Re-test with BOTH impressions data NOT in the previous OI, and prioritisation
  *           data in the 2nd previous OI, but pass in the ad/zone pair, and ensure that
  *           ONLY data relating to the prioritisation is returned.
  *
  * Test 12:  Test with BOTH impressions data in the 2nd previous OI, and prioritisation
  *           data NOT in the previous OI, and ensure no data is returned.
  * Test 13:  Test with BOTH impressions data in the 2nd previous OI, and prioritisation
  *           data in the previous OI, and ensure ONLY data relating to the prioritisation
  *           is returned.
  * Test 14:  Test with BOTH impressions data in the 2nd previous OI, and prioritisation
  *           data in the 2nd previous OI, and ensure no data is returned.
  * Test 14a: Re-test with BOTH impressions data in the 2nd previous OI, and prioritisation
  *           data in the 2nd previous OI, but pass in the ad/zone pair, and ensure that
  *           all data is returned.
  *
  * Test 15:  Test with BOTH impressions data in the previous OI, and prioritisation
  *           data NOT in the previous OI, and ensure that ONLY data relating to the
  *           impressions is returned.
  * Test 16:  Test with BOTH impressions data in the previous OI, and prioritisation
  *           data in the previous OI, and ensure that all data is returned.
  * Test 17:  Test with BOTH impressions data in the previous OI, and prioritisation
  *           data in the 2nd previous OI, and ensure that all data is returned.
  * Test 17a: Re-test with BOTH impressions data in the previous OI, and prioritisation
  *           data in the 2nd previous OI, but pass in the ad/zone pair, and ensure that
  *           all data is returned.
  *
  * Test 18:  Perform a more realistic test, with data for the ads/zones in various
  *           past OIs, and including some ads with multiple prioritisation data
  *           per OI, as well as ads with no prioritisation data in some OIs, and
  *           ensure that the correct values are returned for each one. Test that:
  *           - Only ad/zones that delivered in the previous operation interval,
  *             or were requested to deliver in the previous operation interval,
  *             but didn't (i.e. not in other intervals) are returned in the
  *             results.
  *           - That prioritisation information where just ONE set of data exists
  *             is returned correctly.
  *           - That prioritisation information where multiple sets of INDENTICAL
  *             data exists is returned correctly.
  *           - That prioritisation information where multiple sets of DIFFERENT
  *             data exists is returned correctly.
  *           - That prioritisation information from older sets of data is
  *             returned correctly.
  * Test 18a: Re-test, but also include ad/zone pairs that are in/not in the above
  *           set of data, and ensure that these ad/zone pairs are also included
  *           in the results.
  */
 function testGetPreviousAdDeliveryInfo()
 {
     $conf = $GLOBALS['_MAX']['CONF'];
     $oDbh =& OA_DB::singleton();
     $oMaxDalMaintenance = new OA_Dal_Maintenance_Priority();
     $aEmptyZoneAdArray = array();
     $aAdParams = array('ad_id' => 1, 'active' => 't', 'type' => 'sql', 'weight' => 1);
     $oAd = new OA_Maintenance_Priority_Ad($aAdParams);
     $oZone = new OX_Maintenance_Priority_Zone(array('zoneid' => 1));
     $oZone->addAdvert($oAd);
     $aZoneAdArray = array($oZone->id => $oZone);
     // Test 1
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oServiceLocator->remove('now');
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
     $this->assertFalse($result);
     // Test 2
     $oDate = new Date();
     $oServiceLocator->register('now', $oDate);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
     $this->assertEqual(count($result), 0);
     // Test 3
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
     $oNow = new Date();
     $bannerId1 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $operationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 1, 1, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
     $this->assertEqual(count($result), 0);
     $oDate =& $oServiceLocator->get('now');
     DataGenerator::cleanUp();
     $oServiceLocator->register('now', $oDate);
     // Test 4
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $bannerId1 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 1, 1, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
     $this->assertEqual(count($result), 1);
     $this->assertEqual($result[1][1]['ad_id'], $bannerId1);
     $this->assertEqual($result[1][1]['zone_id'], 1);
     $this->assertNull($result[1][1]['required_impressions']);
     $this->assertNull($result[1][1]['requested_impressions']);
     $this->assertNull($result[1][1]['priority_factor']);
     $this->assertNull($result[1][1]['past_zone_traffic_fraction']);
     $this->assertEqual($result[1][1]['impressions'], 1);
     $oDate =& $oServiceLocator->get('now');
     DataGenerator::cleanUp();
     $oServiceLocator->register('now', $oDate);
     // Test 5, 5a
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($previousOperationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($aDates['start']);
     $bannerId1 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 1, 1, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
     $this->assertEqual(count($result), 0);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aZoneAdArray);
     $this->assertEqual(count($result), 0);
     $oDate =& $oServiceLocator->get('now');
     DataGenerator::cleanUp();
     $oServiceLocator->register('now', $oDate);
     // Test 6
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
     $bannerId1 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $operationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId1, 1, 1, 1, 0.1, 0.5, 0.99, $oNow->format('%Y-%m-%d %H:%M:%S'), 0);
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
     $this->assertEqual(count($result), 0);
     $oDate =& $oServiceLocator->get('now');
     DataGenerator::cleanUp();
     $oServiceLocator->register('now', $oDate);
     // Test 7
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $bannerId1 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId1, 1, 1, 1, 0, 0.5, 0.99, $oNow->format('%Y-%m-%d %H:%M:%S'), 0);
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
     $this->assertEqual(count($result), 1);
     $this->assertEqual($result[1][1]['ad_id'], $bannerId1);
     $this->assertEqual($result[1][1]['zone_id'], 1);
     $this->assertEqual($result[1][1]['required_impressions'], 1);
     $this->assertEqual($result[1][1]['requested_impressions'], 1);
     $this->assertEqual($result[1][1]['priority_factor'], 0.5);
     $this->assertEqual($result[1][1]['past_zone_traffic_fraction'], 0.99);
     $this->assertNull($result[1][1]['impressions']);
     $oDate =& $oServiceLocator->get('now');
     DataGenerator::cleanUp();
     $oServiceLocator->register('now', $oDate);
     // Test 8, 8a
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($previousOperationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($aDates['start']);
     $bannerId1 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId1, 1, 1, 1, 0, 0.5, 0.99, $oNow->format('%Y-%m-%d %H:%M:%S'), 0);
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
     $this->assertEqual(count($result), 0);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aZoneAdArray);
     $this->assertEqual(count($result), 1);
     $this->assertEqual($result[1][1]['ad_id'], $bannerId1);
     $this->assertEqual($result[1][1]['zone_id'], 1);
     $this->assertEqual($result[1][1]['required_impressions'], 1);
     $this->assertEqual($result[1][1]['requested_impressions'], 1);
     $this->assertEqual($result[1][1]['priority_factor'], 0.5);
     $this->assertEqual($result[1][1]['past_zone_traffic_fraction'], 0.99);
     $this->assertNull($result[1][1]['impressions']);
     $oDate =& $oServiceLocator->get('now');
     DataGenerator::cleanUp();
     $oServiceLocator->register('now', $oDate);
     // Test 9
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
     $bannerId1 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $operationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 1, 1, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
     $aData = array($conf['maintenance']['operationInterval'], $operationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId1, 1, 1, 1, 0, 0.5, 0.99, $oNow->format('%Y-%m-%d %H:%M:%S'), 0);
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
     $this->assertEqual(count($result), 0);
     $oDate =& $oServiceLocator->get('now');
     DataGenerator::cleanUp();
     $oServiceLocator->register('now', $oDate);
     // Test 10
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
     $bannerId1 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $operationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 1, 1, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId1, 1, 1, 1, 0, 0.5, 0.99, $oNow->format('%Y-%m-%d %H:%M:%S'), 0);
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
     $this->assertEqual(count($result), 1);
     $this->assertEqual($result[1][1]['ad_id'], $bannerId1);
     $this->assertEqual($result[1][1]['zone_id'], 1);
     $this->assertEqual($result[1][1]['required_impressions'], 1);
     $this->assertEqual($result[1][1]['requested_impressions'], 1);
     $this->assertEqual($result[1][1]['priority_factor'], 0.5);
     $this->assertEqual($result[1][1]['past_zone_traffic_fraction'], 0.99);
     $this->assertNull($result[1][1]['impressions']);
     $oDate =& $oServiceLocator->get('now');
     DataGenerator::cleanUp();
     $oServiceLocator->register('now', $oDate);
     // Test 11, 11a
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
     $bannerId1 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $operationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 1, 1, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($previousOperationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($aDates['start']);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId1, 1, 1, 1, 0, 0.5, 0.99, $oNow->format('%Y-%m-%d %H:%M:%S'), 0);
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
     $this->assertEqual(count($result), 0);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aZoneAdArray);
     $this->assertEqual(count($result), 1);
     $this->assertEqual($result[1][1]['ad_id'], $bannerId1);
     $this->assertEqual($result[1][1]['zone_id'], 1);
     $this->assertEqual($result[1][1]['required_impressions'], 1);
     $this->assertEqual($result[1][1]['requested_impressions'], 1);
     $this->assertEqual($result[1][1]['priority_factor'], 0.5);
     $this->assertEqual($result[1][1]['past_zone_traffic_fraction'], 0.99);
     $this->assertNull($result[1][1]['impressions']);
     $oDate =& $oServiceLocator->get('now');
     DataGenerator::cleanUp();
     $oServiceLocator->register('now', $oDate);
     // Test 12
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($previousOperationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($aDates['start']);
     $bannerId1 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 1, 1, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
     $aData = array($conf['maintenance']['operationInterval'], $operationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId1, 1, 1, 1, 0, 0.5, 0.99, $oNow->format('%Y-%m-%d %H:%M:%S'), 0);
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
     $this->assertEqual(count($result), 0);
     $oDate =& $oServiceLocator->get('now');
     DataGenerator::cleanUp();
     $oServiceLocator->register('now', $oDate);
     // Test 13
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($previousOperationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($aDates['start']);
     $bannerId1 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 1, 1, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId1, 1, 1, 1, 0, 0.5, 0.99, $oNow->format('%Y-%m-%d %H:%M:%S'), 0);
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
     $this->assertEqual(count($result), 1);
     $this->assertEqual($result[1][1]['ad_id'], $bannerId1);
     $this->assertEqual($result[1][1]['zone_id'], 1);
     $this->assertEqual($result[1][1]['required_impressions'], 1);
     $this->assertEqual($result[1][1]['requested_impressions'], 1);
     $this->assertEqual($result[1][1]['priority_factor'], 0.5);
     $this->assertEqual($result[1][1]['past_zone_traffic_fraction'], 0.99);
     $this->assertNull($result[1][1]['impressions']);
     $oDate =& $oServiceLocator->get('now');
     DataGenerator::cleanUp();
     $oServiceLocator->register('now', $oDate);
     // Test 14, 14a
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($previousOperationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($aDates['start']);
     $bannerId1 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 1, 1, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($previousOperationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($aDates['start']);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId1, 1, 1, 1, 0, 0.5, 0.99, $oNow->format('%Y-%m-%d %H:%M:%S'), 0);
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
     $this->assertEqual(count($result), 0);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aZoneAdArray);
     $this->assertEqual(count($result), 1);
     $this->assertEqual($result[1][1]['ad_id'], $bannerId1);
     $this->assertEqual($result[1][1]['zone_id'], 1);
     $this->assertEqual($result[1][1]['required_impressions'], 1);
     $this->assertEqual($result[1][1]['requested_impressions'], 1);
     $this->assertEqual($result[1][1]['priority_factor'], 0.5);
     $this->assertEqual($result[1][1]['past_zone_traffic_fraction'], 0.99);
     $this->assertEqual($result[1][1]['impressions'], 1);
     $oDate =& $oServiceLocator->get('now');
     DataGenerator::cleanUp();
     $oServiceLocator->register('now', $oDate);
     // Test 15
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $bannerId1 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 1, 1, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
     $aData = array($conf['maintenance']['operationInterval'], $operationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId1, 1, 1, 1, 0, 0.5, 0.99, $oNow->format('%Y-%m-%d %H:%M:%S'), 0);
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
     $this->assertEqual(count($result), 1);
     $this->assertEqual($result[1][1]['ad_id'], $bannerId1);
     $this->assertEqual($result[1][1]['zone_id'], 1);
     $this->assertNull($result[1][1]['required_impressions']);
     $this->assertNull($result[1][1]['requested_impressions']);
     $this->assertNull($result[1][1]['priority_factor']);
     $this->assertNull($result[1][1]['past_zone_traffic_fraction']);
     $this->assertEqual($result[1][1]['impressions'], 1);
     $oDate =& $oServiceLocator->get('now');
     DataGenerator::cleanUp();
     $oServiceLocator->register('now', $oDate);
     // Test 16
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $bannerId1 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 1, 1, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId1, 1, 1, 1, 0, 0.5, 0.99, $oNow->format('%Y-%m-%d %H:%M:%S'), 0);
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
     $this->assertEqual(count($result), 1);
     $this->assertEqual($result[1][1]['ad_id'], $bannerId1);
     $this->assertEqual($result[1][1]['zone_id'], 1);
     $this->assertEqual($result[1][1]['required_impressions'], 1);
     $this->assertEqual($result[1][1]['requested_impressions'], 1);
     $this->assertEqual($result[1][1]['priority_factor'], 0.5);
     $this->assertEqual($result[1][1]['past_zone_traffic_fraction'], 0.99);
     $this->assertEqual($result[1][1]['impressions'], 1);
     $oDate =& $oServiceLocator->get('now');
     DataGenerator::cleanUp();
     $oServiceLocator->register('now', $oDate);
     // Test 17, 17a
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $bannerId1 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 1, 1, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($previousOperationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($aDates['start']);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId1, 1, 1, 1, 0, 0.5, 0.99, $oNow->format('%Y-%m-%d %H:%M:%S'), 0);
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
     $this->assertEqual(count($result), 1);
     $this->assertEqual($result[1][1]['ad_id'], $bannerId1);
     $this->assertEqual($result[1][1]['zone_id'], 1);
     $this->assertEqual($result[1][1]['required_impressions'], 1);
     $this->assertEqual($result[1][1]['requested_impressions'], 1);
     $this->assertEqual($result[1][1]['priority_factor'], 0.5);
     $this->assertEqual($result[1][1]['past_zone_traffic_fraction'], 0.99);
     $this->assertEqual($result[1][1]['impressions'], 1);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aZoneAdArray);
     $this->assertEqual(count($result), 1);
     $this->assertEqual($result[1][1]['ad_id'], $bannerId1);
     $this->assertEqual($result[1][1]['zone_id'], 1);
     $this->assertEqual($result[1][1]['required_impressions'], 1);
     $this->assertEqual($result[1][1]['requested_impressions'], 1);
     $this->assertEqual($result[1][1]['priority_factor'], 0.5);
     $this->assertEqual($result[1][1]['past_zone_traffic_fraction'], 0.99);
     $this->assertEqual($result[1][1]['impressions'], 1);
     $oDate =& $oServiceLocator->get('now');
     DataGenerator::cleanUp();
     $oServiceLocator->register('now', $oDate);
     // Test 18
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $bannerId1 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 1, 1, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 2, 1, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $bannerId2 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId2, 0, 3, 2, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId2, 0, 4, 2, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $bannerId3 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId3, 0, 5, 5, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($previousOperationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($aDates['start']);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 1, 100, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 2, 100, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId2, 0, 3, 200, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId2, 0, 4, 200, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId3, 0, 5, 500, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), 4, 0, 5, 500, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $oSpecialDate = new Date($aDates['end']);
     $oSpecialDate->addSeconds(1);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId1, 2, 10, 10, 0, 0.5, 0.99, $oNow->format('%Y-%m-%d %H:%M:%S'), 0);
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), 9, 9, 59, 59, 0, 95, 0.995, $oNow->format('%Y-%m-%d %H:%M:%S'), 0);
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId2, 3, 30, 30, 0, 0.4, 0.5, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), 0, $aDates['end']->format('%Y-%m-%d %H:30:00'));
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId2, 3, 30, 30, 0, 0.4, 0.5, $aDates['start']->format('%Y-%m-%d %H:30:00'), 0, $aDates['end']->format('%Y-%m-%d %H:%M:%S'));
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId2, 4, 10, 10, 0, 0.4, 0.5, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), 0, $aDates['end']->format('%Y-%m-%d %H:30:00'));
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId2, 4, 20, 20, 0, 0.8, 0.5, $aDates['start']->format('%Y-%m-%d %H:30:00'), 0, $oSpecialDate->format('%Y-%m-%d %H:%M:%S'));
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($previousOperationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($aDates['start']);
     $oSpecialDate = new Date($aDates['end']);
     $oSpecialDate->addSeconds(1);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId3, 5, 200, 200, 0, 0.2, 0.95, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), 0, $aDates['end']->format('%Y-%m-%d %H:30:00'));
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId3, 5, 100, 100, 0, 0.4, 0.95, $aDates['start']->format('%Y-%m-%d %H:30:00'), 0, $oSpecialDate->format('%Y-%m-%d %H:%M:%S'));
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aEmptyZoneAdArray);
     $this->assertEqual(count($result), 4);
     $this->assertEqual(count($result[1]), 2);
     $this->assertEqual($result[1][1]['ad_id'], $bannerId1);
     $this->assertEqual($result[1][1]['zone_id'], 1);
     $this->assertNull($result[1][1]['required_impressions']);
     $this->assertNull($result[1][1]['requested_impressions']);
     $this->assertNull($result[1][1]['priority_factor']);
     $this->assertNull($result[1][1]['past_zone_traffic_fraction']);
     $this->assertEqual($result[1][1]['impressions'], 1);
     $this->assertEqual($result[1][2]['ad_id'], $bannerId1);
     $this->assertEqual($result[1][2]['zone_id'], 2);
     $this->assertEqual($result[1][2]['required_impressions'], 10);
     $this->assertEqual($result[1][2]['requested_impressions'], 10);
     $this->assertEqual($result[1][2]['priority_factor'], 0.5);
     $this->assertEqual($result[1][2]['past_zone_traffic_fraction'], 0.99);
     $this->assertEqual($result[1][2]['impressions'], 1);
     $this->assertEqual(count($result[2]), 2);
     $this->assertEqual($result[2][3]['ad_id'], $bannerId2);
     $this->assertEqual($result[2][3]['zone_id'], 3);
     $this->assertEqual($result[2][3]['required_impressions'], 30);
     $this->assertEqual($result[2][3]['requested_impressions'], 30);
     $this->assertEqual($result[2][3]['priority_factor'], 0.4);
     $this->assertEqual($result[2][3]['past_zone_traffic_fraction'], 0.5);
     $this->assertEqual($result[2][3]['impressions'], 2);
     $this->assertEqual($result[2][4]['ad_id'], $bannerId2);
     $this->assertEqual($result[2][4]['zone_id'], 4);
     $this->assertEqual($result[2][4]['required_impressions'], 15);
     $this->assertEqual($result[2][4]['requested_impressions'], 15);
     $this->assertEqual($result[2][4]['priority_factor'], 0.6);
     $this->assertEqual($result[2][4]['past_zone_traffic_fraction'], 0.5);
     $this->assertEqual($result[2][4]['impressions'], 2);
     $this->assertEqual(count($result[3]), 1);
     $this->assertEqual($result[3][5]['ad_id'], $bannerId3);
     $this->assertEqual($result[3][5]['zone_id'], 5);
     $this->assertEqual($result[3][5]['required_impressions'], 150);
     $this->assertEqual($result[3][5]['requested_impressions'], 150);
     $this->assertEqual($result[3][5]['priority_factor'], 0.3);
     $this->assertEqual($result[3][5]['past_zone_traffic_fraction'], 0.95);
     $this->assertEqual($result[3][5]['impressions'], 5);
     $this->assertEqual(count($result[9]), 1);
     $this->assertEqual($result[9][9]['ad_id'], 9);
     $this->assertEqual($result[9][9]['zone_id'], 9);
     $this->assertEqual($result[9][9]['required_impressions'], 59);
     $this->assertEqual($result[9][9]['requested_impressions'], 59);
     $this->assertEqual($result[9][9]['priority_factor'], 95);
     $this->assertEqual($result[9][9]['past_zone_traffic_fraction'], 0.995);
     $this->assertNull($result[9][9]['impressions']);
     $oDate =& $oServiceLocator->get('now');
     DataGenerator::cleanUp();
     $oServiceLocator->register('now', $oDate);
     // Test 18a
     $oZone = new OX_Maintenance_Priority_Zone(array('zoneid' => 4));
     $aAdParams = array('ad_id' => 10, 'active' => 't', 'type' => 'sql', 'weight' => 1);
     $oAd = new OA_Maintenance_Priority_Ad($aAdParams);
     $oZone->addAdvert($oAd);
     $aAdParams = array('ad_id' => 11, 'active' => 't', 'type' => 'sql', 'weight' => 1);
     $oAd = new OA_Maintenance_Priority_Ad($aAdParams);
     $oZone->addAdvert($oAd);
     $aZoneAdArray = array($oZone->id => $oZone);
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $bannerId1 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 1, 1, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 2, 1, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $bannerId2 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId2, 0, 3, 2, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId2, 0, 4, 2, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $bannerId3 = $this->_insertCampaignBanner();
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId3, 0, 5, 5, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($previousOperationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($aDates['start']);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 1, 100, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId1, 0, 2, 100, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId2, 0, 3, 200, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId2, 0, 4, 200, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), $bannerId3, 0, 5, 500, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), 4, 0, 5, 500, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), 10, 0, 4, 1000, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     for ($i = 0; $i <= MINUTES_PER_WEEK / $conf['maintenance']['operationInterval']; $i++) {
         $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($previousOperationIntervalID);
     }
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     for ($i = 0; $i <= MINUTES_PER_WEEK / $conf['maintenance']['operationInterval']; $i++) {
         $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($aDates['start']);
     }
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $aDates['start']->format('%Y-%m-%d'), $aDates['start']->format('%H'), 11, 0, 4, 2000, $oNow->format('%Y-%m-%d %H:%M:%S'));
     $idDia = $this->_insertDataIntermediateAd($aData);
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $oSpecialDate = new Date($aDates['end']);
     $oSpecialDate->addSeconds(1);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId1, 2, 10, 10, 0, 0.5, 0.99, $oNow->format('%Y-%m-%d %H:%M:%S'), 0);
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), 9, 9, 59, 59, 0, 95, 0.995, $oNow->format('%Y-%m-%d %H:%M:%S'), 0);
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId2, 3, 30, 30, 0, 0.4, 0.5, $aDates['start']->format('%Y-%m-%d %H:30:00'), 0, $oSpecialDate->format('%Y-%m-%d %H:%M:%S'));
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId2, 3, 30, 30, 0, 0.4, 0.5, $aDates['start']->format('%Y-%m-%d %H:30:00'), 0, $aDates['end']->format('%Y-%m-%d %H:%M:%S'));
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId2, 4, 10, 10, 0, 0.4, 0.5, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), 0, $aDates['end']->format('%Y-%m-%d %H:30:00'));
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId2, 4, 20, 20, 0, 0.8, 0.5, $aDates['start']->format('%Y-%m-%d %H:30:00'), 0, $oSpecialDate->format('%Y-%m-%d %H:%M:%S'));
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($previousOperationIntervalID);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($aDates['start']);
     $oSpecialDate = new Date($aDates['end']);
     $oSpecialDate->addSeconds(1);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId3, 5, 200, 200, 0, 0.2, 0.95, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), 0, $aDates['end']->format('%Y-%m-%d %H:30:00'));
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), $bannerId3, 5, 100, 100, 0, 0.4, 0.95, $aDates['start']->format('%Y-%m-%d %H:30:00'), 0, $oSpecialDate->format('%Y-%m-%d %H:%M:%S'));
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), 10, 4, 1000, 1000, 0, 1, 0.9, $aDates['start']->format('%Y-%m-%d %H:30:00'), 0, $oSpecialDate->format('%Y-%m-%d %H:%M:%S'));
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     for ($i = 0; $i <= MINUTES_PER_WEEK / $conf['maintenance']['operationInterval']; $i++) {
         $previousOperationIntervalID = OX_OperationInterval::previousOperationIntervalID($previousOperationIntervalID);
     }
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     for ($i = 0; $i <= MINUTES_PER_WEEK / $conf['maintenance']['operationInterval']; $i++) {
         $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($aDates['start']);
     }
     $oSpecialDate = new Date($aDates['end']);
     $oSpecialDate->addSeconds(1);
     $aData = array($conf['maintenance']['operationInterval'], $previousOperationIntervalID, $aDates['start']->format('%Y-%m-%d %H:%M:%S'), $aDates['end']->format('%Y-%m-%d %H:%M:%S'), 11, 4, 2000, 2000, 0, 1, 0.9, $aDates['start']->format('%Y-%m-%d %H:30:00'), 0, $oSpecialDate->format('%Y-%m-%d %H:%M:%S'));
     $this->_insertDataSummaryAdZoneAssoc($aData);
     $result =& $oMaxDalMaintenance->getPreviousAdDeliveryInfo($aZoneAdArray);
     $this->assertEqual(count($result), 5);
     $this->assertEqual(count($result[1]), 2);
     $this->assertEqual($result[1][1]['ad_id'], $bannerId1);
     $this->assertEqual($result[1][1]['zone_id'], 1);
     $this->assertNull($result[1][1]['required_impressions']);
     $this->assertNull($result[1][1]['requested_impressions']);
     $this->assertNull($result[1][1]['priority_factor']);
     $this->assertNull($result[1][1]['past_zone_traffic_fraction']);
     $this->assertEqual($result[1][1]['impressions'], 1);
     $this->assertEqual($result[1][2]['ad_id'], $bannerId1);
     $this->assertEqual($result[1][2]['zone_id'], 2);
     $this->assertEqual($result[1][2]['required_impressions'], 10);
     $this->assertEqual($result[1][2]['requested_impressions'], 10);
     $this->assertEqual($result[1][2]['priority_factor'], 0.5);
     $this->assertEqual($result[1][2]['past_zone_traffic_fraction'], 0.99);
     $this->assertEqual($result[1][2]['impressions'], 1);
     $this->assertEqual(count($result[2]), 2);
     $this->assertEqual($result[2][3]['ad_id'], $bannerId2);
     $this->assertEqual($result[2][3]['zone_id'], 3);
     $this->assertEqual($result[2][3]['required_impressions'], 30);
     $this->assertEqual($result[2][3]['requested_impressions'], 30);
     $this->assertEqual($result[2][3]['priority_factor'], 0.4);
     $this->assertEqual($result[2][3]['past_zone_traffic_fraction'], 0.5);
     $this->assertEqual($result[2][3]['impressions'], 2);
     $this->assertEqual($result[2][4]['ad_id'], $bannerId2);
     $this->assertEqual($result[2][4]['zone_id'], 4);
     $this->assertEqual($result[2][4]['required_impressions'], 15);
     $this->assertEqual($result[2][4]['requested_impressions'], 15);
     $this->assertEqual($result[2][4]['priority_factor'], 0.6);
     $this->assertEqual($result[2][4]['past_zone_traffic_fraction'], 0.5);
     $this->assertEqual($result[2][4]['impressions'], 2);
     $this->assertEqual(count($result[3]), 1);
     $this->assertEqual($result[3][5]['ad_id'], $bannerId3);
     $this->assertEqual($result[3][5]['zone_id'], 5);
     $this->assertEqual($result[3][5]['required_impressions'], 150);
     $this->assertEqual($result[3][5]['requested_impressions'], 150);
     $this->assertEqual($result[3][5]['priority_factor'], 0.3);
     $this->assertEqual($result[3][5]['past_zone_traffic_fraction'], 0.95);
     $this->assertEqual($result[3][5]['impressions'], 5);
     $this->assertEqual(count($result[9]), 1);
     $this->assertEqual($result[9][9]['ad_id'], 9);
     $this->assertEqual($result[9][9]['zone_id'], 9);
     $this->assertEqual($result[9][9]['required_impressions'], 59);
     $this->assertEqual($result[9][9]['requested_impressions'], 59);
     $this->assertEqual($result[9][9]['priority_factor'], 95);
     $this->assertEqual($result[9][9]['past_zone_traffic_fraction'], 0.995);
     $this->assertNull($result[9][9]['impressions']);
     $this->assertEqual(count($result[10]), 1);
     $this->assertEqual($result[10][4]['ad_id'], 10);
     $this->assertEqual($result[10][4]['zone_id'], 4);
     $this->assertEqual($result[10][4]['required_impressions'], 1000);
     $this->assertEqual($result[10][4]['requested_impressions'], 1000);
     $this->assertEqual($result[10][4]['priority_factor'], 1);
     $this->assertEqual($result[10][4]['past_zone_traffic_fraction'], 0.9);
     $this->assertEqual($result[10][4]['impressions'], 1000);
     TestEnv::restoreEnv();
 }
 /**
  * A method to test the getAdZoneAssociationsByAds method.
  *
  * Test 1: Test with bad input, and ensure that an empty array is retuend.
  * Test 2: Test with no data, and ensure that an empty array is returned.
  * Test 3: Test with one ad/zone link, and ensure the correct data is returned.
  * Test 4: Test with a more complex set of data.
  */
 function testGetAdZoneAssociationsByAds()
 {
     $conf = $GLOBALS['_MAX']['CONF'];
     $oDbh =& OA_DB::singleton();
     $oDal = new OA_Dal_Maintenance_Priority();
     // Test 1
     $result = $oDal->getAdZoneAssociationsByAds(1);
     $this->assertTrue(is_array($result));
     $this->assertEqual(count($result), 0);
     // Test 2
     $aAdIds = array(1);
     $result = $oDal->getAdZoneAssociationsByAds($aAdIds);
     $this->assertTrue(is_array($result));
     $this->assertEqual(count($result), 0);
     // Test 3
     $doZones = OA_Dal::factoryDO('zones');
     $zoneId = DataGenerator::generateOne($doZones, true);
     $doAdZone = OA_Dal::factoryDO('ad_zone_assoc');
     $doAdZone->ad_id = 1;
     $doAdZone->zone_id = $zoneId;
     $doAdZone->link_type = 1;
     $idAdZone = DataGenerator::generateOne($doAdZone);
     $aAdIds = array(1);
     $result = $oDal->getAdZoneAssociationsByAds($aAdIds);
     $this->assertTrue(is_array($result));
     $this->assertEqual(count($result), 1);
     $this->assertTrue(is_array($result[1]));
     $this->assertEqual(count($result[1]), 1);
     $this->assertTrue(is_array($result[1][0]));
     $this->assertEqual(count($result[1][0]), 1);
     $this->assertTrue(isset($result[1][0]['zone_id']));
     $this->assertEqual($result[1][0]['zone_id'], 1);
     DataGenerator::cleanUp();
     // Test 4
     $zoneId1 = DataGenerator::generateOne($doZones, true);
     $doAdZone->ad_id = 1;
     $doAdZone->zone_id = $zoneId1;
     $doAdZone->link_type = 1;
     $idAdZone = DataGenerator::generateOne($doAdZone);
     $zoneId2 = DataGenerator::generateOne($doZones, true);
     $doAdZone->ad_id = 1;
     $doAdZone->zone_id = $zoneId2;
     $doAdZone->link_type = 1;
     $idAdZone = DataGenerator::generateOne($doAdZone);
     $zoneId3 = DataGenerator::generateOne($doZones, true);
     $doAdZone->ad_id = 1;
     $doAdZone->zone_id = $zoneId3;
     $doAdZone->link_type = 1;
     $idAdZone = DataGenerator::generateOne($doAdZone);
     $doAdZone->ad_id = 2;
     $doAdZone->zone_id = $zoneId2;
     $doAdZone->link_type = 1;
     $idAdZone = DataGenerator::generateOne($doAdZone);
     $doAdZone->ad_id = 2;
     $doAdZone->zone_id = $zoneId3;
     $doAdZone->link_type = 0;
     $idAdZone = DataGenerator::generateOne($doAdZone);
     $zoneId = DataGenerator::generateOne($doZones, true);
     $doAdZone->ad_id = 3;
     $doAdZone->zone_id = $zoneId1;
     $doAdZone->link_type = 1;
     $idAdZone = DataGenerator::generateOne($doAdZone);
     $zoneId4 = DataGenerator::generateOne($doZones, true);
     $zoneId = DataGenerator::generateOne($doZones, true);
     $doAdZone->ad_id = 3;
     $doAdZone->zone_id = $zoneId4;
     $doAdZone->link_type = 1;
     $idAdZone = DataGenerator::generateOne($doAdZone);
     $aAdIds = array(1, 2, 3);
     $result = $oDal->getAdZoneAssociationsByAds($aAdIds);
     $this->assertTrue(is_array($result));
     $this->assertEqual(count($result), 3);
     $this->assertTrue(is_array($result[1]));
     $this->assertEqual(count($result[1]), 3);
     $this->assertTrue(is_array($result[1][0]));
     $this->assertEqual(count($result[1][0]), 1);
     $this->assertTrue(isset($result[1][0]['zone_id']));
     $this->assertEqual($result[1][0]['zone_id'], $zoneId1);
     $this->assertTrue(is_array($result[1][1]));
     $this->assertEqual(count($result[1][1]), 1);
     $this->assertTrue(isset($result[1][1]['zone_id']));
     $this->assertEqual($result[1][1]['zone_id'], $zoneId2);
     $this->assertTrue(is_array($result[1][2]));
     $this->assertEqual(count($result[1][2]), 1);
     $this->assertTrue(isset($result[1][2]['zone_id']));
     $this->assertEqual($result[1][2]['zone_id'], $zoneId3);
     $this->assertTrue(is_array($result[2]));
     $this->assertEqual(count($result[2]), 1);
     $this->assertTrue(is_array($result[2][0]));
     $this->assertEqual(count($result[2][0]), 1);
     $this->assertTrue(isset($result[2][0]['zone_id']));
     $this->assertEqual($result[2][0]['zone_id'], $zoneId2);
     $this->assertTrue(is_array($result[3]));
     $this->assertEqual(count($result[3]), 2);
     $this->assertTrue(is_array($result[3][0]));
     $this->assertEqual(count($result[3][0]), 1);
     $this->assertTrue(isset($result[3][0]['zone_id']));
     $this->assertEqual($result[3][0]['zone_id'], $zoneId1);
     $this->assertTrue(is_array($result[3][1]));
     $this->assertEqual(count($result[3][1]), 1);
     $this->assertTrue(isset($result[3][1]['zone_id']));
     $this->assertEqual($result[3][1]['zone_id'], $zoneId4);
     DataGenerator::cleanUp();
 }
 /**
  * Method to test the getMaintenancePriorityLastRunInfo 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.
  * Test 4: Test correct results are returned with multiple run types.
  */
 function testGetMaintenancePriorityLastRunInfo()
 {
     $conf = $GLOBALS['_MAX']['CONF'];
     $oDbh =& OA_DB::singleton();
     $oMaxDalMaintenance = new OA_Dal_Maintenance_Priority();
     // Test 1
     $result = $oMaxDalMaintenance->getMaintenancePriorityLastRunInfo(DAL_PRIORITY_UPDATE_ECPM);
     $this->assertFalse($result);
     // Test 2
     $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');
     $oMaxDalMaintenance->setMaintenancePriorityLastRunInfo($oStartDate, $oEndDate, $oUpdatedTo, DAL_PRIORITY_UPDATE_ECPM);
     $result = $oMaxDalMaintenance->getMaintenancePriorityLastRunInfo(DAL_PRIORITY_UPDATE_ECPM);
     $this->assertTrue(is_array($result));
     $this->assertEqual($result['updated_to'], '2005-06-21 15:59:59');
     $this->assertEqual($result['operation_interval'], $conf['maintenance']['operationInterval']);
     // Test 3
     $oStartDate = new Date('2005-06-21 14:00:01');
     $oEndDate = new Date('2005-06-21 14:01:01');
     $oUpdatedTo = new Date('2005-06-21 14:59:59');
     $oMaxDalMaintenance->setMaintenancePriorityLastRunInfo($oStartDate, $oEndDate, $oUpdatedTo, DAL_PRIORITY_UPDATE_ECPM);
     $result = $oMaxDalMaintenance->getMaintenancePriorityLastRunInfo(DAL_PRIORITY_UPDATE_ECPM);
     $this->assertTrue(is_array($result));
     $this->assertEqual($result['updated_to'], '2005-06-21 15:59:59');
     $this->assertEqual($result['operation_interval'], $conf['maintenance']['operationInterval']);
     $oStartDate = new Date('2005-06-21 16:00:01');
     $oEndDate = new Date('2005-06-21 16:01:01');
     $oUpdatedTo = new Date('2005-06-21 16:59:59');
     $oMaxDalMaintenance->setMaintenancePriorityLastRunInfo($oStartDate, $oEndDate, $oUpdatedTo, DAL_PRIORITY_UPDATE_ECPM);
     $result = $oMaxDalMaintenance->getMaintenancePriorityLastRunInfo(DAL_PRIORITY_UPDATE_ECPM);
     $this->assertTrue(is_array($result));
     $this->assertEqual($result['updated_to'], '2005-06-21 16:59:59');
     $this->assertEqual($result['operation_interval'], $conf['maintenance']['operationInterval']);
     // Test 4
     $result = $oMaxDalMaintenance->getMaintenancePriorityLastRunInfo(DAL_PRIORITY_UPDATE_PRIORITY_COMPENSATION);
     $this->assertFalse($result);
     DataGenerator::cleanUp(array('log_maintenance_priority'));
 }
 /**
  * A method to test the getPreviousWeekZoneForcastImpressions() method.
  *
  * Test 1: Test with bad input, and ensure false is returned.
  * Test 2: Test with no date in the service locator, and ensure that
  *         false is returned.
  * Test 3: Test with no data, and ensure that an array with the default
  *         forecast for each zone is returned.
  * Test 4: Test with data, and ensure that an array with the correct
  *         forecasts is returned.
  */
 function testGetPreviousWeekZoneForcastImpressions()
 {
     $aConf = $GLOBALS['_MAX']['CONF'];
     $oDbh =& OA_DB::singleton();
     $oDal = new OA_Dal_Maintenance_Priority();
     // Test 1
     $aResult = $oDal->getPreviousWeekZoneForcastImpressions('foo');
     $this->assertFalse($aResult);
     // Test 2
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oServiceLocator->remove('now');
     $aResult = $oDal->getPreviousWeekZoneForcastImpressions(1);
     $this->assertFalse($aResult);
     // Test 3
     $oDate = new Date();
     $oServiceLocator->register('now', $oDate);
     $aResult = $oDal->getPreviousWeekZoneForcastImpressions(1);
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), OX_OperationInterval::operationIntervalsPerWeek());
     for ($operationIntervalID = 0; $operationIntervalID < OX_OperationInterval::operationIntervalsPerWeek(); $operationIntervalID++) {
         $expected = array('zone_id' => 1, 'forecast_impressions' => $oDal->getZoneForecastDefaultZoneImpressions(), 'operation_interval_id' => $operationIntervalID);
         $this->assertEqual($aResult[$operationIntervalID], $expected);
     }
     // Test 4
     // Insert impressions for the previous operation interval
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($aDates['start']);
     $firstIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($aDates['start']);
     $startDate = $aDates['start']->format('%Y-%m-%d %H:%M:%S');
     $endDate = $aDates['start']->format('%Y-%m-%d %H:%M:%S');
     $doDIA = OA_Dal::factoryDO('data_intermediate_ad');
     $aDIAs = DataGenerator::generate($doDIA, 4);
     $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[0]);
     $startDate = $aDates['start']->format('%Y-%m-%d %H:%M:%S');
     $endDate = $aDates['start']->format('%Y-%m-%d %H:%M:%S');
     $doDIA->date_time = $startDate;
     $doDIA->interval_start = $startDate;
     $doDIA->interval_end = $endDate;
     $doDIA->operation_interval = $aConf['maintenance']['operationInterval'];
     $doDIA->operation_interval_id = $firstIntervalID;
     $doDIA->zone_id = 1;
     $doDIA->ad_id = 1;
     $doDIA->impressions = 4000;
     $doDIA->update();
     // Insert forcast for the (N - 2) OI
     // for two different ads in this OI
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($aDates['start']);
     $secondIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($aDates['start']);
     $startDate = $aDates['start']->format('%Y-%m-%d %H:%M:%S');
     $endDate = $aDates['start']->format('%Y-%m-%d %H:%M:%S');
     $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[1]);
     $doDIA->date_time = $startDate;
     $doDIA->interval_start = $startDate;
     $doDIA->interval_end = $endDate;
     $doDIA->operation_interval = $aConf['maintenance']['operationInterval'];
     $doDIA->operation_interval_id = $secondIntervalID;
     $doDIA->zone_id = 1;
     $doDIA->ad_id = 1;
     $doDIA->impressions = 4990;
     $doDIA->update();
     $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[2]);
     $doDIA->date_time = $startDate;
     $doDIA->interval_start = $startDate;
     $doDIA->interval_end = $endDate;
     $doDIA->operation_interval = $aConf['maintenance']['operationInterval'];
     $doDIA->operation_interval_id = $secondIntervalID;
     $doDIA->zone_id = 1;
     $doDIA->ad_id = 2;
     $doDIA->impressions = 10;
     $doDIA->update();
     // Insert forcast for the second previous operation interval, but
     // one week ago (so it should not be in the result set)
     $oNewDate = new Date();
     $oNewDate->copy($aDates['start']);
     $oNewDate->subtractSeconds(SECONDS_PER_WEEK);
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oNewDate);
     $intervalID = OX_OperationInterval::convertDateToOperationIntervalID($aDates['start']);
     $startDate = $aDates['start']->format('%Y-%m-%d %H:%M:%S');
     $endDate = $aDates['start']->format('%Y-%m-%d %H:%M:%S');
     $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[3]);
     $doDIA->date_time = $startDate;
     $doDIA->interval_start = $startDate;
     $doDIA->interval_end = $endDate;
     $doDIA->operation_interval = $aConf['maintenance']['operationInterval'];
     $doDIA->operation_interval_id = $intervalID;
     $doDIA->zone_id = 1;
     $doDIA->ad_id = 1;
     $doDIA->impressions = 1000;
     $doDIA->update();
     // What's the current OI?
     $currentIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oServiceLocator->get('now'));
     $aResult = $oDal->getPreviousWeekZoneForcastImpressions(1);
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), OX_OperationInterval::operationIntervalsPerWeek());
     for ($operationIntervalID = 0; $operationIntervalID < OX_OperationInterval::operationIntervalsPerWeek(); $operationIntervalID++) {
         $this->assertTrue(is_array($aResult[$operationIntervalID]));
         $this->assertEqual(count($aResult[$operationIntervalID]), 3);
         $this->assertEqual($aResult[$operationIntervalID]['zone_id'], 1);
         if ($operationIntervalID == $firstIntervalID || $operationIntervalID == $currentIntervalID) {
             // Current and previous OI forecasts should be the same
             $this->assertEqual($aResult[$operationIntervalID]['forecast_impressions'], 4000);
         } elseif ($operationIntervalID == $secondIntervalID) {
             $this->assertEqual($aResult[$operationIntervalID]['forecast_impressions'], 5000);
         } else {
             $this->assertEqual($aResult[$operationIntervalID]['forecast_impressions'], 4500);
             // average between both known forecast
         }
         $this->assertEqual($aResult[$operationIntervalID]['operation_interval_id'], $operationIntervalID);
     }
     DataGenerator::cleanUp();
 }
 /**
  * The method to test the getActiveZones() method.
  */
 function testGetActiveZones()
 {
     $oDal = new OA_Dal_Maintenance_Priority();
     // Add campaign
     $doCampaigns = OA_Dal::factoryDO('campaigns');
     $doCampaigns->campaignname = 'Active Campaign';
     $doCampaigns->status = OA_ENTITY_STATUS_RUNNING;
     $doCampaigns->priority = 9;
     $idCampaign = DataGenerator::generateOne($doCampaigns);
     // Test with no zones in the system
     $aResult = $oDal->getActiveZones();
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 0);
     // Test with two zones in the system, but with no banners linked
     $doZones = OA_Dal::factoryDO('zones');
     $oNow = new Date();
     $doZones->zonename = 'First Zone';
     $doZones->zonetype = 3;
     $doZones->updated = $oNow->format('%Y-%m-%d %H:%M:%S');
     $idZoneFirst = DataGenerator::generateOne($doZones);
     $doZones = OA_Dal::factoryDO('zones');
     $oNow = new Date();
     $doZones->zonename = 'Second Zone';
     $doZones->zonetype = 3;
     $doZones->updated = $oNow->format('%Y-%m-%d %H:%M:%S');
     $idZoneSecond = DataGenerator::generateOne($doZones);
     $aResult = $oDal->getActiveZones();
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 0);
     // Test with active and inactive banners in the system, but not linked
     $doBanners = OA_Dal::factoryDO('banners');
     $oNow = new Date();
     $doBanners->status = OA_ENTITY_STATUS_RUNNING;
     $doBanners->campaignid = $idCampaign;
     $doBanners->acls_updated = $oNow->format('%Y-%m-%d %H:%M:%S');
     $doBanners->updated = $oNow->format('%Y-%m-%d %H:%M:%S');
     $idBannerActive = DataGenerator::generateOne($doBanners, true);
     $doBanners = OA_Dal::factoryDO('banners');
     $oNow = new Date();
     $doBanners->status = OA_ENTITY_STATUS_INACTIVE;
     $doBanners->campaignid = $idCampaign;
     $doBanners->acls_updated = $oNow->format('%Y-%m-%d %H:%M:%S');
     $doBanners->updated = $oNow->format('%Y-%m-%d %H:%M:%S');
     $idBannerInactive = DataGenerator::generateOne($doBanners, true);
     $aResult = $oDal->getActiveZones();
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 0);
     // Link the active and inactive banners to different zones, and
     // check only the active zone is returned
     $doAdZone = OA_Dal::factoryDO('ad_zone_assoc');
     $doAdZone->ad_id = $idBannerActive;
     $doAdZone->zone_id = $idZoneFirst;
     $doAdZone->priority = 0;
     $doAdZone->link_type = 1;
     $doAdZone->priority_factor = 1;
     $doAdZone->to_be_delivered = 1;
     $idAdZone = DataGenerator::generateOne($doAdZone);
     $doAdZone = OA_Dal::factoryDO('ad_zone_assoc');
     $doAdZone->ad_id = $idBannerInactive;
     $doAdZone->zone_id = $idZoneSecond;
     $doAdZone->priority = 0;
     $doAdZone->link_type = 1;
     $doAdZone->priority_factor = 1;
     $doAdZone->to_be_delivered = 1;
     $idAdZone = DataGenerator::generateOne($doAdZone);
     $aResult = $oDal->getActiveZones();
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 1);
     $aZone = $aResult[0];
     $this->assertTrue(array_key_exists('zoneid', $aZone));
     $this->assertTrue(array_key_exists('zonename', $aZone));
     $this->assertTrue(array_key_exists('zonetype', $aZone));
     $this->assertEqual($aZone['zoneid'], $idZoneFirst);
     $this->assertEqual($aZone['zonename'], 'First Zone');
     $this->assertEqual($aZone['zonetype'], 3);
     // Now link the active banner to the second zone, and check
     // both zones are returned
     $doAdZone = OA_Dal::factoryDO('ad_zone_assoc');
     $doAdZone->ad_id = $idBannerActive;
     $doAdZone->zone_id = $idZoneSecond;
     $doAdZone->priority = 0;
     $doAdZone->link_type = 1;
     $doAdZone->priority_factor = 1;
     $doAdZone->to_be_delivered = 1;
     $idAdZone = DataGenerator::generateOne($doAdZone);
     $aResult = $oDal->getActiveZones();
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 2);
     $aZone = $aResult[0];
     $this->assertTrue(array_key_exists('zoneid', $aZone));
     $this->assertTrue(array_key_exists('zonename', $aZone));
     $this->assertTrue(array_key_exists('zonetype', $aZone));
     $this->assertEqual($aZone['zoneid'], $idZoneFirst);
     $this->assertEqual($aZone['zonename'], 'First Zone');
     $this->assertEqual($aZone['zonetype'], 3);
     $aZone = $aResult[1];
     $this->assertTrue(array_key_exists('zoneid', $aZone));
     $this->assertTrue(array_key_exists('zonename', $aZone));
     $this->assertTrue(array_key_exists('zonetype', $aZone));
     $this->assertEqual($aZone['zoneid'], $idZoneSecond);
     $this->assertEqual($aZone['zonename'], 'Second Zone');
     $this->assertEqual($aZone['zonetype'], 3);
     DataGenerator::cleanUp();
 }
Ejemplo n.º 17
0
 /**
  * A method to set details of the placement's delivery statistics
  * for "today" only, from the data stored in the database.
  *
  * @param string $today A string representing today's date in
  *                      "YYYY-MM-DD" format.
  */
 function setSummaryStatisticsToday($today)
 {
     $aStats = $this->oMaxDalMaintenancePriority->getCampaignStats($this->id, true, $today);
     $this->deliveredRequests = (int) $aStats['sum_requests'];
     $this->deliveredImpressions = (int) $aStats['sum_views'];
     $this->deliveredClicks = (int) $aStats['sum_clicks'];
     $this->deliveredConversions = (int) $aStats['sum_conversions'];
 }
 /**
  * Method to test the getCampaignDeliveryToDate 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.
  *
  * @TODO Incomplete test!
  */
 function testGetCampaignDeliveryToDate()
 {
     /**
      * @TODO Locate where clean up doesn't happen before this test, and fix!
      */
     TestEnv::restoreEnv();
     $conf = $GLOBALS['_MAX']['CONF'];
     $oDbh =& OA_DB::singleton();
     $oMaxDalMaintenance = new OA_Dal_Maintenance_Priority();
     $oNow = new Date();
     // Test 1
     $result = $oMaxDalMaintenance->getCampaignDeliveryToDate(1);
     $this->assertTrue(is_array($result));
     $this->assertEqual(count($result), 0);
     $doCampaigns = OA_Dal::factoryDO('campaigns');
     $doCampaigns->activate_time = '2005-06-23 00:00:00';
     $doCampaigns->expire_time = '2005-06-25 23:59:59';
     $doCampaigns->priority = '1';
     $doCampaigns->active = 1;
     $doCampaigns->views = 100;
     $doCampaigns->clicks = 200;
     $doCampaigns->conversions = 300;
     $doCampaigns->status = OA_ENTITY_STATUS_RUNNING;
     $doCampaigns->updated = $oNow->format('%Y-%m-%d %H:%M:%S');
     $idCampaign = DataGenerator::generateOne($doCampaigns, true);
     $doBanners = OA_Dal::factoryDO('banners');
     $doBanners->campaignid = $idCampaign;
     $doBanners->active = 1;
     $doBanners->status = OA_ENTITY_STATUS_RUNNING;
     $doBanners->acls_updated = $oNow->format('%Y-%m-%d %H:%M:%S');
     $doBanners->updated = $oNow->format('%Y-%m-%d %H:%M:%S');
     $idBanner = DataGenerator::generateOne($doBanners);
     $doInterAd = OA_Dal::factoryDO('data_intermediate_ad');
     $doInterAd->operation_interval = 60;
     $doInterAd->operation_interval_id = 0;
     $doInterAd->ad_id = $idBanner;
     $doInterAd->day = '2005-06-24';
     $doInterAd->creative_id = 0;
     $doInterAd->zone_id = 1;
     $doInterAd->requests = 500;
     $doInterAd->impressions = 475;
     $doInterAd->clicks = 25;
     $doInterAd->conversions = 5;
     $doInterAd->updated = $oNow->format('%Y-%m-%d %H:%M:%S');
     $doInterAd->interval_start = '2005-06-24 10:00:00';
     $doInterAd->interval_end = '2005-06-24 10:59:59';
     $doInterAd->hour = 10;
     $idInterAd = DataGenerator::generateOne($doInterAd);
     $doInterAd->interval_start = '2005-06-24 11:00:00';
     $doInterAd->interval_end = '2005-06-24 11:59:59';
     $doInterAd->hour = 11;
     $idInterAd = DataGenerator::generateOne($doInterAd);
     $result = $oMaxDalMaintenance->getCampaignDeliveryToDate(1);
     $this->assertTrue(is_array($result));
     $this->assertEqual(count($result), 1);
     $this->assertEqual($result[0]['placement_id'], 1);
     $this->assertEqual($result[0]['sum_requests'], 1000);
     $this->assertEqual($result[0]['sum_views'], 950);
     $this->assertEqual($result[0]['sum_clicks'], 50);
     $this->assertEqual($result[0]['sum_conversions'], 10);
     // Test 3
     DataGenerator::cleanUp();
 }
Ejemplo n.º 19
0
 /**
  * The method to run the Maintenance Priority Engine process.
  *
  * @static
  * @param boolean $alwaysRun Default value is false. If true, the Maintenance
  *                           Priority Engine process will always run, even if
  *                           instant priority updates have been disabled in the
  *                           configuration. Used to ensure that the maintenance
  *                           script process can always update priorities.
  * @return boolean True on MPE running correctly, false otherwise.
  */
 function run($alwaysRun = false)
 {
     OA::switchLogIdent('maintenance');
     // Get the configuration
     $aConf = $GLOBALS['_MAX']['CONF'];
     // Should the MPE process run?
     if (!$alwaysRun) {
         // Is instant update for priority set?
         if (!$aConf['priority']['instantUpdate']) {
             OA::debug('Instant update of priorities disabled, not running MPE', PEAR_LOG_INFO);
             return false;
         }
         OA::debug();
     }
     // Log the start of the process
     OA::debug('Running Maintenance Priority Engine', PEAR_LOG_INFO);
     // Set longer time out, and ignore user abort
     if (!ini_get('safe_mode')) {
         @set_time_limit($aConf['maintenance']['timeLimitScripts']);
         @ignore_user_abort(true);
     }
     // Attempt to increase PHP memory
     OX_increaseMemoryLimit(OX_getMinimumRequiredMemory('maintenance'));
     // Run the following code as the "Maintenance" user
     OA_Permission::switchToSystemProcessUser('Maintenance');
     // Create a Maintenance DAL object
     $oDal = new OA_Dal_Maintenance_Priority();
     // Try to get the MPE database-level lock
     $lock = $oDal->obtainPriorityLock();
     if (!$lock) {
         OA::debug('Unable to obtain database-level lock, not running MPE', PEAR_LOG_ERR);
         return false;
     }
     // Ensure the the current time is registered with the OA_ServiceLocator
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oDate =& $oServiceLocator->get('now');
     if (!$oDate) {
         // Record the current time, and register with the OA_ServiceLocator
         $oDate = new Date();
         $oServiceLocator->register('now', $oDate);
     }
     // Run the MPE process for the AdServer module
     require_once MAX_PATH . '/lib/OA/Maintenance/Priority/AdServer.php';
     $oMaintenancePriority = new OA_Maintenance_Priority_AdServer();
     // TODO: OA_Maintenance_Priority_AdServer::updatePriorities
     //       should be refactored to return a boolean we can check here.
     $oMaintenancePriority->updatePriorities();
     // Release the MPE database-level lock
     $result = $oDal->releasePriorityLock();
     if (PEAR::isError($result)) {
         // Unable to continue!
         OA::debug('Unable to release database-level lock', PEAR_LOG_ERR);
         return false;
     }
     // Return to the "normal" user
     OA_Permission::switchToSystemProcessUser();
     // Log the end of the process
     OA::debug('Maintenance Priority Engine Completed (Started at ' . $oDate->format('%Y-%m-%d %H:%M:%S') . ' ' . $oDate->tz->getShortName() . ')', PEAR_LOG_INFO);
     OA::switchLogIdent();
     return true;
 }
Ejemplo n.º 20
0
 function calculateEcpm()
 {
     if ($this->campaignid) {
         $oMaxDalMaintenance = new OA_Dal_Maintenance_Priority();
         $result = $oMaxDalMaintenance->getCampaignDeliveryToDate($this->campaignid);
         $requestsToDate = $result[0]['sum_requests'];
         $impressionsToDate = $result[0]['sum_views'];
         $clicksToDate = $result[0]['sum_clicks'];
         $conversionsToDate = $result[0]['sum_conversions'];
     } else {
         $requestsToDate = $impressionsToDate = $clicksToDate = $conversionsToDate = 0;
     }
     return OX_Util_Utils::getEcpm($this->revenue_type, $this->revenue, $impressionsToDate, $clicksToDate, $conversionsToDate, $this->activate_time, $this->expire_time);
 }
Ejemplo n.º 21
0
 /**
  * A method to get the delivery limitations of an advertisement
  * object from the database, and return them as an array.
  *
  * @return array An array of arrays, each representing a delivery
  *               limitation, for example:
  *               array(
  *                   [ad_id]             => 1
  *                   [logical]           => and
  *                   [type]              => Time:Hour
  *                   [comparison]        => ==
  *                   [data]              => 1,7,18,23
  *                   [executionorder]    => 1
  *               )
  */
 function getDeliveryLimitations()
 {
     return $this->oMaxDalMaintenancePriority->getAllDeliveryLimitationsByTypeId($this->id, 'ad');
 }
 /**
  * The method to test the getZonesForecasts() method.
  */
 function testgetZonesForecasts()
 {
     $this->_createTestData();
     $operationInterval = $GLOBALS['_MAX']['CONF']['maintenance']['operationInterval'];
     $oDal = new OA_Dal_Maintenance_Priority();
     $oLowerDate = new Date('2007-09-16 12:00:00');
     $oUpperDate = new Date('2007-09-16 17:00:00');
     $lowerDateStr = $oLowerDate->format(self::DATE_TIME_FORMAT);
     $upperDateStr = $oUpperDate->format(self::DATE_TIME_FORMAT);
     $weeks = 2;
     // Test with bad input
     $badAgencyId = -1;
     $result = $oDal->getZonesForecasts($lowerDateStr, $upperDateStr);
     $expected = array();
     $this->assertEqual($result, $expected);
     // Test with data outside the range
     $oDate = new Date('2007-09-16 11:00:00');
     $operationIntervalId = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
     $previousOIDate = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $startDateStr = $aDates['start']->format(self::DATE_TIME_FORMAT);
     $endDateStr = $aDates['end']->format(self::DATE_TIME_FORMAT);
     $doDIA = OA_Dal::factoryDO('data_intermediate_ad');
     $aDIAs = DataGenerator::generate($doDIA, 1);
     $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[0]);
     $doDIA->date_time = $startDateStr;
     $doDIA->operation_interval = $operationInterval;
     $doDIA->zone_id = $this->zoneId1;
     $doDIA->ad_id = 1;
     $doDIA->impressions = 1000;
     $doDIA->update();
     $result = $oDal->getZonesForecasts($startDateStr, $endDateStr);
     $expected = array();
     $this->assertEqual($result, $expected);
     // Test with data inside the range
     $oDate = new Date('2007-09-16 13:00:00');
     $operationIntervalId = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
     $previousOIDate = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $startDateStr = $aDates['start']->format(self::DATE_TIME_FORMAT);
     $endDateStr = $aDates['end']->format(self::DATE_TIME_FORMAT);
     $aDIAs = DataGenerator::generate($doDIA, 1);
     $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[0]);
     $doDIA->date_time = $previousOIDate['start']->format(self::DATE_TIME_FORMAT);
     $doDIA->operation_interval = $operationInterval;
     $doDIA->zone_id = $this->zoneId1;
     $doDIA->ad_id = 1;
     $doDIA->impressions = 70;
     $doDIA->update();
     $result = $oDal->getZonesForecasts($startDateStr, $endDateStr);
     $expected = array($this->zoneId1 => 70);
     $this->assertEqual($result, $expected);
     // Test with more data from the same zone
     $oDate = new Date('2007-09-16 14:00:00');
     $operationIntervalId = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
     $previousOIDate = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $startDateStr = $aDates['start']->format(self::DATE_TIME_FORMAT);
     $endDateStr = $aDates['end']->format(self::DATE_TIME_FORMAT);
     $aDIAs = DataGenerator::generate($doDIA, 3);
     $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[0]);
     $doDIA->date_time = $previousOIDate['start']->format(self::DATE_TIME_FORMAT);
     $doDIA->operation_interval = $operationInterval;
     $doDIA->zone_id = $this->zoneId1;
     $doDIA->ad_id = 2;
     $doDIA->impressions = 90;
     $doDIA->update();
     $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[1]);
     $doDIA->date_time = $previousOIDate['start']->format(self::DATE_TIME_FORMAT);
     $doDIA->operation_interval = $operationInterval;
     $doDIA->zone_id = $this->zoneId1;
     $doDIA->ad_id = 4;
     $doDIA->impressions = 110;
     $doDIA->update();
     $doDIA = OA_Dal::staticGetDO('data_intermediate_ad', $aDIAs[2]);
     $doDIA->date_time = $previousOIDate['start']->format(self::DATE_TIME_FORMAT);
     $doDIA->operation_interval = $operationInterval;
     $doDIA->zone_id = $this->zoneId2;
     $doDIA->ad_id = 4;
     $doDIA->impressions = 15000;
     $doDIA->update();
     $result = $oDal->getZonesForecasts($startDateStr, $endDateStr);
     $expected = array($this->zoneId1 => 200, $this->zoneId2 => 15000);
     $this->assertEqual($result, $expected);
     DataGenerator::cleanUp();
 }
 /**
  * Method to test the getAllDeliveryLimitationChangedCreatives method.
  *
  * Requirements:
  * Test 0: Test with bad input data, and ensure the method survives.
  * Test 1: Test with no data, and ensure no data are returned.
  * Test 2: Test with an active ad that has not had any delivery limitation changes,
  *         and ensure that no data are returned: DEPRECATED TEST, PostgreSQL DOES
  *         NOT PERMIT THE acls_update FIELD TO HAVE A NULL ENTRY.
  * Test 3: Test with an active ad that has had a delivery limitation change in the
  *         last OI, before the last Priority Compensation run, and ensure that no
  *         data are returned.
  * Test 4: Test with an active ad that has had a delivery limitation change in the
  *         last OI, after the last Priority Compensation run, and ensure that the
  *         correct data are returned.
  * Test 5: Test with an active ad that has had a delivery limitation change in the
  *         current OI, and ensure that the correct data are returned.
  * Test 6: Repeat test 3, but with an inactive ad.
  * Test 7: Repeat test 4, but with an inactive ad.
  * Test 8: Repeat test 5, but with an inactive ad.
  * Test 9: Test with a mixture of ads, and ensure the correct data are returned.
  */
 function testGetAllDeliveryLimitationChangedCreatives()
 {
     TestEnv::restoreEnv('dropTmpTables');
     $conf = $GLOBALS['_MAX']['CONF'];
     $oDbh =& OA_DB::singleton();
     $oMaxDalMaintenance = new OA_Dal_Maintenance_Priority();
     $oDateNow = new Date('2006-10-04 12:07:01');
     $oDateLastPC = new Date('2006-10-04 11:14:53');
     $aLastRun = array('start_run' => $oDateLastPC, 'now' => $oDateNow);
     // Test 0
     $aResult =& $oMaxDalMaintenance->getAllDeliveryLimitationChangedCreatives(array());
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 0);
     // Test 1
     $aResult =& $oMaxDalMaintenance->getAllDeliveryLimitationChangedCreatives($aLastRun);
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 0);
     // Test 3
     $doCampaigns = OA_Dal::factoryDO('campaigns');
     $doCampaigns->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S');
     $doCampaigns->priority = 1;
     $doCampaigns->status = OA_ENTITY_STATUS_RUNNING;
     $idCampaign = DataGenerator::generateOne($doCampaigns, true);
     $doBanners = OA_Dal::factoryDO('banners');
     $doBanners->campaignid = $idCampaign;
     $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S');
     $doBanners->status = OA_ENTITY_STATUS_RUNNING;
     $doBanners->acls_updated = '2006-10-04 11:10:00';
     $idBanner = DataGenerator::generateOne($doBanners);
     $aResult =& $oMaxDalMaintenance->getAllDeliveryLimitationChangedCreatives($aLastRun);
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 0);
     DataGenerator::cleanUp();
     // Test 4
     $doCampaigns = OA_Dal::factoryDO('campaigns');
     $doCampaigns->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S');
     $doCampaigns->priority = 1;
     $doCampaigns->status = OA_ENTITY_STATUS_RUNNING;
     $idCampaign = DataGenerator::generateOne($doCampaigns, true);
     $doBanners = OA_Dal::factoryDO('banners');
     $doBanners->campaignid = $idCampaign;
     $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S');
     $doBanners->status = OA_ENTITY_STATUS_RUNNING;
     $doBanners->acls_updated = '2006-10-04 11:15:00';
     $idBanner = DataGenerator::generateOne($doBanners);
     $aResult =& $oMaxDalMaintenance->getAllDeliveryLimitationChangedCreatives($aLastRun);
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 1);
     $this->assertEqual($aResult[$idBanner], '2006-10-04 11:15:00');
     DataGenerator::cleanUp();
     // Test 5
     $doCampaigns = OA_Dal::factoryDO('campaigns');
     $doCampaigns->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S');
     $doCampaigns->priority = 1;
     $doCampaigns->status = OA_ENTITY_STATUS_RUNNING;
     $idCampaign = DataGenerator::generateOne($doCampaigns, true);
     $doBanners = OA_Dal::factoryDO('banners');
     $doBanners->campaignid = $idCampaign;
     $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S');
     $doBanners->status = OA_ENTITY_STATUS_RUNNING;
     $doBanners->acls_updated = '2006-10-04 12:15:00';
     $idBanner = DataGenerator::generateOne($doBanners);
     $aResult =& $oMaxDalMaintenance->getAllDeliveryLimitationChangedCreatives($aLastRun);
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 1);
     $this->assertEqual($aResult[$idBanner], '2006-10-04 12:15:00');
     DataGenerator::cleanUp();
     // Test 6
     $doCampaigns = OA_Dal::factoryDO('campaigns');
     $doCampaigns->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S');
     $doCampaigns->priority = 1;
     $doCampaigns->status = OA_ENTITY_STATUS_RUNNING;
     $idCampaign = DataGenerator::generateOne($doCampaigns, true);
     $doBanners = OA_Dal::factoryDO('banners');
     $doBanners->campaignid = $idCampaign;
     $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S');
     $doBanners->status = OA_ENTITY_STATUS_RUNNING;
     $doBanners->acls_updated = '2006-10-04 11:10:00';
     $idBanner = DataGenerator::generateOne($doBanners);
     $aResult =& $oMaxDalMaintenance->getAllDeliveryLimitationChangedCreatives($aLastRun);
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 0);
     DataGenerator::cleanUp();
     // Test 7
     $doCampaigns = OA_Dal::factoryDO('campaigns');
     $doCampaigns->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S');
     $doCampaigns->priority = 1;
     $doCampaigns->activate_time = '2020-01-01 00:00:00';
     $doCampaigns->status = OA_ENTITY_STATUS_AWAITING;
     $idCampaign = DataGenerator::generateOne($doCampaigns, true);
     $doBanners = OA_Dal::factoryDO('banners');
     $doBanners->campaignid = $idCampaign;
     $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S');
     $doBanners->status = OA_ENTITY_STATUS_RUNNING;
     $doBanners->acls_updated = '2006-10-04 11:15:00';
     $idBanner = DataGenerator::generateOne($doBanners);
     $aResult =& $oMaxDalMaintenance->getAllDeliveryLimitationChangedCreatives($aLastRun);
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 0);
     DataGenerator::cleanUp();
     // Test 8
     $doCampaigns = OA_Dal::factoryDO('campaigns');
     $doCampaigns->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S');
     $doCampaigns->priority = 1;
     $doCampaigns->activate_time = '2020-01-01 00:00:00';
     $doCampaigns->status = OA_ENTITY_STATUS_AWAITING;
     $idCampaign = DataGenerator::generateOne($doCampaigns, true);
     $doBanners = OA_Dal::factoryDO('banners');
     $doBanners->campaignid = $idCampaign;
     $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S');
     $doBanners->status = OA_ENTITY_STATUS_AWAITING;
     $doBanners->acls_updated = '2006-10-04 12:15:00';
     $idBanner = DataGenerator::generateOne($doBanners);
     $aResult =& $oMaxDalMaintenance->getAllDeliveryLimitationChangedCreatives($aLastRun);
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 0);
     DataGenerator::cleanUp();
     // Test 9
     $doCampaigns = OA_Dal::factoryDO('campaigns');
     $doCampaigns->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S');
     $doCampaigns->priority = 1;
     $doCampaigns->status = OA_ENTITY_STATUS_RUNNING;
     $aIdCampaignsActive = DataGenerator::generate($doCampaigns, 2, true);
     $doCampaigns->activate_time = '2020-01-01 00:00:00';
     $doCampaigns->status = OA_ENTITY_STATUS_AWAITING;
     $idCampaignInactive = DataGenerator::generateOne($doCampaigns, true);
     $doBanners = OA_Dal::factoryDO('banners');
     $doBanners->campaignid = $aIdCampaignsActive[0];
     $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S');
     $doBanners->status = OA_ENTITY_STATUS_RUNNING;
     $doBanners->acls_updated = '2006-10-04 11:30:00';
     $idBanner1 = DataGenerator::generateOne($doBanners);
     $doBanners->campaignid = $aIdCampaignsActive[0];
     $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S');
     $doBanners->status = OA_ENTITY_STATUS_RUNNING;
     $doBanners->acls_updated = '2006-10-04 10:15:00';
     $idBanner2 = DataGenerator::generateOne($doBanners);
     $doBanners->campaignid = $aIdCampaignsActive[1];
     $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S');
     $doBanners->status = OA_ENTITY_STATUS_AWAITING;
     $doBanners->acls_updated = '2006-10-04 12:06:00';
     $idBanner3 = DataGenerator::generateOne($doBanners);
     $doBanners->campaignid = $aIdCampaignsActive[1];
     $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S');
     $doBanners->status = OA_ENTITY_STATUS_RUNNING;
     $doBanners->acls_updated = '2006-10-04 12:15:00';
     $idBanner4 = DataGenerator::generateOne($doBanners);
     $doBanners->campaignid = $idCampaignInactive;
     $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S');
     $doBanners->status = OA_ENTITY_STATUS_RUNNING;
     $doBanners->acls_updated = '2006-10-04 12:05:00';
     $idBanner5 = DataGenerator::generateOne($doBanners);
     $doBanners->campaignid = $idCampaignInactive;
     $doBanners->updated = $oDateNow->format('%Y-%m-%d %H:%M:%S');
     $doBanners->status = OA_ENTITY_STATUS_RUNNING;
     $doBanners->acls_updated = '2006-10-04 12:01:00';
     $idBanner5 = DataGenerator::generateOne($doBanners);
     $aResult =& $oMaxDalMaintenance->getAllDeliveryLimitationChangedCreatives($aLastRun);
     $this->assertTrue(is_array($aResult));
     $this->assertEqual(count($aResult), 2);
     $this->assertEqual($aResult[$idBanner1], '2006-10-04 11:30:00');
     $this->assertEqual($aResult[$idBanner4], '2006-10-04 12:15:00');
     DataGenerator::cleanUp();
 }
 /**
  * Method to test the getZonesForecastsForAllZones method.
  *
  * Requirements:
  * Test 1: Test with no Date registered in the service locator, ensure false returned.
  * Test 2: Test with a Date registered in the service locator, no data in the database,
  *         and ensure no data is returned.
  * Test 3: Test with forecast data but no actual impressions
  * Test 3.5: Test with actual data but no forecast impressions
  * Test 4: Test with data both in, and not in, the current OI, and ensure the correct
  *         data is returned.
  * Test 5: Repeat Test 4, but with additional zones (that don't have data) in the zones
  *         table.
  */
 function testGetAllZonesImpInv()
 {
     $conf = $GLOBALS['_MAX']['CONF'];
     $oDbh =& OA_DB::singleton();
     $oMaxDalMaintenance = new OA_Dal_Maintenance_Priority();
     $zoneForecastDefaultZoneImpressions = 0;
     // $oMaxDalMaintenance->getZoneForecastDefaultZoneImpressions();
     // Test 1
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oServiceLocator->remove('now');
     $result =& $oMaxDalMaintenance->getZonesForecastsForAllZones();
     $this->assertFalse($result);
     // Test 2
     $oDate = new Date();
     $oServiceLocator->register('now', $oDate);
     $result =& $oMaxDalMaintenance->getZonesForecastsForAllZones();
     $this->assertEqual($result, array(0 => $zoneForecastDefaultZoneImpressions));
     // Zone 0
     // Test 3
     // generate the first zone
     $aZones = $this->_generateTestZones(1);
     //         only generate previous OI delivered impressions, should return zone 0 only
     $oDate =& $oServiceLocator->get('now');
     $oNewDate = new Date();
     $oNewDate->copy($oDate);
     $oNewDate->subtractSeconds($conf['maintenance']['operationInterval'] * 60 + 1);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oNewDate);
     $this->_generateTestHistory(1, $aDates, 42, 0);
     $result =& $oMaxDalMaintenance->getZonesForecastsForAllZones();
     $expected = array(0 => $zoneForecastDefaultZoneImpressions, 1 => $zoneForecastDefaultZoneImpressions);
     $this->assertEqual($result, $expected);
     // Test 3.5
     // generate the second zone
     $aZones = $this->_generateTestZones(1);
     //     only generate previous OI forecasted impressions, should return zone 0 only
     $oNewDate = new Date();
     $oNewDate->copy($aDates['start']);
     $oNewDate->subtractSeconds(1);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oNewDate);
     $this->_generateTestHistory(2, $aDates, 0, 37);
     $result =& $oMaxDalMaintenance->getZonesForecastsForAllZones();
     $expected = array(0 => $zoneForecastDefaultZoneImpressions, 1 => $zoneForecastDefaultZoneImpressions, 2 => $zoneForecastDefaultZoneImpressions);
     $this->assertEqual($result, $expected);
     $oDate =& $oServiceLocator->get('now');
     DataGenerator::cleanUp();
     $oServiceLocator->register('now', $oDate);
     // Test 4
     $oDate =& $oServiceLocator->get('now');
     // generate three zone
     $this->_generateTestZones(3);
     // set forecast and impressions for OI - 1
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
     $this->_generateTestHistory(1, $aDates, 42, 100);
     $this->_generateTestHistory(2, $aDates, 5, 2);
     $this->_generateTestHistory(3, $aDates, 9999, 9999);
     $result =& $oMaxDalMaintenance->getZonesForecastsForAllZones();
     $expected = array(0 => $zoneForecastDefaultZoneImpressions, 1 => 42, 2 => 5, 3 => 9999);
     $this->assertEqual($result, $expected);
     // Test 5
     // New zone must appear in the array with default forecast
     $aZones = $this->_generateTestZones(1);
     $result =& $oMaxDalMaintenance->getZonesForecastsForAllZones();
     $expected = array(0 => $zoneForecastDefaultZoneImpressions, 1 => 42, 2 => 5, 3 => 9999, 4 => $zoneForecastDefaultZoneImpressions);
     $result =& $oMaxDalMaintenance->getZonesForecastsForAllZones();
     $this->assertEqual($result, $expected);
     // register forecast for the OI before, this should not affect current OI forecast
     $oDate =& $oServiceLocator->get('now');
     $aDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oDate);
     $currentOpIntID = OX_OperationInterval::convertDateToOperationIntervalID($aDates['start']);
     $this->_generateTestHistory(1, $aDates, 3700, 0);
     $this->_generateTestHistory(2, $aDates, 300, 0);
     $this->_generateTestHistory(3, $aDates, 500, 0);
     $result =& $oMaxDalMaintenance->getZonesForecastsForAllZones();
     $this->assertEqual($result, $expected);
     DataGenerator::cleanUp();
 }
 /**
  * Method to test the updatePriorities method.
  *
  * Test 1: Test with no Date registered in the service locator, ensure false returned.
  * Test 2: Test with no data in the database, ensure data is correctly stored.
  * Test 3: Test with previous test data in the database, ensure data is correctly stored.
  * Test 4: Test with an obscene number of items, and ensure that the packet size is
  *         not exceeded (no asserts, test suite will simply fail if unable to work).
  */
 function testUpdatePriorities()
 {
     /**
      * @TODO Locate where clean up doesn't happen before this test, and fix!
      */
     TestEnv::restoreEnv();
     $conf = $GLOBALS['_MAX']['CONF'];
     $oDbh =& OA_DB::singleton();
     $oMaxDalMaintenance = new OA_Dal_Maintenance_Priority();
     // Insert the data into the ad_zone_assoc table, as an ad is linked to a zone
     $this->_generateTestData();
     // Test 1
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oServiceLocator->remove('now');
     $aData = array(array('ads' => array(array('ad_id' => $this->aIds['ad'], 'zone_id' => $this->aIds['zone'], 'required_impressions' => '1000', 'requested_impressions' => '1000', 'priority' => '0.45', 'priority_factor' => null, 'priority_factor_limited' => false, 'past_zone_traffic_fraction' => null))));
     $result = $oMaxDalMaintenance->updatePriorities($aData);
     $this->assertFalse($result);
     // Test 2
     $oDate = new Date();
     $oServiceLocator->register('now', $oDate);
     $result = $oMaxDalMaintenance->updatePriorities($aData);
     $this->assertTrue($result);
     $query = "\n            SELECT\n                ad_id,\n                zone_id,\n                priority\n            FROM\n                " . $oDbh->quoteIdentifier($conf['table']['prefix'] . $conf['table']['ad_zone_assoc'], true) . "\n            WHERE\n                ad_id = {$this->aIds['ad']} AND zone_id = {$this->aIds['zone']}";
     $rc = $oDbh->query($query);
     $aRow = $rc->fetchRow();
     $this->assertEqual($aRow['ad_id'], $this->aIds['ad']);
     $this->assertEqual($aRow['zone_id'], $this->aIds['zone']);
     $this->assertEqual($aRow['priority'], 0.45);
     $query = "\n            SELECT\n                operation_interval,\n                operation_interval_id,\n                interval_start,\n                interval_end,\n                ad_id,\n                zone_id,\n                required_impressions,\n                requested_impressions,\n                priority,\n                priority_factor,\n                priority_factor_limited,\n                past_zone_traffic_fraction,\n                created,\n                created_by,\n                expired,\n                expired_by\n            FROM\n                " . $oDbh->quoteIdentifier($conf['table']['prefix'] . $conf['table']['data_summary_ad_zone_assoc'], true) . "\n            WHERE\n                ad_id = {$this->aIds['ad']}";
     $rc = $oDbh->query($query);
     $aRow = $rc->fetchRow();
     $currentOperationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
     $this->assertEqual($aRow['operation_interval'], $conf['maintenance']['operationInterval']);
     $this->assertEqual($aRow['operation_interval_id'], $currentOperationIntervalID);
     $this->assertEqual($aRow['interval_start'], $aDates['start']->format('%Y-%m-%d %H:%M:%S'));
     $this->assertEqual($aRow['interval_end'], $aDates['end']->format('%Y-%m-%d %H:%M:%S'));
     $this->assertEqual($aRow['ad_id'], $this->aIds['ad']);
     $this->assertEqual($aRow['zone_id'], $this->aIds['zone']);
     $this->assertEqual($aRow['required_impressions'], 1000);
     $this->assertEqual($aRow['requested_impressions'], 1000);
     $this->assertEqual($aRow['priority'], 0.45);
     $this->assertNull($aRow['priority_factor']);
     $this->assertFalse($aRow['priority_factor_limited']);
     $this->assertNull($aRow['past_zone_traffic_fraction']);
     $this->assertEqual($aRow['created'], $oDate->format('%Y-%m-%d %H:%M:%S'));
     $this->assertEqual($aRow['created_by'], 0);
     $this->assertNull($aRow['expired']);
     $this->assertNull($aRow['expired_by']);
     // Test 3
     $aData = array(array('ads' => array(array('ad_id' => $this->aIds['ad'], 'zone_id' => $this->aIds['zone'], 'required_impressions' => 2000, 'requested_impressions' => 2000, 'priority' => 0.9, 'priority_factor' => 0.1, 'priority_factor_limited' => false, 'past_zone_traffic_fraction' => 0.99), array('ad_id' => $this->aIds['ad'] + 1, 'zone_id' => $this->aIds['ad'] + 1, 'required_impressions' => 500, 'requested_impressions' => 500, 'priority' => 0.1, 'priority_factor' => 0.2, 'priority_factor_limited' => true, 'past_zone_traffic_fraction' => 0.45))));
     $oOldDate = new Date();
     $oOldDate->copy($oDate);
     $oDate = new Date();
     $oServiceLocator->register('now', $oDate);
     $result = $oMaxDalMaintenance->updatePriorities($aData);
     $this->assertTrue($result);
     $query = "\n            SELECT\n                ad_id,\n                zone_id,\n                priority\n            FROM\n                " . $oDbh->quoteIdentifier($conf['table']['prefix'] . $conf['table']['ad_zone_assoc'], true) . "\n            WHERE\n                ad_id = {$this->aIds['ad']} AND zone_id = {$this->aIds['zone']}";
     $rc = $oDbh->query($query);
     $aRow = $rc->fetchRow();
     $this->assertEqual($aRow['ad_id'], $this->aIds['ad']);
     $this->assertEqual($aRow['zone_id'], $this->aIds['zone']);
     $this->assertEqual($aRow['priority'], 0.9);
     $query = "\n            SELECT\n                operation_interval,\n                operation_interval_id,\n                interval_start,\n                interval_end,\n                ad_id,\n                zone_id,\n                required_impressions,\n                requested_impressions,\n                priority,\n                priority_factor,\n                priority_factor_limited,\n                past_zone_traffic_fraction,\n                created,\n                created_by,\n                expired,\n                expired_by\n            FROM\n                " . $oDbh->quoteIdentifier($conf['table']['prefix'] . $conf['table']['data_summary_ad_zone_assoc'], true) . "\n            WHERE\n                ad_id = {$this->aIds['ad']}\n                AND expired IS NOT NULL";
     $rc = $oDbh->query($query);
     $aRow = $rc->fetchRow();
     $currentOperationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oOldDate);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oOldDate);
     $this->assertEqual($aRow['operation_interval'], $conf['maintenance']['operationInterval']);
     $this->assertEqual($aRow['operation_interval_id'], $currentOperationIntervalID);
     $this->assertEqual($aRow['interval_start'], $aDates['start']->format('%Y-%m-%d %H:%M:%S'));
     $this->assertEqual($aRow['interval_end'], $aDates['end']->format('%Y-%m-%d %H:%M:%S'));
     $this->assertEqual($aRow['ad_id'], $this->aIds['ad']);
     $this->assertEqual($aRow['zone_id'], $this->aIds['ad']);
     $this->assertEqual($aRow['required_impressions'], 1000);
     $this->assertEqual($aRow['requested_impressions'], 1000);
     $this->assertEqual($aRow['priority'], 0.45);
     $this->assertNull($aRow['priority_factor']);
     $this->assertFalse($aRow['priority_factor_limited']);
     $this->assertNull($aRow['past_zone_traffic_fraction']);
     $this->assertEqual($aRow['created'], $oOldDate->format('%Y-%m-%d %H:%M:%S'));
     $this->assertEqual($aRow['created_by'], 0);
     $this->assertEqual($aRow['expired'], $oDate->format('%Y-%m-%d %H:%M:%S'));
     $this->assertEqual($aRow['expired_by'], 0);
     $query = "\n            SELECT\n                operation_interval,\n                operation_interval_id,\n                interval_start,\n                interval_end,\n                ad_id,\n                zone_id,\n                required_impressions,\n                requested_impressions,\n                priority,\n                priority_factor,\n                priority_factor_limited,\n                past_zone_traffic_fraction,\n                created,\n                created_by,\n                expired,\n                expired_by\n            FROM\n                " . $oDbh->quoteIdentifier($conf['table']['prefix'] . $conf['table']['data_summary_ad_zone_assoc'], true) . "\n            WHERE\n                ad_id = {$this->aIds['ad']}\n                AND expired IS NULL";
     $rc = $oDbh->query($query);
     $aRow = $rc->fetchRow();
     $currentOperationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
     $this->assertEqual($aRow['operation_interval'], $conf['maintenance']['operationInterval']);
     $this->assertEqual($aRow['operation_interval_id'], $currentOperationIntervalID);
     $this->assertEqual($aRow['interval_start'], $aDates['start']->format('%Y-%m-%d %H:%M:%S'));
     $this->assertEqual($aRow['interval_end'], $aDates['end']->format('%Y-%m-%d %H:%M:%S'));
     $this->assertEqual($aRow['ad_id'], $this->aIds['ad']);
     $this->assertEqual($aRow['zone_id'], $this->aIds['ad']);
     $this->assertEqual($aRow['required_impressions'], 2000);
     $this->assertEqual($aRow['requested_impressions'], 2000);
     $this->assertEqual($aRow['priority'], 0.9);
     $this->assertEqual($aRow['priority_factor'], 0.1);
     $this->assertFalse($aRow['priority_factor_limited']);
     $this->assertEqual($aRow['past_zone_traffic_fraction'], 0.99);
     $this->assertEqual($aRow['created'], $oDate->format('%Y-%m-%d %H:%M:%S'));
     $this->assertEqual($aRow['created_by'], 0);
     $this->assertNull($aRow['expired']);
     $this->assertNull($aRow['expired_by']);
     $query = "\n            SELECT\n                operation_interval,\n                operation_interval_id,\n                interval_start,\n                interval_end,\n                ad_id,\n                zone_id,\n                required_impressions,\n                requested_impressions,\n                priority,\n                priority_factor,\n                priority_factor_limited,\n                past_zone_traffic_fraction,\n                created,\n                created_by,\n                expired,\n                expired_by\n            FROM\n                " . $oDbh->quoteIdentifier($conf['table']['prefix'] . $conf['table']['data_summary_ad_zone_assoc'], true) . "\n            WHERE\n                ad_id = " . ($this->aIds['ad'] + 1);
     $rc = $oDbh->query($query);
     $aRow = $rc->fetchRow();
     $currentOperationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($oDate);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
     $this->assertEqual($aRow['operation_interval'], $conf['maintenance']['operationInterval']);
     $this->assertEqual($aRow['operation_interval_id'], $currentOperationIntervalID);
     $this->assertEqual($aRow['interval_start'], $aDates['start']->format('%Y-%m-%d %H:%M:%S'));
     $this->assertEqual($aRow['interval_end'], $aDates['end']->format('%Y-%m-%d %H:%M:%S'));
     $this->assertEqual($aRow['ad_id'], $this->aIds['ad'] + 1);
     $this->assertEqual($aRow['zone_id'], $this->aIds['ad'] + 1);
     $this->assertEqual($aRow['required_impressions'], 500);
     $this->assertEqual($aRow['requested_impressions'], 500);
     $this->assertEqual($aRow['priority'], 0.1);
     $this->assertEqual($aRow['priority_factor'], 0.2);
     $this->assertTrue($aRow['priority_factor_limited']);
     $this->assertEqual($aRow['past_zone_traffic_fraction'], 0.45);
     $this->assertEqual($aRow['created'], $oDate->format('%Y-%m-%d %H:%M:%S'));
     $this->assertEqual($aRow['created_by'], 0);
     $this->assertNull($aRow['expired']);
     $this->assertNull($aRow['expired_by']);
     // Test 4
     $aData = array();
     for ($i = 1; $i < 5000; $i++) {
         $aData[$i] = array('ads' => array(array('ad_id' => $i, 'zone_id' => $i, 'required_impressions' => 2000, 'requested_impressions' => 2000, 'priority' => 0.9, 'priority_factor' => 0.1, 'priority_factor_limited' => false, 'past_zone_traffic_fraction' => 0.99)));
     }
     $oOldDate = new Date();
     $oOldDate->copy($oDate);
     $oDate = new Date();
     $oServiceLocator->register('now', $oDate);
     $result = $oMaxDalMaintenance->updatePriorities($aData);
     TestEnv::restoreEnv('dropTmpTables');
 }