+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
class api_v3_ContributionTest extends CiviUnitTestCase {
/**
- * Assume empty database with just civicrm_data
+ * Assume empty database with just civicrm_data.
*/
protected $_individualId;
protected $_contribution;
protected $_ids = array();
protected $_pageParams = array();
+ /**
+ * Parameters to create payment processor.
+ *
+ * @var array
+ */
+ protected $_processorParams = array();
+
+ /**
+ * ID of created event.
+ *
+ * @var int
+ */
+ protected $_eventID;
+
/**
* Setup function.
*/
));
}
- ///////////////// civicrm_contribution_
-
/**
* Create an contribution_id=FALSE and financial_type_id=Donation.
*/
}
/**
- * Check with complete array + custom field
+ * Check with complete array + custom field.
+ *
* Note that the test is written on purpose without any
* variables specific to participant so it can be replicated into other entities
* and / or moved to the automated test suite
}
/**
- * Test checks that passing in line items suppresses the create mechanism
+ * Test checks that passing in line items suppresses the create mechanism.
*/
public function testCreateContributionChainedLineItems() {
$params = array(
),
);
- $description = "Create Contribution with Nested Line Items";
+ $description = "Create Contribution with Nested Line Items.";
$subfile = "CreateWithNestedLineItems";
$contribution = $this->callAPIAndDocument('contribution', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
}
/**
- * Test create with valid payment instument
+ * Test create with valid payment instrument.
*/
public function testCreateContributionWithPaymentInstrument() {
$params = $this->_params + array('payment_instrument' => 'EFT');
}
/**
- * Create test with unique field name on source
+ * Create test with unique field name on source.
*/
public function testCreateContributionSource() {
}
/**
- * Create test with unique field name on source
+ * Create test with unique field name on source.
*/
public function testCreateDefaultNow() {
* Test note created correctly.
*/
public function testCreateContributionWithNote() {
- $description = "Demonstrates creating contribution with Note Entity";
+ $description = "Demonstrates creating contribution with Note Entity.";
$subfile = "ContributionCreateWithNote";
$params = array(
'contact_id' => $this->_individualId,
* This is the test for creating soft credits.
*/
public function testCreateContributionWithSoftCredit() {
- $description = "Demonstrates creating contribution with SoftCredit";
+ $description = "Demonstrates creating contribution with SoftCredit.";
$subfile = "ContributionCreateWithSoftCredit";
$contact2 = $this->callAPISuccess('Contact', 'create', array(
'display_name' => 'superman',
}
public function testCreateContributionWithSoftCreditDefaults() {
- $description = "Demonstrates creating contribution with Soft Credit defaults for amount and type";
+ $description = "Demonstrates creating contribution with Soft Credit defaults for amount and type.";
$subfile = "ContributionCreateWithSoftCreditDefaults";
$contact2 = $this->callAPISuccess('Contact', 'create', array(
'display_name' => 'superman',
}
public function testCreateContributionWithHonoreeContact() {
- $description = "Demonstrates creating contribution with Soft Credit by passing in honor_contact_id";
+ $description = "Demonstrates creating contribution with Soft Credit by passing in honor_contact_id.";
$subfile = "ContributionCreateWithHonoreeContact";
$contact2 = $this->callAPISuccess('Contact', 'create', array(
'display_name' => 'superman',
}
/**
- * Function tests that additional financial records are created when online contribution with pending option
- * is created
+ * Function tests that additional financial records are created for online contribution with pending option.
*/
public function testCreateContributionPendingOnline() {
$paymentProcessor = CRM_Financial_BAO_PaymentProcessor::create($this->_processorParams);
}
/**
- * Function tests that line items, financial records are updated when contribution amount is changed
+ * Function tests that line items, financial records are updated when contribution amount is changed.
*/
public function testCreateUpdateContributionChangeTotal() {
$contribution = $this->callAPISuccess('contribution', 'create', $this->_params);
$this->assertEquals('125.00', $lineItems);
$trxnAmount = $this->_getFinancialTrxnAmount($contribution['id']);
- $fitemAmount = $this->_getFinancialItemAmount($contribution['id']);
- // Financial trxn SUM = 125 + 5 (fee)
+
+ // Financial trxn SUM = 125 + 5 (fee).
$this->assertEquals('130.00', $trxnAmount);
- $this->assertEquals('125.00', $fitemAmount);
+ $this->assertEquals('125.00', $this->_getFinancialItemAmount($contribution['id']));
}
/**
- * Function tests that line items, financial records are updated when pay later contribution is received
+ * Function tests that line items, financial records are updated when pay later contribution is received.
*/
public function testCreateUpdateContributionPayLater() {
$contribParams = array(
}
/**
- * Function tests that financial records are updated when Payment Instrument is changed
+ * Function tests that financial records are updated when Payment Instrument is changed.
*/
public function testCreateUpdateContributionPaymentInstrument() {
$instrumentId = $this->_addPaymentInstrument();
}
/**
- * Function tests that financial records are added when Contribution is Refunded
+ * Function tests that financial records are added when Contribution is Refunded.
*/
public function testCreateUpdateContributionRefund() {
$contribParams = array(
}
/**
- * Function tests invalid contribution status change
+ * Function tests invalid contribution status change.
*/
public function testCreateUpdateContributionInValidStatusChange() {
$contribParams = array(
}
/**
- * Function tests that financial records are added when Pending Contribution is Canceled
+ * Function tests that financial records are added when Pending Contribution is Canceled.
*/
public function testCreateUpdateContributionCancelPending() {
$contribParams = array(
}
/**
- * Function tests that financial records are added when Financial Type is Changed
+ * Function tests that financial records are added when Financial Type is Changed.
*/
public function testCreateUpdateContributionChangeFinancialType() {
$contribParams = array(
}
/**
- * Test that update does not change status id CRM-15105
+ * Test that update does not change status id CRM-15105.
*/
public function testCreateUpdateWithoutChangingPendingStatus() {
$contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_params, array('contribution_status_id' => 2)));
}
/**
- * To Update Contribution
+ * Test Updating a Contribution.
+ *
* CHANGE: we require the API to do an incremental update
*/
public function testCreateUpdateContribution() {
);
$original = $this->callAPISuccess('contribution', 'get', $old_params);
- //Make sure it came back
+ // Make sure it came back.
$this->assertAPISuccess($original);
$this->assertEquals($original['id'], $contributionID);
//set up list of old params, verify
/**
* Test civicrm_contribution_search with empty params.
+ *
* All available contributions expected.
*/
public function testSearchEmptyParams() {
}
/**
- * Test completing a transaction via the API
+ * Test completing a transaction via the API.
*
* Note that we are creating a logged in user because email goes out from
* that person
}
/**
- * CRM-14151
- * Test completing a transaction via the API
- *
- * tests.
+ * Test repeat contribution successfully creates line items.
+ */
+ public function testRepeatTransaction() {
+ $paymentProcessorID = $this->paymentProcessorCreate();
+ $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']))
+ );
+
+ $this->callAPISuccess('contribution', 'repeattransaction', array(
+ 'original_contribution_id' => $originalContribution['id'],
+ 'contribution_status_id' => 'Completed',
+ 'trxn_id' => uniqid(),
+ ));
+ $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',
+ ),
+ );
+ $lineItem1 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
+ 'entity_id' => $originalContribution['id'],
+ )));
+ $lineItem2 = $this->callAPISuccess('line_item', 'get', array_merge($lineItemParams, array(
+ 'entity_id' => $originalContribution['id'] + 1,
+ )));
+ unset($lineItem1['values'][0]['id'], $lineItem1['values'][0]['entity_id']);
+ unset($lineItem2['values'][0]['id'], $lineItem2['values'][0]['entity_id']);
+ $this->assertEquals($lineItem1['values'][0], $lineItem2['values'][0]);
+
+ $this->quickCleanUpFinancialEntities();
+ }
+
+ /**
+ * Test completing a transaction does not 'mess' with net amount (CRM-15960).
+ */
+ public function testCompleteTransactionNetAmountOK() {
+ $this->createLoggedInUser();
+ $params = array_merge($this->_params, array('contribution_status_id' => 2));
+ unset($params['net_amount']);
+ $contribution = $this->callAPISuccess('contribution', 'create', $params);
+ $this->callAPISuccess('contribution', 'completetransaction', array(
+ 'id' => $contribution['id'],
+ ));
+ $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $contribution['id']));
+ $this->assertEquals('Completed', $contribution['contribution_status']);
+ $this->assertTrue(($contribution['total_amount'] - $contribution['net_amount']) == $contribution['fee_amount']);
+ }
+
+ /**
+ * CRM-14151 - Test completing a transaction via the API.
*/
public function testCompleteTransactionWithReceiptDateSet() {
$mut = new CiviMailUtils($this, TRUE);
}
/**
- * Test completing a transaction with an event via the API
+ * Test completing a transaction with an event via the API.
*
* Note that we are creating a logged in user because email goes out from
* that person
}
/**
- * Test membership is renewed when transaction completed
+ * Test membership is renewed when transaction completed.
*/
public function testCompleteTransactionMembershipPriceSet() {
$this->createPriceSetWithPage('membership');
}
/**
- * Test membership is renewed when transaction completed
+ * Test membership is renewed when transaction completed.
*/
public function testCompleteTransactionMembershipPriceSetTwoTerms() {
$this->createPriceSetWithPage('membership');
/**
+ * Create price set with contribution test for test setup.
+ *
* This could be merged with 4.5 function setup in api_v3_ContributionPageTest::setUpContributionPage
- * on parent class at some point (fn is not in 4.4)
+ * on parent class at some point (fn is not in 4.4).
+ *
* @param $entity
* @param array $params
*/
}
/**
- * Set up a pending transaction with a specific price field id
+ * Set up a pending transaction with a specific price field id.
+ *
* @param int $priceFieldValueID
*/
public function setUpPendingContribution($priceFieldValueID) {
}
/**
- * Test sending a mail via the API
+ * Test sending a mail via the API.
*/
public function testSendMail() {
$mut = new CiviMailUtils($this, TRUE);
}
/**
- * Test sending a mail via the API
+ * Test sending a mail via the API.
*/
public function testSendMailEvent() {
$mut = new CiviMailUtils($this, TRUE);
}
/**
- * This function does a GET & compares the result against the $params
- * Use as a double check on Creates
- * @param $params
- * @param $id
- * @param int $delete
+ * This function does a GET & compares the result against the $params.
+ *
+ * Use as a double check on Creates.
+ *
+ * @param array $params
+ * @param int $id
+ * @param bool $delete
*/
- public function contributionGetnCheck($params, $id, $delete = 1) {
+ public function contributionGetnCheck($params, $id, $delete = TRUE) {
$contribution = $this->callAPISuccess('Contribution', 'Get', array(
'id' => $id,
}
/**
- * Create a pending contribution & linked pending participant record
- * (along with an event)
+ * Create a pending contribution & linked pending participant record (along with an event).
*/
public function createPendingParticipantContribution() {
$event = $this->eventCreate(array('is_email_confirm' => 1, 'confirm_from_email' => 'test@civicrm.org'));
}
/**
+ * Get financial transaction amount.
+ *
* @param int $contId
*
* @return null|string