Skip to content

Commit

Permalink
CRM-20585, Added unit test to check to and from entries in financial …
Browse files Browse the repository at this point in the history
…trxn table for deferred revenue

----------------------------------------
* CRM-20585: Correct the from and to accounts for deferred revenue transactions
  https://issues.civicrm.org/jira/browse/CRM-20585
  • Loading branch information
pradpnayak committed May 17, 2017
1 parent ec64795 commit 87bf7cb
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/phpunit/CRM/Contribute/BAO/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1248,4 +1248,60 @@ public function testReplaceContributionTokens() {
<p>Contribution Receive Date: May 11th, 2015</p></br>", $contributionDetails[$contactId2]['html'], "The html does not match");
}

/**
* Test for contribution with deferred revenue.
*/
public function testContributionWithDeferredRevenue() {
$contactId = $this->individualCreate();
Civi::settings()->set('deferred_revenue_enabled', TRUE);
$params = array(
'contact_id' => $contactId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'financial_type_id' => 'Event Fee',
'trxn_id' => 12345,
'invoice_id' => 67890,
'source' => 'SSF',
'contribution_status_id' => 'Completed',
'revenue_recognition_date' => date('Ymd', strtotime("+3 month")),
);
$contribution = $this->callAPISuccess('contribution', 'create', $params);

$this->callAPISuccessGetCount('EntityFinancialTrxn', array(
'entity_table' => "civicrm_contribution",
'entity_id' => $contribution['id'],
), 2);

$checkAgainst = array(
'financial_trxn_id.to_financial_account_id.name' => 'Deferred Revenue - Event Fee',
'financial_trxn_id.from_financial_account_id.name' => 'Event Fee',
'financial_trxn_id' => '2'
);
$result = $this->callAPISuccessGetSingle('EntityFinancialTrxn', array(
'return' => array(
"financial_trxn_id.from_financial_account_id.name",
"financial_trxn_id.to_financial_account_id.name",
"financial_trxn_id",
),
'entity_table' => "civicrm_contribution",
'entity_id' => $contribution['id'],
'financial_trxn_id.is_payment' => 0,
), $checkAgainst);

$result = $this->callAPISuccessGetSingle('EntityFinancialTrxn', array(
'entity_table' => "civicrm_financial_item",
'financial_trxn_id' => $result['financial_trxn_id'],
'return' => array('entity_id'),
));

$checkAgainst = array(
'financial_account_id.name' => 'Deferred Revenue - Event Fee',
'id' => $result['entity_id'],
);
$result = $this->callAPISuccessGetSingle('FinancialItem', array(
'id' => $result['entity_id'],
'return' => array("financial_account_id.name"),
), $checkAgainst);
}

}

0 comments on commit 87bf7cb

Please sign in to comment.