CRM-16417 add test
authorEileen McNaughton <eileen@fuzion.co.nz>
Wed, 24 Jun 2015 12:23:41 +0000 (00:23 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Wed, 24 Jun 2015 12:51:53 +0000 (00:51 +1200)
tests/phpunit/api/v3/ContributionPageTest.php

index d15ca4f53f3a1dacbee707ac11b49c669ae13361..75f82eb0867a4ea8fa110046e287c6727b2aad06 100644 (file)
@@ -255,6 +255,42 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
     $this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
   }
 
+  /**
+   * Test that when a transaction fails the pending contribution remains.
+   *
+   * An activity should also be created. CRM-16417.
+   */
+  public function testSubmitPaymentProcessorFailure() {
+    $this->setUpContributionPage();
+    $this->setupPaymentProcessor();
+    $this->createLoggedInUser();
+    $priceFieldID = reset($this->_ids['price_field']);
+    $priceFieldValueID = reset($this->_ids['price_field_value']);
+    $submitParams = array(
+      'price_' . $priceFieldID => $priceFieldValueID,
+      'id' => (int) $this->_ids['contribution_page'],
+      'amount' => 10,
+      'payment_processor_id' => 1,
+      'credit_card_number' => '4111111111111111',
+      'credit_card_type' => 'Visa',
+      'credit_card_exp_date' => array('M' => 9, 'Y' => 2008),
+      'cvv2' => 123,
+    );
+
+    $this->callAPISuccess('contribution_page', 'submit', $submitParams);
+    $contribution = $this->callAPISuccessGetSingle('contribution', array(
+      'contribution_page_id' => $this->_ids['contribution_page'],
+      'contribution_status_id' => 2,
+    ));
+
+    $this->callAPISuccessGetSingle('activity', array(
+      'source_record_id' => $contribution['id'],
+      'activity_type_id' => 'Failed Payment',
+    ));
+
+
+  }
+
   /**
    * Test submit recurring membership with immediate confirmation (IATS style)
    * - we process 2 membership transactions against with a recurring contribution against a contribution page with an immediate