CRM test for CRM-18316
authorWeb Access <rohan.katkar@webaccessglobal.com>
Wed, 13 Apr 2016 13:31:43 +0000 (19:01 +0530)
committerWeb Access <rohan.katkar@webaccessglobal.com>
Wed, 13 Apr 2016 13:31:43 +0000 (19:01 +0530)
tests/phpunit/CRM/Pledge/BAO/PledgePaymentTest.php

index 7c00fd77de2f4895838f4031f765e22ce945f3db..544455674f71f890af721e90398fa6eb200b4d45 100644 (file)
@@ -251,6 +251,60 @@ class CRM_Pledge_BAO_PledgePaymentTest extends CiviUnitTestCase {
     $this->assertEquals('20130510000000', $date);
   }
 
+  /**
+   *  CRM-18316: To calculate pledge scheduled dates with end of a month.
+   *  Test culateNextScheduledDateMonth for months.
+   */
+  public function testcalculateNextScheduledDateMonth() {
+    $params = array(
+      'scheduled_date' => '20110510',
+      'frequency_unit' => 'month',
+      'frequency_day' => 31,
+      'frequency_interval' => 1,
+    );
+    $scheduleDate = CRM_Pledge_BAO_PledgePayment::calculateNextScheduledDate($params, 2);
+    $this->assertEquals('20110731000000', $scheduleDate);
+    // assert pledge scheduled date for month february.
+    $scheduleDateForFeb = CRM_Pledge_BAO_PledgePayment::calculateNextScheduledDate($params, 9);
+    $this->assertEquals('20120229000000', $scheduleDateForFeb);
+
+    //Case: Frequency day = 31 and scheduled date = 31st of any month
+    $params['scheduled_date'] = '20110131';
+    $params['frequency_day'] = 31;
+    $scheduleDate = CRM_Pledge_BAO_PledgePayment::calculateNextScheduledDate($params, 1);
+    $this->assertEquals('20110228000000', $scheduleDate);
+
+    //Case: Frequency day = 30 and scheduled date = 30th of any month
+    $params['scheduled_date'] = '20110130';
+    $params['frequency_day'] = 30;
+    $scheduleDate = CRM_Pledge_BAO_PledgePayment::calculateNextScheduledDate($params, 3);
+    $this->assertEquals('20110430000000', $scheduleDate);
+
+    //Case: Frequency day = 30 and scheduled date = any day of month
+    $params['scheduled_date'] = '20110110';
+    $params['frequency_day'] = 30;
+    $scheduleDate = CRM_Pledge_BAO_PledgePayment::calculateNextScheduledDate($params, 4);
+    $this->assertEquals('20110530000000', $scheduleDate);
+
+    //Case: Frequency day = any and scheduled date = 31st of any month
+    $params['scheduled_date'] = '20110131';
+    $params['frequency_day'] = 5;
+    $scheduleDate = CRM_Pledge_BAO_PledgePayment::calculateNextScheduledDate($params, 5);
+    $this->assertEquals('20110605000000', $scheduleDate);
+
+    //Case: Frequency day = any AND Satrt date = 30th of any month
+    $params['scheduled_date'] = '20110130';
+    $params['frequency_day'] = 10;
+    $scheduleDate = CRM_Pledge_BAO_PledgePayment::calculateNextScheduledDate($params, 6);
+    $this->assertEquals('20110710000000', $scheduleDate);
+
+    //Case: Frequency day = any AND Satrt date = any day month
+    $params['scheduled_date'] = '20110124';
+    $params['frequency_day'] = 6;
+    $scheduleDate = CRM_Pledge_BAO_PledgePayment::calculateNextScheduledDate($params, 7);
+    $this->assertEquals('20110806000000', $scheduleDate);
+  }
+
   /**
    *  Test calculateNextScheduledDate - no date provided
    */