Skip to content

Commit

Permalink
Merge pull request #15683 from eileenmcnaughton/test
Browse files Browse the repository at this point in the history
[NFC] test cleanup
  • Loading branch information
eileenmcnaughton authored Nov 1, 2019
2 parents 08718f9 + 5266bd4 commit d08b8e8
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 59 deletions.
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Financial/BAO/FinancialAccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public function testGetDeferredFinancialType() {
*/
public function testValidateFinancialAccount() {
// Create a record with financial item having financial account as Event Fee.
$this->createParticipantWithContribution();
$this->createPartiallyPaidParticipantOrder();
$financialAccounts = CRM_Contribute_PseudoConstant::financialAccount();
$financialAccountId = array_search('Event Fee', $financialAccounts);
$message = CRM_Financial_BAO_FinancialAccount::validateFinancialAccount($financialAccountId);
Expand Down
108 changes: 59 additions & 49 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2629,55 +2629,9 @@ protected function addProfile($name, $contributionPageID, $module = 'CiviContrib
*
* @throws \CRM_Core_Exception
*/
protected function createParticipantWithContribution() {
// creating price set, price field
$this->_contactId = $this->individualCreate();
$event = $this->eventCreate();
$this->_eventId = $event['id'];
$eventParams = [
'id' => $this->_eventId,
'financial_type_id' => 4,
'is_monetary' => 1,
];
$this->callAPISuccess('event', 'create', $eventParams);
$priceFields = $this->createPriceSet('event', $this->_eventId);
$participantParams = [
'financial_type_id' => 4,
'event_id' => $this->_eventId,
'role_id' => 1,
'status_id' => 14,
'fee_currency' => 'USD',
'contact_id' => $this->_contactId,
];
$participant = $this->callAPISuccess('Participant', 'create', $participantParams);
$orderParams = [
'total_amount' => 300,
'currency' => 'USD',
'contact_id' => $this->_contactId,
'financial_type_id' => 4,
'contribution_status_id' => 'Pending',
'contribution_mode' => 'participant',
'participant_id' => $participant['id'],
'api.Payment.create' => ['total_amount' => 150],
];
foreach ($priceFields['values'] as $key => $priceField) {
$orderParams['line_items'][] = [
'line_item' => [
[
'price_field_id' => $priceField['price_field_id'],
'price_field_value_id' => $priceField['id'],
'label' => $priceField['label'],
'field_title' => $priceField['label'],
'qty' => 1,
'unit_price' => $priceField['amount'],
'line_total' => $priceField['amount'],
'financial_type_id' => $priceField['financial_type_id'],
'entity_table' => 'civicrm_participant',
],
],
'params' => $participant,
];
}
protected function createPartiallyPaidParticipantOrder() {
$orderParams = $this->getParticipantOrderParams();
$orderParams['api.Payment.create'] = ['total_amount' => 150];
return $this->callAPISuccess('Order', 'create', $orderParams);
}

Expand Down Expand Up @@ -3350,4 +3304,60 @@ protected function resetLabels() {
CRM_Core_DAO::executeQuery("UPDATE civicrm_option_value SET label = REPLACE(name, ' Label**', '') WHERE label LIKE '% Label**'");
}

/**
* Get parameters to set up a multi-line participant order.
*
* @return array
* @throws \CRM_Core_Exception
*/
protected function getParticipantOrderParams(): array {
$this->_contactId = $this->individualCreate();
$event = $this->eventCreate();
$this->_eventId = $event['id'];
$eventParams = [
'id' => $this->_eventId,
'financial_type_id' => 4,
'is_monetary' => 1,
];
$this->callAPISuccess('event', 'create', $eventParams);
$priceFields = $this->createPriceSet('event', $this->_eventId);
$participantParams = [
'financial_type_id' => 4,
'event_id' => $this->_eventId,
'role_id' => 1,
'status_id' => 14,
'fee_currency' => 'USD',
'contact_id' => $this->_contactId,
];
$participant = $this->callAPISuccess('Participant', 'create', $participantParams);
$orderParams = [
'total_amount' => 300,
'currency' => 'USD',
'contact_id' => $this->_contactId,
'financial_type_id' => 4,
'contribution_status_id' => 'Pending',
'contribution_mode' => 'participant',
'participant_id' => $participant['id'],
];
foreach ($priceFields['values'] as $key => $priceField) {
$orderParams['line_items'][] = [
'line_item' => [
[
'price_field_id' => $priceField['price_field_id'],
'price_field_value_id' => $priceField['id'],
'label' => $priceField['label'],
'field_title' => $priceField['label'],
'qty' => 1,
'unit_price' => $priceField['amount'],
'line_total' => $priceField['amount'],
'financial_type_id' => $priceField['financial_type_id'],
'entity_table' => 'civicrm_participant',
],
],
'params' => $participant,
];
}
return $orderParams;
}

}
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function testGetOrder() {
*/
public function testGetOrderParticipant() {
$this->addOrder(FALSE, 100);
$contribution = $this->createParticipantWithContribution();
$contribution = $this->createPartiallyPaidParticipantOrder();

$params = [
'contribution_id' => $contribution['id'],
Expand Down
40 changes: 32 additions & 8 deletions tests/phpunit/api/v3/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function testGetPaymentWithTrxnID() {
*/
public function testPaymentEmailReceipt() {
$mut = new CiviMailUtils($this);
$contribution = $this->createParticipantWithContribution();
$contribution = $this->createPartiallyPaidParticipantOrder();
$event = $this->callAPISuccess('Event', 'get', []);
$this->addLocationToEvent($event['id']);
$params = [
Expand Down Expand Up @@ -206,7 +206,7 @@ public function testPaymentEmailReceipt() {
public function testPaymentEmailReceiptFullyPaid() {
$mut = new CiviMailUtils($this);
CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviContribute', 'edit contributions', 'access CiviCRM'];
$contribution = $this->createParticipantWithContribution();
$contribution = $this->createPartiallyPaidParticipantOrder();

$params = [
'contribution_id' => $contribution['id'],
Expand Down Expand Up @@ -242,7 +242,7 @@ public function testRefundEmailReceipt($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
$decimalSeparator = ($thousandSeparator === ',' ? '.' : ',');
$mut = new CiviMailUtils($this);
$contribution = $this->createParticipantWithContribution();
$contribution = $this->createPartiallyPaidParticipantOrder();
$this->callAPISuccess('payment', 'create', [
'contribution_id' => $contribution['id'],
'total_amount' => 50,
Expand Down Expand Up @@ -284,13 +284,37 @@ public function testRefundEmailReceipt($thousandSeparator) {
$mut->clearMessages();
}

/**
* Test adding a payment to a pending multi-line order.
*
* @throws \CRM_Core_Exception
*/
public function testCreatePaymentPendingOrderNoLineItems() {
$order = $this->createPendingParticipantOrder();
$this->callAPISuccess('Payment', 'create', [
'order_id' => $order['id'],
'total_amount' => 50,
]);
}

/**
* Add participant with contribution
*
* @return array
*
* @throws \CRM_Core_Exception
*/
protected function createPendingParticipantOrder() {
return $this->callAPISuccess('Order', 'create', $this->getParticipantOrderParams());
}

/**
* Test create payment api with no line item in params
*
* @throws \CRM_Core_Exception
*/
public function testCreatePaymentNoLineItems() {
$contribution = $this->createParticipantWithContribution();
$contribution = $this->createPartiallyPaidParticipantOrder();

//Create partial payment
$params = [
Expand Down Expand Up @@ -387,7 +411,7 @@ public function checkPaymentResult($payment, $expectedResult) {
* Test create payment api with line item in params
*/
public function testCreatePaymentLineItems() {
$contribution = $this->createParticipantWithContribution();
$contribution = $this->createPartiallyPaidParticipantOrder();
$lineItems = $this->callAPISuccess('LineItem', 'get', ['contribution_id' => $contribution['id']]);

//Create partial payment by passing line item array is params
Expand Down Expand Up @@ -482,7 +506,7 @@ public function testCreatePaymentLineItems() {
*/
public function testCancelPayment() {
CRM_Core_Config::singleton()->userPermissionClass->permissions = ['administer CiviCRM', 'access CiviContribute'];
$contribution = $this->createParticipantWithContribution();
$contribution = $this->createPartiallyPaidParticipantOrder();

$params = [
'contribution_id' => $contribution['id'],
Expand Down Expand Up @@ -518,7 +542,7 @@ public function testCancelPayment() {
*/
public function testDeletePayment() {
CRM_Core_Config::singleton()->userPermissionClass->permissions = ['administer CiviCRM', 'access CiviContribute'];
$contribution = $this->createParticipantWithContribution();
$contribution = $this->createPartiallyPaidParticipantOrder();

$params = [
'contribution_id' => $contribution['id'],
Expand Down Expand Up @@ -572,7 +596,7 @@ public function testDeletePayment() {
*/
public function testUpdatePayment() {
CRM_Core_Config::singleton()->userPermissionClass->permissions = ['administer CiviCRM', 'access CiviContribute', 'edit contributions'];
$contribution = $this->createParticipantWithContribution();
$contribution = $this->createPartiallyPaidParticipantOrder();

//Create partial payment by passing line item array is params
$params = [
Expand Down

0 comments on commit d08b8e8

Please sign in to comment.