/**
  * A method to test the deliveryBlocked() method.
  */
 function testDeliveryBlocked()
 {
     OA_setTimeZoneUTC();
     $aDeliveryLimitation = array('ad_id' => 1, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Hour', 'comparison' => '=~', 'data' => '1,5,7,20', 'executionorder' => 1);
     $oLimitationHour = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     $oDate = new Date('2006-02-07 23:15:45');
     for ($i = 0; $i < 24; $i++) {
         $oDate->addSeconds(SECONDS_PER_HOUR);
         if ($i == 1 || $i == 5 || $i == 7 || $i == 20) {
             $this->assertFalse($oLimitationHour->deliveryBlocked($oDate));
         } else {
             $this->assertTrue($oLimitationHour->deliveryBlocked($oDate));
         }
     }
     // Test timezone
     $aDeliveryLimitation = array('ad_id' => 1, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Hour', 'comparison' => '=~', 'data' => '1,5,7,20@Europe/Rome', 'executionorder' => 1);
     $oLimitationHour = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     $oDate = new Date('2006-02-07 23:15:45');
     for ($i = 0; $i < 24; $i++) {
         $oDate->addSeconds(SECONDS_PER_HOUR);
         if ($i == 0 || $i == 4 || $i == 6 || $i == 19) {
             $this->assertFalse($oLimitationHour->deliveryBlocked($oDate));
         } else {
             $this->assertTrue($oLimitationHour->deliveryBlocked($oDate));
         }
     }
     OA_setTimeZoneLocal();
 }
Example #2
0
 /**
  * A method to test the deliveryBlocked() method.
  */
 function testDeliveryBlocked()
 {
     $aDeliveryLimitation = array('ad_id' => 1, 'logical' => 'and', 'type' => 'Client:IP', 'comparison' => '==', 'data' => '192.168.0.1', 'executionorder' => 1);
     $oLimitationDay = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     $oDate = new Date('2006-02-05');
     $this->assertFalse($oLimitationDay->deliveryBlocked($oDate));
 }
 /**
  * A method to test the deliveryBlocked() method.
  */
 function testDeliveryBlocked()
 {
     OA_setTimeZoneUTC();
     $aDeliveryLimitation = array('ad_id' => 1, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Day', 'comparison' => '=~', 'data' => '1,5,4,6', 'executionorder' => 1);
     $oLimitationDay = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     $oDate = new Date('2006-02-05');
     // Sunday
     $this->assertTrue($oLimitationDay->deliveryBlocked($oDate));
     $oDate = new Date('2006-02-06');
     // Monday
     $this->assertFalse($oLimitationDay->deliveryBlocked($oDate));
     $oDate = new Date('2006-02-07');
     // Tuesday
     $this->assertTrue($oLimitationDay->deliveryBlocked($oDate));
     $oDate = new Date('2006-02-08');
     // Wednesday
     $this->assertTrue($oLimitationDay->deliveryBlocked($oDate));
     $oDate = new Date('2006-02-09');
     // Thursday
     $this->assertFalse($oLimitationDay->deliveryBlocked($oDate));
     $oDate = new Date('2006-02-10');
     // Friday
     $this->assertFalse($oLimitationDay->deliveryBlocked($oDate));
     $oDate = new Date('2006-02-11');
     // Saturday
     $this->assertFalse($oLimitationDay->deliveryBlocked($oDate));
     // Test timezone
     $aDeliveryLimitation = array('ad_id' => 1, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Day', 'comparison' => '=~', 'data' => '1,5,4,6@America/New_York', 'executionorder' => 1);
     $oLimitationDay = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     $oDate = new Date('2006-02-05');
     // Sunday, but Saturday in GMT-5
     $this->assertFalse($oLimitationDay->deliveryBlocked($oDate));
     $oDate = new Date('2006-02-06');
     // Monday, but Sunday in GMT-5
     $this->assertTrue($oLimitationDay->deliveryBlocked($oDate));
     $oDate = new Date('2006-02-07');
     // Tuesday, but Monday in GMT-5
     $this->assertFalse($oLimitationDay->deliveryBlocked($oDate));
     $oDate = new Date('2006-02-08');
     // Wednesday, but Tuesday in GMT-5
     $this->assertTrue($oLimitationDay->deliveryBlocked($oDate));
     $oDate = new Date('2006-02-09');
     // Thursday, but Wednesday in GMT-5
     $this->assertTrue($oLimitationDay->deliveryBlocked($oDate));
     $oDate = new Date('2006-02-10');
     // Friday, but Friday in GMT-5
     $this->assertFalse($oLimitationDay->deliveryBlocked($oDate));
     $oDate = new Date('2006-02-11');
     // Saturday, but Friday in GMT-5
     $this->assertFalse($oLimitationDay->deliveryBlocked($oDate));
     OA_setTimeZoneLocal();
 }
Example #4
0
 /**
  * A factory method to return the appropriate
  * OA_Maintenance_Priority_DeliveryLimitation_Common
  * subclass object (one of OA_Maintenance_Priority_DeliveryLimitation_Date,
  * OA_Maintenance_Priority_DeliveryLimitation_Day,
  * OA_Maintenance_Priority_DeliveryLimitation_Empty or
  * OA_Maintenance_Priority_DeliveryLimitation_Hour), depending on the data
  * provided.
  *
  * @static
  * @param array $aDeliveryLimitation An array containing the details of a delivery limitation
  *                                   associated with an ad. For example:
  *                                   array(
  *                                       [ad_id]             => 1
  *                                       [logical]           => and
  *                                       [type]              => Time:Hour
  *                                       [comparison]        => ==
  *                                       [data]              => 1,7,18,23
  *                                       [executionorder]    => 1
  *                                   )
  * @return object OA_Maintenance_Priority_DeliveryLimitation_Common
  */
 function &factory($aDeliveryLimitation)
 {
     // Load plugins if not already in cache
     if (!isset(self::$aPlugins)) {
         self::$aPlugins = OX_Component::getComponents('deliveryLimitations', null, false);
     }
     // Return instance of the MPE DL class
     if (isset(self::$aPlugins[$aDeliveryLimitation['type']])) {
         return self::$aPlugins[$aDeliveryLimitation['type']]->getMpeClassInstance($aDeliveryLimitation);
     }
     // Unknown plugin? Return the empty MPE DL class
     return new OA_Maintenance_Priority_DeliveryLimitation_Empty($aDeliveryLimitation);
 }
 /**
  * A method to test the factory method.
  *
  * Test 1: Test Date object creation
  * Test 2: Test Day object creation
  * Test 3: Test Empty object creation
  * Test 4: Test Hour object creation
  */
 function testFactory()
 {
     // Test 1
     $aDeliveryLimitation = array('ad_id' => 3, 'logical' => 'or', 'type' => 'deliveryLimitations:Time:Date', 'comparison' => '>', 'data' => '20050505', 'executionorder' => 1);
     $obj = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     $this->assertIsA($obj, 'OA_Maintenance_Priority_DeliveryLimitation_Common');
     // Test 2
     $aDeliveryLimitation = array('ad_id' => 3, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Day', 'comparison' => '=~', 'data' => '0,6', 'executionorder' => 7);
     $obj = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     $this->assertIsA($obj, 'OA_Maintenance_Priority_DeliveryLimitation_Common');
     // Test 4
     $aDeliveryLimitation = array('ad_id' => 3, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Hour', 'comparison' => '=~', 'data' => '0,6,21', 'executionorder' => 0);
     $obj = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     $this->assertIsA($obj, 'OA_Maintenance_Priority_DeliveryLimitation_Common');
     // Test 4
     $aDeliveryLimitation = array('ad_id' => 3, 'logical' => 'and', 'type' => 'deliveryLimitations:Client:IP', 'comparison' => '=~', 'data' => '192.168.0.1', 'executionorder' => 0);
     $obj = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     $this->assertIsA($obj, 'OA_Maintenance_Priority_DeliveryLimitation_Empty');
     // Test 5
     $aDeliveryLimitation = array('ad_id' => 3, 'logical' => 'and', 'type' => 'Bogus', 'comparison' => '=~', 'data' => '192.168.0.1', 'executionorder' => 0);
     $obj = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     $this->assertIsA($obj, 'OA_Maintenance_Priority_DeliveryLimitation_Empty');
 }
 /**
  * A method to test the deliveryBlocked() method.
  *
  * Test 1: Test date == delivery requirement
  * Test 2: Test date != delivery requirement
  * Test 3: Test date <= delivery requirement
  * Test 4: Test date >= delivery requirement
  * Test 5: Test date <  delivery requirement
  * Test 6: Test date >  delivery requirement
  * Test 7: Bad input, no date object passed to method
  */
 function testDeliveryBlocked()
 {
     // Set timezone to UTC
     OA_setTimeZoneUTC();
     $oDate = new Date('2005-04-03');
     $oEarlierDate = new Date('2005-04-02');
     $oLaterDate = new Date('2005-04-04');
     $limitationData = $oDate->format('%Y%m%d@%Z');
     // Test 1
     $aDeliveryLimitation = array('ad_id' => 1, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Date', 'comparison' => '==', 'data' => $limitationData, 'executionorder' => 1);
     $oLimitationDate = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     // Test with same date: false, ad is active
     $this->assertFalse($oLimitationDate->deliveryBlocked($oDate));
     // Test with ealier date: true, ad is inactive
     $this->assertTrue($oLimitationDate->deliveryBlocked($oEarlierDate));
     // Test with later date: true, ad is inactive
     $this->assertTrue($oLimitationDate->deliveryBlocked($oLaterDate));
     // Test 2
     $aDeliveryLimitation = array('ad_id' => 1, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Date', 'comparison' => '!=', 'data' => $limitationData, 'executionorder' => 1);
     $oLimitationDate = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     // Test with same date: true, ad is inactive
     $this->assertTrue($oLimitationDate->deliveryBlocked($oDate));
     // Test with ealier date: false, ad is active
     $this->assertFalse($oLimitationDate->deliveryBlocked($oEarlierDate));
     // Test with later date: false, ad is active
     $this->assertFalse($oLimitationDate->deliveryBlocked($oLaterDate));
     // Test 3
     $aDeliveryLimitation = array('ad_id' => 1, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Date', 'comparison' => '<=', 'data' => $limitationData, 'executionorder' => 1);
     $oLimitationDate = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     // Test with same date: false, ad is active
     $this->assertFalse($oLimitationDate->deliveryBlocked($oDate));
     // Test with ealier date: false, ad is active
     $this->assertFalse($oLimitationDate->deliveryBlocked($oEarlierDate));
     // Test with later date: true, ad is inactive
     $this->assertTrue($oLimitationDate->deliveryBlocked($oLaterDate));
     // Test 4
     $aDeliveryLimitation = array('ad_id' => 1, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Date', 'comparison' => '>=', 'data' => $limitationData, 'executionorder' => 1);
     $oLimitationDate = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     // Test with same date: false, ad is active
     $this->assertFalse($oLimitationDate->deliveryBlocked($oDate));
     // Test with ealier date: true, ad is inactive
     $this->assertTrue($oLimitationDate->deliveryBlocked($oEarlierDate));
     // Test with later date: false, ad is active
     $this->assertFalse($oLimitationDate->deliveryBlocked($oLaterDate));
     // Test 5
     $aDeliveryLimitation = array('ad_id' => 1, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Date', 'comparison' => '<', 'data' => $limitationData, 'executionorder' => 1);
     $oLimitationDate = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     // Test with same date: true, ad is inactive
     $this->assertTrue($oLimitationDate->deliveryBlocked($oDate));
     // Test with ealier date: false, ad is active
     $this->assertFalse($oLimitationDate->deliveryBlocked($oEarlierDate));
     // Test with later date: true, ad is inactive
     $this->assertTrue($oLimitationDate->deliveryBlocked($oLaterDate));
     // Test 6
     $aDeliveryLimitation = array('ad_id' => 1, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Date', 'comparison' => '>', 'data' => $limitationData, 'executionorder' => 1);
     $oLimitationDate = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     // Test with same date: true, ad is inactive
     $this->assertTrue($oLimitationDate->deliveryBlocked($oDate));
     // Test with ealier date: true, ad is inactive
     $this->assertTrue($oLimitationDate->deliveryBlocked($oEarlierDate));
     // Test with later date: false, ad is active
     $this->assertFalse($oLimitationDate->deliveryBlocked($oLaterDate));
     // Test 7
     $aDeliveryLimitation = array('ad_id' => 1, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Date', 'comparison' => '>', 'data' => $limitationData, 'executionorder' => 1);
     $oLimitationDate = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     PEAR::pushErrorHandling(null);
     $this->assertTrue(is_a($oLimitationDate->deliveryBlocked('not a date'), 'pear_error'));
     PEAR::popErrorHandling();
     // Test with PST timezone
     $limitationData = $oDate->format('%Y%m%d') . '@America/New_York';
     $aDeliveryLimitation = array('ad_id' => 1, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Date', 'comparison' => '==', 'data' => $limitationData, 'executionorder' => 1);
     $oLimitationDate = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     // Test with same date (-1 day, 19pm in EST): true, ad is inactive
     $this->assertTrue($oLimitationDate->deliveryBlocked($oDate));
     // Test with ealier date (-2 days, 19pm in EST): true, ad is inactive
     $this->assertTrue($oLimitationDate->deliveryBlocked($oEarlierDate));
     // Test with later date (-0 days, 19pm in EST): false, ad is active
     $this->assertFalse($oLimitationDate->deliveryBlocked($oLaterDate));
     // Reset timezone
     OA_setTimeZoneLocal();
 }
 /**
  * Constructor method.
  *
  * @param array $aDeliveryLimitations An array or arrays, each containing the details of a
  *                                    delivery limitation associated with an ad. For example:
  *                                    array(
  *                                        [0] => array(
  *                                                   [ad_id]             => 1
  *                                                   [logical]           => and
  *                                                   [type]              => Time:Hour
  *                                                   [comparison]        => ==
  *                                                   [data]              => 1,7,18,23
  *                                                   [executionorder]    => 0
  *                                                ),
  *                                        [1] => array(
  *                                                   [ad_id]             => 1
  *                                                   [logical]           => and
  *                                                   [type]              => Time:Day
  *                                                   [comparison]        => !=
  *                                                   [data]              => '2005-06-32'
  *                                                   [executionorder]    => 1
  *                                                ),
  *                                          .
  *                                          .
  *                                          .
  *                                    )
  * @return OA_Maintenance_Priority_DeliveryLimitation
  */
 function __construct($aDeliveryLimitations)
 {
     // If there are delivery limitations...
     if (is_array($aDeliveryLimitations) && !empty($aDeliveryLimitations)) {
         // Sort the array of limitations so that they are ordered by execution order
         $aSort = array();
         foreach ($aDeliveryLimitations as $key => $aDeliveryLimitation) {
             $aSort[$key] = $aDeliveryLimitation['executionorder'];
         }
         array_multisort($aSort, SORT_ASC, $aDeliveryLimitations);
         // For each delivery limitation, in execution order...
         $groupNumber = 0;
         foreach ($aDeliveryLimitations as $key => $aDeliveryLimitation) {
             // Instantiate an appropriate delivery limitation class for the limitation type
             $this->aRules[$key] = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
             // Is the logical grouping AND or OR?
             if (!is_a($this->aRules[$key], 'pear_error') && strtolower($this->aRules[$key]->logical) == 'or') {
                 // Start a new grouping for the next (set of) rule(s)
                 $groupNumber++;
             }
             // Store possible "blocking" delivery limitations classes ONLY in
             // the appropriately numbered operation group, for later testing
             if (is_a($this->aRules[$key], 'OA_Maintenance_Priority_DeliveryLimitation_Common')) {
                 $this->aOperationGroups[$groupNumber][] = $this->aRules[$key];
             }
         }
     }
 }