Skip to content
Snippets Groups Projects
Commit 26076348 authored by Eileen McNaughton's avatar Eileen McNaughton
Browse files

Fix BaseIPN test to (mostly) pass invalid financials

parent 6d2cfffb
Branches
Tags
No related merge requests found
......@@ -144,7 +144,7 @@ function civicrm_api3_order_create(array $params): array {
}
$contribution = civicrm_api3('Contribution', 'create', $contributionParams);
$contribution['values'][$contribution['id']]['line_item'] = $order->getLineItems();
$contribution['values'][$contribution['id']]['line_item'] = array_values($order->getLineItems());
// add payments
if ($entity && !empty($contribution['id'])) {
......
......@@ -17,6 +17,16 @@ use Civi\Api4\Contribution;
*/
class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase {
/**
* Should financials be checked after the test but before tear down.
*
* Ideally all tests (or at least all that call any financial api calls ) should do this but there
* are some test data issues and some real bugs currently blocking.
*
* @var bool
*/
protected $isValidateFinancialsOnPostAssert = TRUE;
protected $_financialTypeId;
protected $_contributionParams;
protected $_contactId;
......@@ -78,18 +88,10 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase {
'financial_type_id' => $this->_financialTypeId,
'receive_date' => date('Ymd'),
'total_amount' => 150.00,
'invoice_id' => 'c8acb91e080ad7bd8a2adc119c192885',
'currency' => 'USD',
'contribution_recur_id' => $this->_recurId,
'contribution_status_id' => 2,
];
$contribution = $this->callAPISuccess('contribution', 'create', $this->_contributionParams);
$this->_contributionId = $contribution['id'];
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $this->_contributionId;
$contribution->find(TRUE);
$this->objects['contribution'] = $contribution;
}
/**
......@@ -106,6 +108,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase {
public function testLoadMembershipObjectsLoadAll() {
$this->_setUpMembershipObjects();
$this->_setUpRecurringContribution();
$this->_membershipId = $this->ids['membership'];
unset($this->ids['membership']);
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $this->_contributionId;
......@@ -258,6 +261,8 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase {
* @throws \CiviCRM_API3_Exception
*/
public function testThatCancellingEventPaymentWillCancelAllAdditionalPendingParticipantsAndCreateCancellationActivities(): void {
// Test fails - reason not yet investigated.
$this->isValidateFinancialsOnPostAssert = FALSE;
$this->_setUpParticipantObjects('Pending from incomplete transaction');
$additionalParticipantId = $this->participantCreate([
'event_id' => $this->_eventId,
......@@ -357,7 +362,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase {
'component' => 'contribute',
'contribution_page_id' => $contributionPageID,
'total_amount' => 110.00,
'invoiceID' => "c8acb91e080ad7777a2adc119c192885",
'invoiceID' => 'c8acb91e080ad7777a2adc119c192885',
'contactID' => $this->_contactId,
'contributionID' => $this->objects['contribution']->id,
];
......@@ -367,55 +372,45 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase {
* Prepare for membership test.
*/
public function _setUpMembershipObjects(): void {
try {
if (!$this->_membershipTypeID) {
$this->_membershipTypeID = $this->membershipTypeCreate();
}
if (!$this->_membershipStatusID) {
$this->_membershipStatusID = $this->membershipStatusCreate('test status');
}
if (!$this->_membershipTypeID) {
$this->_membershipTypeID = $this->membershipTypeCreate();
}
catch (Exception$e) {
echo $e->getMessage();
if (!$this->_membershipStatusID) {
$this->_membershipStatusID = $this->membershipStatusCreate('test status');
}
CRM_Member_PseudoConstant::membershipType($this->_membershipTypeID, TRUE);
CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'name', TRUE);
$this->_membershipParams = [
'contact_id' => $this->_contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => '2009-01-21',
'start_date' => '2009-01-21',
'end_date' => '2009-12-21',
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
'version' => 3,
];
$membership = $this->callAPISuccess('membership', 'create', $this->_membershipParams);
if ($this->objects['contribution']->id != $this->_contributionId) {
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $this->_contributionId;
$contribution->find(TRUE);
$this->objects = ['contribution' => $contribution];
}
$this->_membershipId = $membership['id'];
//we'll create membership payment here because to make setup more re-usable
$this->callAPISuccess('membership_payment', 'create', [
'contribution_id' => $this->_contributionId,
'membership_id' => $this->_membershipId,
]);
$orderParams = $this->_contributionParams;
$orderParams['line_items'] = [
[
'line_item' => [['membership_type_id' => $this->_membershipTypeID, 'line_total' => 150]],
'params' => [
'contact_id' => $this->_contactId,
'membership_type_id' => $this->_membershipTypeID,
'join_date' => '2009-01-21',
'start_date' => '2009-01-21',
'end_date' => '2009-12-21',
'source' => 'Payment',
'is_override' => 1,
'status_id' => $this->_membershipStatusID,
],
],
];
$order = $this->callAPISuccess('Order', 'create', $orderParams);
$this->_contributionId = $order['id'];
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $this->_contributionId;
$contribution->find(TRUE);
$this->objects = ['contribution' => $contribution];
$this->ids['membership'] = (int) $order['values'][$order['id']]['line_item'][0]['entity_id'];
$this->input = [
'component' => 'contribute',
'total_amount' => 150.00,
'invoiceID' => "c8acb91e080ad7bd8a2adc119c192885",
'invoiceID' => 'c8acb91e080ad7bd8a2adc119c192885',
'contactID' => $this->_contactId,
'contributionID' => $this->_contributionId,
'membershipID' => $this->_membershipId,
'membershipID' => $this->ids['membership'],
];
$this->ids['membership'] = $this->_membershipId;
}
public function _setUpRecurringContribution() {
......@@ -450,6 +445,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase {
*/
public function _setUpParticipantObjects($participantStatus = 'Attended'): void {
$event = $this->eventCreate(['is_email_confirm' => 1]);
$this->setupContribution();
$this->_eventId = $event['id'];
$this->_participantId = $this->participantCreate([
......@@ -485,6 +481,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase {
* Set up participant requirements for test.
*/
public function _setUpPledgeObjects() {
$this->setupContribution();
$this->_pledgeId = $this->pledgeCreate(['contact_id' => $this->_contactId]);
//we'll create membership payment here because to make setup more re-usable
$pledgePayment = $this->callAPISuccess('pledge_payment', 'create', [
......@@ -507,4 +504,14 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase {
$this->ids['pledge_payment'][] = $pledgePayment['id'];
}
protected function setupContribution(): void {
$contribution = $this->callAPISuccess('contribution', 'create', $this->_contributionParams);
$this->_contributionId = $contribution['id'];
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $this->_contributionId;
$contribution->find(TRUE);
$this->objects['contribution'] = $contribution;
}
}
......@@ -276,6 +276,9 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
* @throws \CiviCRM_API3_Exception
*/
public function testCRM19273() {
// When a line item is 'resurrected' the financial_items attached to it are wrong.
// We have to skip validatePayments until fixed.
$this->isValidateFinancialsOnPostAssert = FALSE;
$this->registerParticipantAndPay();
$priceSetParams['price_' . $this->priceSetFieldID] = $this->cheapFeeValueID;
......
......@@ -26,6 +26,7 @@
* <http://www.gnu.org/licenses/>.
*/
use Civi\Api4\Contribution;
use Civi\Api4\CustomField;
use Civi\Api4\CustomGroup;
use Civi\Api4\OptionGroup;
......@@ -151,7 +152,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
* Should financials be checked after the test but before tear down.
*
* Ideally all tests (or at least all that call any financial api calls ) should do this but there
* are some test data issues and some real bugs currently blockinng.
* are some test data issues and some real bugs currently blocking.
*
* @var bool
*/
......@@ -3639,10 +3640,10 @@ VALUES
/**
* Validate all created contributions.
*
* @throws \CRM_Core_Exception
* @throws \API_Exception
*/
protected function validateAllContributions(): void {
$contributions = $this->callAPISuccess('Contribution', 'get', ['return' => ['tax_amount', 'total_amount']])['values'];
$contributions = Contribution::get(FALSE)->setSelect(['total_amount', 'tax_amount'])->execute();
foreach ($contributions as $contribution) {
$lineItems = $this->callAPISuccess('LineItem', 'get', [
'contribution_id' => $contribution['id'],
......
......@@ -24,6 +24,16 @@
class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
protected $_apiversion = 3;
/**
* Do not check financial entities in this test class.
*
* The class uses lots of crud to do things by-passing
* BAO logic & entities are often not valid as a result.
*
* @var bool
*/
protected $isValidateFinancialsOnPostAssert = FALSE;
/**
* @var array
* e.g. $this->deletes['CRM_Contact_DAO_Contact'][] = $contactID;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment