/**
  * A method to test the getAdLifetimeZoneImpressionsRemaining() method.
  *
  * Test 1: Test with invalid parameters, and ensure that zero is returned.
  * Test 2: Test with equal start and end dates, and ensure just that OI's
  *         data is returned.
  * Test 3: Test with a small range of dates in one week, that the correct
  *         sum is returned.
  * Test 4: Test with a small range of dates over three days, covering two
  *         weeks, and ensure that the correct result is returned.
  * Test 5: Test with a limitation that blocks less than 50% of the remaining
  *         range, and ensure that the correct result is returned.
  * Test 6: Test with a limitation that blocks more than 50% of the remaining
  *         range, and ensure that the correct result is returned.
  */
 function testGetAdLifetimeZoneImpressionsRemaining()
 {
     $aConf =& $GLOBALS['_MAX']['CONF'];
     $aConf['maintenance']['operationInterval'] = 60;
     $aDeliveryLimitations = array();
     $oDeliveryLimitationManager = new OA_Maintenance_Priority_DeliveryLimitation($aDeliveryLimitations);
     // Test 1
     $oDate = new Date('2006-02-15 11:07:15');
     $aCumulativeZoneForecast = array();
     $aCumulativeZoneForecast = $this->_fillForecastArray($aCumulativeZoneForecast);
     $result = $oDeliveryLimitationManager->getAdLifetimeZoneImpressionsRemaining('foo', $oDate, $aCumulativeZoneForecast);
     $this->assertEqual($result, 0);
     $result = $oDeliveryLimitationManager->getAdLifetimeZoneImpressionsRemaining($oDate, 'foo', $aCumulativeZoneForecast);
     $this->assertEqual($result, 0);
     $result = $oDeliveryLimitationManager->getAdLifetimeZoneImpressionsRemaining($oDate, $oDate, 'foo');
     $this->assertEqual($result, 0);
     // Test 2
     $oDate = new Date('2006-02-15 23:07:15');
     $aCumulativeZoneForecast = array();
     $aCumulativeZoneForecast = $this->_fillForecastArray($aCumulativeZoneForecast);
     $result = $oDeliveryLimitationManager->getAdLifetimeZoneImpressionsRemaining($oDate, $oDate, $aCumulativeZoneForecast);
     $this->assertEqual($result, 1);
     $aDates = OX_OperationInterval::convertDateToOperationIntervalStartAndEndDates($oDate);
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID($aDates['start']);
     $aCumulativeZoneForecast[$operationIntervalID] = 50;
     $previousOperationIntervalId = OX_OperationInterval::previousOperationIntervalID($operationIntervalID);
     $aCumulativeZoneForecast[$previousOperationIntervalId] = 5;
     $nextOperationIntervalId = OX_OperationInterval::nextOperationIntervalID($operationIntervalID);
     $aCumulativeZoneForecast[$nextOperationIntervalId] = 7;
     $aCumulativeZoneForecast = $this->_fillForecastArray($aCumulativeZoneForecast);
     $result = $oDeliveryLimitationManager->getAdLifetimeZoneImpressionsRemaining($oDate, $oDate, $aCumulativeZoneForecast);
     $this->assertEqual($result, 50);
     // Test 3
     $oStartDate = new Date('2006-02-15 11:07:15');
     $oEndDate = new Date('2006-02-15 23:59:59');
     $aCumulativeZoneForecast = array();
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-15 10:00:01'));
     $aCumulativeZoneForecast[$operationIntervalID] = 1;
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-15 11:00:01'));
     $aCumulativeZoneForecast[$operationIntervalID] = 10;
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-15 12:00:01'));
     $aCumulativeZoneForecast[$operationIntervalID] = 100;
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-15 13:00:01'));
     $aCumulativeZoneForecast[$operationIntervalID] = 1000;
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-15 14:00:01'));
     $aCumulativeZoneForecast[$operationIntervalID] = 10000;
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-15 15:00:01'));
     $aCumulativeZoneForecast[$operationIntervalID] = 100000;
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-15 16:00:01'));
     $aCumulativeZoneForecast[$operationIntervalID] = 1000000;
     $aCumulativeZoneForecast = $this->_fillForecastArray($aCumulativeZoneForecast);
     $result = $oDeliveryLimitationManager->getAdLifetimeZoneImpressionsRemaining($oStartDate, $oEndDate, $aCumulativeZoneForecast);
     $this->assertEqual($result, 1111110 + 7);
     // Test 4
     $oStartDate = new Date('2006-02-18 22:07:15');
     $oEndDate = new Date('2006-02-20 23:59:59');
     $aCumulativeZoneForecast = array();
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-18 21:00:01'));
     $aCumulativeZoneForecast[$operationIntervalID] = 1;
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-18 22:00:01'));
     $aCumulativeZoneForecast[$operationIntervalID] = 10;
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-18 23:00:01'));
     $aCumulativeZoneForecast[$operationIntervalID] = 100;
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-19 00:00:01'));
     $aCumulativeZoneForecast[$operationIntervalID] = 1000;
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-19 01:00:01'));
     $aCumulativeZoneForecast[$operationIntervalID] = 10000;
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-19 02:00:01'));
     $aCumulativeZoneForecast[$operationIntervalID] = 100000;
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-19 03:00:01'));
     $aCumulativeZoneForecast[$operationIntervalID] = 1000000;
     $operationIntervalID = OX_OperationInterval::convertDateToOperationIntervalID(new Date('2006-02-19 04:00:01'));
     $aCumulativeZoneForecast[$operationIntervalID] = 10000000;
     $aCumulativeZoneForecast = $this->_fillForecastArray($aCumulativeZoneForecast);
     $result = $oDeliveryLimitationManager->getAdLifetimeZoneImpressionsRemaining($oStartDate, $oEndDate, $aCumulativeZoneForecast);
     $this->assertEqual($result, 110 + 11111000 + 19 + 24);
     // Test 5
     $oStartDate = new Date('2006-02-07 12:07:15');
     $oEndDate = new Date('2006-02-07 23:59:59');
     $aDeliveryLimitations = array(array('ad_id' => 1, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Hour', 'comparison' => '!~', 'data' => '23', 'executionorder' => 0));
     $oDeliveryLimitationManager = new OA_Maintenance_Priority_DeliveryLimitation($aDeliveryLimitations);
     $oDeliveryLimitationManager->getActiveAdOperationIntervals(12, $oStartDate, $oEndDate);
     $aCumulativeZoneForecast = array();
     $aCumulativeZoneForecast = $this->_fillForecastArray($aCumulativeZoneForecast);
     $result = $oDeliveryLimitationManager->getAdLifetimeZoneImpressionsRemaining($oStartDate, $oEndDate, $aCumulativeZoneForecast);
     $this->assertEqual($result, 11);
     // Test 6
     $oStartDate = new Date('2006-02-07 12:07:15');
     $oEndDate = new Date('2006-02-08 23:59:59');
     $aDeliveryLimitations = array(array('ad_id' => 1, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Hour', 'comparison' => '=~', 'data' => '22', 'executionorder' => 0));
     $oDeliveryLimitationManager = new OA_Maintenance_Priority_DeliveryLimitation($aDeliveryLimitations);
     $oDeliveryLimitationManager->getActiveAdOperationIntervals(12, $oStartDate, $oEndDate);
     $aCumulativeZoneForecast = array();
     $aCumulativeZoneForecast = $this->_fillForecastArray($aCumulativeZoneForecast);
     $result = $oDeliveryLimitationManager->getAdLifetimeZoneImpressionsRemaining($oStartDate, $oEndDate, $aCumulativeZoneForecast);
     $this->assertEqual($result, 2);
     TestEnv::restoreConfig();
 }