Merge pull request #12024 from yashodha/price_custom_search
[civicrm-core.git] / tests / phpunit / api / v3 / ContributionTest.php
index 6dd0d2b705a9ba54073a8484d922f5e0880ab2db..d6b765dbc7c1a97fb9cfb6caad0c1e9f29d20bc9 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.7                                                |
+ | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
@@ -695,6 +695,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
 
     $params['total_amount'] = $this->formatMoneyInput(5000.77);
     $params['fee_amount'] = $this->formatMoneyInput(.77);
+    $params['skipCleanMoney'] = FALSE;
 
     $contribution = $this->callAPISuccess('contribution', 'create', $params);
     $contribution = $this->callAPISuccessGetSingle('contribution', array('id' => $contribution['id']));
@@ -2944,11 +2945,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
    * Test if renewal activity is create after changing Pending contribution to Completed via offline
    */
   public function testPendingToCompleteContribution() {
-    $contributionPage = $this->createPriceSetWithPage('membership');
-    $stateOfGrace = $this->callAPISuccess('MembershipStatus', 'getvalue', array(
-      'name' => 'Grace',
-      'return' => 'id')
-    );
+    $this->createPriceSetWithPage('membership');
     $this->setUpPendingContribution($this->_ids['price_field_value'][0]);
     $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership']));
     // Case 1: Assert that Membership Signup Activity is created on Pending to Completed Contribution via backoffice
@@ -2961,7 +2958,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
 
     // change pending contribution to completed
     $form = new CRM_Contribute_Form_Contribution();
-    $error = FALSE;
+
     $form->_params = array(
       'id' => $this->_ids['contribution'],
       'total_amount' => 20,
@@ -2991,12 +2988,9 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
       'contribution_mode' => 'membership',
       'source' => 'Membership Signup and Renewal',
     );
-    try {
-      $form->testSubmit($form->_params, CRM_Core_Action::UPDATE);
-    }
-    catch (Civi\Payment\Exception\PaymentProcessorException $e) {
-      $error = TRUE;
-    }
+
+    $form->testSubmit($form->_params, CRM_Core_Action::UPDATE);
+
     // Case 2: After successful payment for Pending backoffice there are three activities created
     //  2.a Update status of existing Scheduled Membership Signup (created in step 1) to Completed
     $activity = $this->callAPISuccess('Activity', 'get', array(
@@ -3036,6 +3030,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
       'source' => 'SSF',
       'contribution_status_id' => 2,
       'contribution_page_id' => $this->_ids['contribution_page'],
+      // We can't rely on contribution api to link line items correctly to membership
+      'skipLineItem' => TRUE,
       'api.membership_payment.create' => array('membership_id' => $this->_ids['membership']),
     ));
 
@@ -3048,18 +3044,26 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
       'unit_price' => 20,
       'line_total' => 20,
       'financial_type_id' => 1,
+      'price_field_value_id' => $this->_ids['price_field_value']['cont'],
+    ));
+    $this->callAPISuccess('line_item', 'create', array(
+      'entity_id' => $this->_ids['membership'],
+      'entity_table' => 'civicrm_membership',
+      'contribution_id' => $contribution['id'],
+      'price_field_id' => $this->_ids['price_field'][0],
+      'qty' => 1,
+      'unit_price' => 20,
+      'line_total' => 20,
+      'financial_type_id' => 1,
       'price_field_value_id' => $this->_ids['price_field_value'][0],
+      'membership_type_id' => $this->_ids['membership_type'],
     ));
 
     //Update it to Failed.
     $form->_params['id'] = $contribution['id'];
     $form->_params['contribution_status_id'] = 4;
-    try {
-      $form->testSubmit($form->_params, CRM_Core_Action::UPDATE);
-    }
-    catch (Civi\Payment\Exception\PaymentProcessorException $e) {
-      $error = TRUE;
-    }
+
+    $form->testSubmit($form->_params, CRM_Core_Action::UPDATE);
     //Existing membership should not get updated to expired.
     $membership = $this->callAPISuccess('membership', 'getsingle', array('id' => $this->_ids['membership']));
     $this->assertNotEquals($membership['status_id'], 4);
@@ -4126,4 +4130,14 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
     return array_merge(CRM_Financial_BAO_FinancialItem::retrieveEntityFinancialTrxn($trxnParams, FALSE, array()));
   }
 
+  /**
+   * Test getunique api call for Contribution entity
+   */
+  public function testContributionGetUnique() {
+    $result = $this->callAPIAndDocument($this->_entity, 'getunique', array(), __FUNCTION__, __FILE__);
+    $this->assertEquals(2, $result['count']);
+    $this->assertEquals(array('trxn_id'), $result['values']['UI_contrib_trxn_id']);
+    $this->assertEquals(array('invoice_id'), $result['values']['UI_contrib_invoice_id']);
+  }
+
 }