/**
  * Method to prepare user connected to manager account
  *
  */
 function _prepareTestData()
 {
     $doAgency = OA_DAL::factoryDO('agency');
     $this->agencyId = DataGenerator::generateOne($doAgency);
     $doAgency = OA_Dal::staticGetDO('agency', $this->agencyId);
     $this->accountId = $doAgency->account_id;
     $doUsers = OA_Dal::factoryDO('users');
     $doUsers->default_account_id = $this->accountId;
     $doUsers->username = '******';
     $this->userId = DataGenerator::generateOne($doUsers);
 }
Exemple #2
0
 /**
  * A method to duplicate an existing row
  *
  * Example use:
  *     $doBanners = OA_Dal::staticDuplicate('banners', 12, 1);
  *
  * @static
  * @param string $table The name of the table for which a DB_DataObject is required.
  * @param int $origId   The id of the row to copy
  * @param int $newId    The id to be assigned as the id of the row copied (optional)
  * @return mixed        Returns the restults returned from the duplicate method
  */
 function staticDuplicate($table, $origId, $newId = null)
 {
     OA_DAL::_setupDataObjectOptions();
     $do = OA_Dal::factoryDO($table);
     if (PEAR::isError($do)) {
         return false;
     }
     if (!($result = $do->duplicate($origId, $newId))) {
         return false;
     }
     return $result;
 }
 /**
  * A method to test the sending of emails from the
  * manageCampaigns() method - tests the sending of
  * the "campaign deactivated" emails.
  */
 function testManageCampaignsEmailsPlacementDeactivated()
 {
     // Prepare a single placement that is active, and has a lifetime
     // impression target that has been met (so that it will need to
     // be deactivated)
     $aData = array('contact' => 'Test Placement Deactivated Contact', 'email' => '*****@*****.**', 'reportdeactivate' => 't', 'report' => 't');
     $advertiserId = $this->_insertAdvertiser($aData);
     $aAdvertiser = OA_DAL::staticGetDO('clients', $advertiserId)->toArray();
     $aData = array('status' => OA_ENTITY_STATUS_RUNNING, 'views' => '100');
     $campaignId = $this->_insertPlacement($aData);
     $aData = array('campaignid' => $campaignId);
     $adId = $this->_insertAd($aData);
     $aData = array('operation_interval_id' => 25, 'interval_start' => '2005-12-08 00:00:00', 'interval_end' => '2004-12-08 00:59:59', 'hour' => 0, 'ad_id' => 1, 'impressions' => 101);
     $this->_insertDataIntermediateAd($aData);
     // Create an instance of the mocked OA_Email class, and set
     // expectations on how the class' methods should be called
     // based on the above
     Mock::generate('OA_Email');
     $oEmailMock = new MockOA_Email($this);
     $oEmailMock->expectOnce('sendCampaignActivatedDeactivatedEmail', array("{$campaignId}", 2));
     // This is the date that is going to be used later
     $oDate = new Date();
     $oEnd = new Date($oDate);
     $oEnd->addSpan(new Date_Span('1-0-0-0'));
     $oEmailMock->expectOnce('sendCampaignDeliveryEmail', array($aAdvertiser, new Date($aAdvertiser['reportlastdate']), $oEnd, "{$campaignId}"));
     // Register the mocked OA_Email class in the service locator
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oServiceLocator->register('OA_Email', $oEmailMock);
     // Run the manageCampaigns() method and ensure that the correct
     // calls to OA_Email were made
     $oFactory = new OX_Dal_Maintenance_Statistics_Factory();
     $oDalMaintenanceStatistics = $oFactory->factory();
     $report = $oDalMaintenanceStatistics->manageCampaigns($oDate);
     $oEmailMock->tally();
     // Clean up
     DataGenerator::cleanUp();
 }
 function testGetZones()
 {
     $conf = $GLOBALS['_MAX']['CONF'];
     $dbh =& OA_DB::singleton();
     $ret = $this->newZone();
     $this->assertTrue(is_int($ret));
     $this->assertTrue($ret > 0);
     //  get zone record as control element
     $query = 'SELECT * FROM ' . $dbh->quoteIdentifier($conf['table']['prefix'] . 'zones', true) . ' WHERE zoneid = ' . $ret;
     $aZone1 = $dbh->queryRow($query);
     $this->assertTrue(is_array($aZone1));
     //  massage results so as to be comparable with Admin_DA::getZone()
     Admin_DA::_switch($aZone1, 'affiliateid', 'publisher_id');
     Admin_DA::_switch($aZone1, 'zonename', 'name');
     Admin_DA::_switch($aZone1, 'delivery', 'type');
     Admin_DA::_switch($aZone1, 'zoneid', 'zone_id');
     unset($aZone1['zonetype']);
     unset($aZone1['appendtype']);
     unset($aZone1['forceappend']);
     unset($aZone1['inventory_forecast_type']);
     unset($aZone1['height']);
     unset($aZone1['width']);
     unset($aZone1['updated']);
     unset($aZone1['block']);
     unset($aZone1['capping']);
     unset($aZone1['session_capping']);
     unset($aZone1['category']);
     unset($aZone1['rate']);
     unset($aZone1['pricing']);
     unset($aZone1['show_capped_no_cookie']);
     $aZone1 = array_filter($aZone1, 'strlen');
     $aZone2 = Admin_DA::getZones(array('zone_id' => $ret));
     /*
     Array
     (
         [80] => Array
             (
                 [zone_id] => 80
                 [publisher_id] => 508
                 [name] => toufreacli
                 [type] => 3
             )
     
     )
     */
     $this->assertTrue(is_array($aZone2[$ret]));
     $this->assertEqual($aZone1, $aZone2[$ret]);
     $zoneId = $this->newZone();
     $doZones = OA_DAL::staticGetDO('zones', $zoneId);
     $doZones->inventory_forecast_type = 5;
     $doZones->update();
     $aZone = Admin_DA::getZones(array('zone_inventory_forecast_type' => 1));
     $this->assertTrue($aZone);
     // The returned zone isn't null or false or empty.
 }
function MAX_AclCopy($page, $from, $to)
{
    $oDbh =& OA_DB::singleton();
    $conf =& $GLOBALS['_MAX']['CONF'];
    $table = modifyTableName('acls');
    switch ($page) {
        case 'channel-acl.php':
            echo "Not implemented";
            break;
        default:
            // Delete old limitations
            $query = "\n                DELETE FROM\n                      {$table}\n                WHERE\n                    bannerid = " . $oDbh->quote($to, 'integer');
            $res = $oDbh->exec($query);
            if (PEAR::isError($res)) {
                return $res;
            }
            // Copy ACLs
            $query = "\n                INSERT INTO {$table} (bannerid, logical, type, comparison, data, executionorder)\n                    SELECT\n                        " . $oDbh->quote($to, 'integer') . ", logical, type, comparison, data, executionorder\n                    FROM\n                        {$table}\n                    WHERE\n                        bannerid= " . $oDbh->quote($from, 'integer') . "\n                    ORDER BY executionorder\n            ";
            $res = $oDbh->exec($query);
            if (PEAR::isError($res)) {
                return $res;
            }
            // Copy compiledlimitation
            $doBannersFrom = OA_Dal::staticGetDO('banners', $from);
            $doBannersTo = OA_DAL::staticGetDO('banners', $to);
            $doBannersTo->compiledlimitation = $doBannersFrom->compiledlimitation;
            $doBannersTo->acl_plugins = $doBannersFrom->acl_plugins;
            $doBannersTo->block = $doBannersFrom->block;
            $doBannersTo->capping = $doBannersFrom->capping;
            $doBannersTo->session_capping = $doBannersFrom->session_capping;
            return $doBannersTo->update();
    }
}
 /**
  * A method to perform basic end-to-end integration testing of the Maintenance
  * Priority Engine classes for the Ad Server.
  *
  * Test 0: Test that no zone forecast or priority data exists to begin with.
  * Test 1: Run the MPE without any stats, and without the stats engine ever
  *         having been run before. Test that zone forecasts are updated
  *         with the appropriate values, and that the correct priorities are
  *         generated.
  * Test 2: Run the MPE without any stats, but with the stats engine having
  *         reported that it has run. Test that zone forecasts are updated
  *         with the appropriate values, and that the correct priorities are
  *         generated.
  * Test 3: Run the MPE again, as for Test 2, but with a later date used as
  *         for when the stats engine reported having run.
  */
 function testAdServer()
 {
     // Test 0: Ensure correct number of links in the ad_zone_assoc table
     $this->assertEqual($this->_azaRows(), 7);
     // 4 proper associations + 3 default with zone 0
     // Test 0: Ensure no links in the ad_zone_assoc table have priority > 0
     $this->assertEqual($this->_azaRows(true), 0);
     // Test 0: Ensure no links in the data_summary_ad_zone_assoc table have priority > 0
     $this->assertEqual($this->_dsazaRows(true), 0);
     // Test 0: Ensure no data in the log_maintenance_priority table
     $this->_assertLogMaintenance();
     // Test 1: Set "current" date for the MPE run
     $oDate = new Date('2005-06-15 13:01:01');
     $this->oServiceLocator->register('now', $oDate);
     // Test 1: Prepare the MPE object
     $oMaintenancePriority = new OA_Maintenance_Priority_AdServer();
     // Test 1: Store the date before the MPE runs
     $oTest1BeforeUpdateDate = new Date();
     sleep(1);
     // Ensure that next date is at least 1 second after above...
     // Test 1: Run the MPE
     $oMaintenancePriority->updatePriorities();
     // Test 1: Store the date after the MPE runs
     sleep(1);
     // Ensure that next date is at least 1 second after above...
     $oTest1AfterUpdateDate = new Date();
     // Test 1: Ensure correct number of links in the ad_zone_assoc table
     $this->assertEqual($this->_azaRows(), 7);
     // 4 proper associations + 3 default with zone 0
     // Test 1: Ensure correct number of links in the ad_zone_assoc table with priority > 0
     $this->assertEqual($this->_azaRows(true), 7);
     // Test 1: Ensure correct number of links in the data_summary_ad_zone_assoc table with priority >
     $this->assertEqual($this->_dsazaRows(true), 7);
     // Test 1: Ensure that the priorities in the ad_zone_assoc and data_summary_ad_zone_assoc
     // tables are set correctly
     $aTestOneZero = array();
     $aTestOneZero['ad_id'] = 1;
     $aTestOneZero['zone_id'] = 0;
     $aTestOneZero['priority'] = 11 / 200;
     // 200 is 10 (default forecast) / 0.05 (factor)
     $aTestOneZero['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestOneZero['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 11, 'requested_impressions' => 11, 'priority' => $aTestOneZero['priority'], 'priority_factor' => $aTestOneZero['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestOneZero);
     $aTestTwoZero = array();
     $aTestTwoZero['ad_id'] = 2;
     $aTestTwoZero['zone_id'] = 0;
     $aTestTwoZero['priority'] = 12 / 200;
     $aTestTwoZero['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestTwoZero['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 12, 'requested_impressions' => 12, 'priority' => $aTestTwoZero['priority'], 'priority_factor' => $aTestTwoZero['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestTwoZero);
     $aTestThreeZero = array();
     $aTestThreeZero['ad_id'] = 3;
     $aTestThreeZero['zone_id'] = 0;
     $aTestThreeZero['priority'] = 6 / 200;
     $aTestThreeZero['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestThreeZero['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 6, 'requested_impressions' => 6, 'priority' => $aTestThreeZero['priority'], 'priority_factor' => $aTestThreeZero['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestThreeZero);
     $aTestOneOne = array();
     $aTestOneOne['ad_id'] = 1;
     $aTestOneOne['zone_id'] = 1;
     $aTestOneOne['priority'] = 10 / 200;
     // Constant, only priority_factor increases
     $aTestOneOne['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestOneOne['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 11, 'requested_impressions' => 10, 'priority' => $aTestOneOne['priority'], 'priority_factor' => $aTestOneOne['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestOneOne);
     $aTestTwoThree = array();
     $aTestTwoThree['ad_id'] = 2;
     $aTestTwoThree['zone_id'] = 3;
     $aTestTwoThree['priority'] = 8 / 200;
     // Constant, only priority_factor increases
     $aTestTwoThree['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestTwoThree['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 12, 'requested_impressions' => 8, 'priority' => $aTestTwoThree['priority'], 'priority_factor' => $aTestTwoThree['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestTwoThree);
     $aTestThreeThree = array();
     $aTestThreeThree['ad_id'] = 3;
     $aTestThreeThree['zone_id'] = 3;
     $aTestThreeThree['priority'] = 2 / 200;
     // Constant, only priority_factor increases
     $aTestThreeThree['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestThreeThree['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 3, 'requested_impressions' => 2, 'priority' => $aTestThreeThree['priority'], 'priority_factor' => $aTestThreeThree['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestThreeThree);
     $aTestThreeFour = array();
     $aTestThreeFour['ad_id'] = 3;
     $aTestThreeFour['zone_id'] = 4;
     $aTestThreeFour['priority'] = 3 / 200;
     // Constant, only priority_factor increases
     $aTestThreeFour['priority_factor'] = 1;
     // Initial priority run, factor starts at 1
     $aTestThreeFour['history'][0] = array('operation_interval' => 60, 'operation_interval_id' => 85, 'interval_start' => '2005-06-15 13:00:00', 'interval_end' => '2005-06-15 13:59:59', 'required_impressions' => 3, 'requested_impressions' => 3, 'priority' => $aTestThreeFour['priority'], 'priority_factor' => $aTestThreeFour['priority_factor'], 'past_zone_traffic_fraction' => null);
     $this->_assertPriority($aTestThreeFour);
     // Test 1: Ensure that the values in the log_maintenance_priority table are correct
     $this->_assertLogMaintenance(2, $oTest1BeforeUpdateDate, $oTest1AfterUpdateDate, 60, DAL_PRIORITY_UPDATE_ECPM);
     // Insert data that indicates that the Maintenance Statistics Engine
     // has recently updated the available stats, but don't insert any
     // stats into the tables
     $this->oServiceLocator =& OA_ServiceLocator::instance();
     $startDate = new Date('2005-06-15 14:00:01');
     $this->oServiceLocator->register('now', $startDate);
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oMaintenanceStatistics->updateIntermediate = true;
     $oMaintenanceStatistics->updateFinal = true;
     $aOiDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($startDate);
     $oMaintenanceStatistics->oUpdateIntermediateToDate = $aOiDates['end'];
     $oMaintenanceStatistics->oUpdateFinalToDate = $aOiDates['end'];
     $this->oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     $oLogCompletion = new OX_Maintenance_Statistics_Task_LogCompletion();
     $oLogCompletion->run();
     // Test 2: Set "previous" date for the MPE run
     $oPreviousDate = new Date('2005-06-15 13:01:01');
     $previousOperationIntervalID = $currentOperationIntervalID;
     // Test 2: Set "current" date for the MPE run
     $oDate = new Date('2005-06-15 14:01:01');
     $this->oServiceLocator->register('now', $oDate);
     // Test 2: Prepare the MPE object
     $oMaintenancePriority = new OA_Maintenance_Priority_AdServer();
     // Test 2: Store the date before the MPE runs
     $oTest2BeforeUpdateDate = new Date();
     sleep(1);
     // Ensure that next date is at least 1 second after above...
     // Test 2: Run the MPE
     $oMaintenancePriority->updatePriorities();
     // Test 2: Store the date after the MPE runs
     sleep(1);
     // Ensure that next date is at least 1 second after above...
     $oTest2AfterUpdateDate = new Date();
     // Test 2: Ensure correct number of links in the ad_zone_assoc table
     $this->assertEqual($this->_azaRows(), 7);
     // 4 proper associations + 3 default with zone 0
     // Test 2: Ensure correct number of links in the ad_zone_assoc table with priority > 0
     $this->assertEqual($this->_azaRows(true), 7);
     // Test 2: Ensure correct number of links in the data_summary_ad_zone_assoc table with priority > 0
     $this->assertEqual($this->_dsazaRows(true), 14);
     // Test 2: Ensure that the priorities in the ad_zone_assoc and data_summary_ad_zone_assoc
     // tables are set correctly
     $aTestOneZero['priority'] = 12 / 200;
     $aTestOneZero['priority_factor'] = 1;
     // Remains at 1, no priority compensation in Zone ID 0
     $aTestOneZero['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 12, 'requested_impressions' => 12, 'priority' => $aTestOneZero['priority'], 'priority_factor' => $aTestOneZero['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestOneZero);
     $aTestTwoZero['priority'] = 12 / 200;
     $aTestTwoZero['priority_factor'] = 1;
     // Remains at 1, no priority compensation in Zone ID 0
     $aTestTwoZero['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 12, 'requested_impressions' => 12, 'priority' => $aTestTwoZero['priority'], 'priority_factor' => $aTestTwoZero['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestTwoZero);
     $aTestThreeZero['priority'] = 6 / 200;
     $aTestThreeZero['priority_factor'] = 1;
     // Remains at 1, no priority compensation in Zone ID 0
     $aTestThreeZero['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 6, 'requested_impressions' => 6, 'priority' => $aTestThreeZero['priority'], 'priority_factor' => $aTestThreeZero['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestThreeZero);
     $aTestOneOne['priority_factor'] = 1;
     // Remains at 1, zone was not active
     $aTestOneOne['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 12, 'requested_impressions' => 10, 'priority' => $aTestOneOne['priority'], 'priority_factor' => $aTestOneOne['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestOneOne);
     $aTestTwoThree['priority_factor'] = 1;
     // Remains at 1, zone was not active
     $aTestTwoThree['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 12, 'requested_impressions' => 8, 'priority' => $aTestTwoThree['priority'], 'priority_factor' => $aTestTwoThree['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestTwoThree);
     $aTestThreeThree['priority_factor'] = 1;
     // Remains at 1, zone was not active
     $aTestThreeThree['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 3, 'requested_impressions' => 2, 'priority' => $aTestThreeThree['priority'], 'priority_factor' => $aTestThreeThree['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestThreeThree);
     $aTestThreeFour['priority_factor'] = 1;
     // Remains at 1, zone was not active
     $aTestThreeFour['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 86, 'interval_start' => '2005-06-15 14:00:00', 'interval_end' => '2005-06-15 14:59:59', 'required_impressions' => 3, 'requested_impressions' => 3, 'priority' => $aTestThreeFour['priority'], 'priority_factor' => $aTestThreeFour['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestThreeFour);
     // Test 2: Ensure that the values in the log_maintenance_priority table are correct
     $this->_assertLogMaintenance(2, $oTest1BeforeUpdateDate, $oTest1AfterUpdateDate, 60, DAL_PRIORITY_UPDATE_ECPM);
     $this->_assertLogMaintenance(6, $oTest2BeforeUpdateDate, $oTest2AfterUpdateDate, 60, DAL_PRIORITY_UPDATE_ECPM);
     // Insert data that indicates that the Maintenance Statistics Engine
     // has recently updated the available stats
     $this->oServiceLocator =& OA_ServiceLocator::instance();
     $startDate = new Date('2005-06-19 00:00:01');
     $this->oServiceLocator->register('now', $startDate);
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oMaintenanceStatistics->updateIntermediate = true;
     $oMaintenanceStatistics->updateFinal = true;
     $aOiDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($startDate);
     $oMaintenanceStatistics->oUpdateIntermediateToDate = $aOiDates['end'];
     $oMaintenanceStatistics->oUpdateFinalToDate = $aOiDates['end'];
     $this->oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     $oLogCompletion = new OX_Maintenance_Statistics_Task_LogCompletion();
     $oLogCompletion->run();
     // Insert some stats for an ad zone combination
     $doDIA = OA_DAL::factoryDO('data_intermediate_ad');
     $doDIA->ad_id = 3;
     $doDIA->zone_id = 3;
     $doDIA->impressions = 20;
     $doDIA->date_time = $aOiDates['start']->getDate();
     $doDIA->interval_start = $aOiDates['start']->getDate();
     $doDIA->interval_end = $aOiDates['end']->getDate();
     $doDIA->operation_interval = 60;
     $doDIA->operation_interval_id = OX_OperationInterval::convertDateToOperationIntervalID($aOiDates['start']);
     $doDIA->insert();
     // Test 3: Set "current" date for the MPE run
     $oDate = new Date('2005-06-19 00:01:01');
     $this->oServiceLocator->register('now', $oDate);
     // Test 3: Prepare the MPE object
     $oMaintenancePriority = new OA_Maintenance_Priority_AdServer();
     // Test 3: Store the date before the MPE runs
     $oTest3BeforeUpdateDate = new Date();
     sleep(1);
     // Ensure that next date is at least 1 second after above...
     // Test 3: Run the MPE
     $oMaintenancePriority->updatePriorities();
     // Test 3: Store the date after the MPE runs
     sleep(1);
     // Ensure that next date is at least 1 second after above...
     $oTest3AfterUpdateDate = new Date();
     $oLastUpdatedTo1 = new Date('2005-06-15 14:00:00');
     $oNowUpdatedTo1 = new Date('2005-06-15 15:00:00');
     $oSpan = new Date_Span();
     $oLastUpdatedTo1Copy = new Date();
     $oLastUpdatedTo1Copy->copy($oLastUpdatedTo1);
     $oNowUpdatedTo1Copy = new Date();
     $oNowUpdatedTo1Copy->copy($oNowUpdatedTo1);
     $oSpan->setFromDateDiff($oLastUpdatedTo1Copy, $oNowUpdatedTo1Copy);
     $hours1 = $oSpan->toHours();
     $oLastUpdatedTo2 = new Date('2005-06-15 15:00:00');
     $oNowUpdatedTo2 = new Date('2005-06-19 01:00:00');
     $oSpan = new Date_Span();
     $oLastUpdatedTo2Copy = new Date();
     $oLastUpdatedTo2Copy->copy($oLastUpdatedTo2);
     $oNowUpdatedTo2Copy = new Date();
     $oNowUpdatedTo2Copy->copy($oNowUpdatedTo2);
     $oSpan->setFromDateDiff($oLastUpdatedTo2Copy, $oNowUpdatedTo2Copy);
     $hours2 = $oSpan->toHours();
     // Test 3: Ensure correct number of links in the ad_zone_assoc table
     $this->assertEqual($this->_azaRows(), 7);
     // 4 proper associations + 3 default with zone 0
     // Test 3: Ensure correct number of links in the ad_zone_assoc table with priority > 0
     $this->assertEqual($this->_azaRows(true), 7);
     // Test 3: Ensure correct number of links in the data_summary_ad_zone_assoc table with priority > 0
     $this->assertEqual($this->_dsazaRows(true), 21);
     // Test 3: Ensure that the priorities in the ad_zone_assoc and data_summary_ad_zone_assoc
     // tables are set correctly
     $aTestOneZero['priority'] = 5 / 200;
     $aTestOneZero['priority_factor'] = 1;
     // Remains at 1, no priority compensation in Zone ID 0
     $aTestOneZero['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 5, 'requested_impressions' => 5, 'priority' => $aTestOneZero['priority'], 'priority_factor' => $aTestOneZero['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestOneZero);
     $aTestTwoZero['priority'] = 12 / 200;
     $aTestTwoZero['priority_factor'] = 1;
     // Remains at 1, no priority compensation in Zone ID 0
     $aTestTwoZero['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 12, 'requested_impressions' => 12, 'priority' => $aTestTwoZero['priority'], 'priority_factor' => $aTestTwoZero['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestTwoZero);
     $aTestThreeZero['priority'] = 6 / 200;
     $aTestThreeZero['priority_factor'] = 1;
     // Remains at 1, no priority compensation in Zone ID 0
     $aTestThreeZero['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 6, 'requested_impressions' => 6, 'priority' => $aTestThreeZero['priority'], 'priority_factor' => $aTestThreeZero['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestThreeZero);
     $aTestOneOne['priority'] = 5 / 200;
     // Changed, skipped OIs
     $aTestOneOne['priority_factor'] = 1;
     // Remains at 1, zone was not active
     $aTestOneOne['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 5, 'requested_impressions' => 5, 'priority' => $aTestOneOne['priority'], 'priority_factor' => $aTestOneOne['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestOneOne);
     $aTestTwoThree['priority'] = 12 / 20;
     // Zone has had some impressions, we have a forecast now
     $aTestTwoThree['priority_factor'] = 10;
     // But this ad didn't deliver. Factor increased
     $aTestTwoThree['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 12, 'requested_impressions' => 12, 'priority' => $aTestTwoThree['priority'], 'priority_factor' => $aTestTwoThree['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestTwoThree);
     $aTestThreeThree['priority'] = 4 / 20;
     // Ad/Zone has delivered!
     $aTestThreeThree['priority_factor'] = 2 / 20;
     // Overdelivered quite a bit!
     $aTestThreeThree['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 4, 'requested_impressions' => 4, 'priority' => $aTestThreeThree['priority'], 'priority_factor' => $aTestThreeThree['priority_factor'], 'past_zone_traffic_fraction' => 1);
     $this->_assertPriority($aTestThreeThree);
     $aTestThreeFour['priority'] = 2 / 200;
     // Ad has delivered, but not in this zone
     $aTestThreeFour['priority_factor'] = 1;
     // Remains at 1, zone was not active
     $aTestThreeFour['history'][1] = array('operation_interval' => 60, 'operation_interval_id' => 0, 'interval_start' => '2005-06-19 00:00:00', 'interval_end' => '2005-06-19 00:59:59', 'required_impressions' => 2, 'requested_impressions' => 2, 'priority' => $aTestThreeFour['priority'], 'priority_factor' => $aTestThreeFour['priority_factor'], 'past_zone_traffic_fraction' => 0);
     $this->_assertPriority($aTestThreeFour);
     // Test 3: Ensure that the values in the log_maintenance_priority table are correct
     $this->_assertLogMaintenance(2, $oTest1BeforeUpdateDate, $oTest1AfterUpdateDate, 60, DAL_PRIORITY_UPDATE_ECPM);
     $this->_assertLogMaintenance(6, $oTest2BeforeUpdateDate, $oTest2AfterUpdateDate, 60, DAL_PRIORITY_UPDATE_ECPM);
 }