CRM-16397 test for repeatcontribution with altered line items
authorEileen McNaughton <eileen@fuzion.co.nz>
Thu, 7 May 2015 02:38:05 +0000 (14:38 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Thu, 7 May 2015 04:39:08 +0000 (16:39 +1200)
tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/phpunit/api/v3/ContributionTest.php

index 10388ebc58e0565ec0d343635be4acd2ea7279e1..b896aac5bb0a92c58fce0cb9797ee2ceb90e5197 100755 (executable)
@@ -1952,6 +1952,22 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
     crm_add_uf_join($params);
   }
 
+  /**
+   * @param array $params
+   *   Optional parameters.
+   *
+   * @return int
+   *   Campaign ID.
+   */
+  public function campaignCreate($params = array()) {
+    $this->enableCiviCampaign();
+    $campaign = $this->callAPISuccess('campaign', 'create', array_merge(array(
+      'name' => 'big_campaign',
+      'title' => 'Campaign',
+    ), $params));
+    return $campaign['id'];
+  }
+
   /**
    * Create Group for a contact.
    *
index 0da81ae91646afed1d8c587bdfb4a734e451e73e..7429dafa05cd605c98a28366dee49c11d3b58d2c 100644 (file)
@@ -1392,6 +1392,80 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
     $this->quickCleanUpFinancialEntities();
   }
 
+  /**
+   * CRM-16397 test appropriate action if total amount has changed for single line items.
+   */
+  public function testRepeatTransactionAlteredAmount() {
+    $paymentProcessorID = $this->paymentProcessorCreate();
+    $campaignID = $this->campaignCreate();
+    $campaignID2 = $this->campaignCreate();
+    $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array(
+      'contact_id' => $this->_individualId,
+      'installments' => '12',
+      'frequency_interval' => '1',
+      'amount' => '500',
+      'contribution_status_id' => 1,
+      'start_date' => '2012-01-01 00:00:00',
+      'currency' => 'USD',
+      'frequency_unit' => 'month',
+      'payment_processor_id' => $paymentProcessorID,
+    ));
+    $originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
+        $this->_params,
+        array(
+          'contribution_recur_id' => $contributionRecur['id'],
+          'campaign_id' => $campaignID,
+        ))
+    );
+
+    $this->callAPISuccess('contribution', 'repeattransaction', array(
+      'original_contribution_id' => $originalContribution['id'],
+      'contribution_status_id' => 'Completed',
+      'trxn_id' => uniqid(),
+      'total_amount' => '400',
+      'fee_amount' => 50,
+      'campaign_id' => $campaignID2,
+    ));
+    $lineItemParams = array(
+      'entity_id' => $originalContribution['id'],
+      'sequential' => 1,
+      'return' => array(
+        'entity_table',
+        'qty',
+        'unit_price',
+        'line_total',
+        'label',
+        'financial_type_id',
+        'deductible_amount',
+        'price_field_value_id',
+        'price_field_id',
+      ),
+    );
+    $this->callAPISuccessGetSingle('contribution', array(
+      'total_amount' => 400,
+      'campaign_id' => $campaignID2,
+      'fee_amount' => 50,
+      'net_amount' => 350,
+    ));
+    $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
+      'entity_id' => $originalContribution['id'],
+    )));
+    $expectedLineItem = array_merge(
+      $lineItem1['values'][0], array(
+        'line_total' => '400.00',
+        'unit_price' => '400.00',
+      ));
+
+    $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
+      'entity_id' => $originalContribution['id'] + 1,
+    )));
+    unset($expectedLineItem['id'], $expectedLineItem['entity_id']);
+    unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
+    $this->assertEquals($expectedLineItem, $lineItem2['values'][0]);
+
+    $this->quickCleanUpFinancialEntities();
+  }
+
   /**
    * Test completing a transaction does not 'mess' with net amount (CRM-15960).
    */