Skip to content

Commit

Permalink
Merge pull request #19416 from eileenmcnaughton/dep
Browse files Browse the repository at this point in the history
dev/financial#148 fully deprecate loadObjects function
  • Loading branch information
colemanw authored Jan 21, 2021
2 parents 395bbc1 + f2c927f commit dca7262
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 121 deletions.
3 changes: 3 additions & 0 deletions CRM/Core/Payment/BaseIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ public function validateData($input, &$ids, &$objects, $required = TRUE, $paymen
/**
* Load objects related to contribution.
*
* @deprecated
*
* @input array information from Payment processor
*
* @param array $input
Expand All @@ -152,6 +154,7 @@ public function validateData($input, &$ids, &$objects, $required = TRUE, $paymen
* @throws \CRM_Core_Exception
*/
public function loadObjects($input, &$ids, &$objects, $required, $paymentProcessorID) {
CRM_Core_Error::deprecatedFunctionWarning('use api methods in ipn');
$contribution = &$objects['contribution'];
$ids['paymentProcessor'] = $paymentProcessorID;
$success = $contribution->loadRelatedObjects($input, $ids);
Expand Down
15 changes: 9 additions & 6 deletions CRM/Core/Payment/PayPalProIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,10 @@ public function main() {
unset($ids['contributionPage']);
}

if (!$this->loadObjects($input, $ids, $objects, TRUE, $paymentProcessorID)) {
return;
}
$contribution = &$objects['contribution'];
$ids['paymentProcessor'] = $paymentProcessorID;
$contribution->loadRelatedObjects($input, $ids);
$objects = array_merge($objects, $contribution->_relatedObjects);

$input['payment_processor_id'] = $paymentProcessorID;

Expand Down Expand Up @@ -640,9 +641,11 @@ public function handlePaymentExpress() {
unset($ids['contributionPage']);
}

if (!$this->loadObjects($input, $ids, $objects, TRUE, $paymentProcessorID)) {
throw new CRM_Core_Exception('Data did not validate');
}
$contribution = &$objects['contribution'];
$ids['paymentProcessor'] = $paymentProcessorID;
$contribution->loadRelatedObjects($input, $ids);
$objects = array_merge($objects, $contribution->_relatedObjects);

$this->recur($input, $ids, $objects['contributionRecur'], $objects['contribution'], $isFirst);
}

Expand Down
116 changes: 1 addition & 115 deletions tests/phpunit/CRM/Core/Payment/BaseIPNTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,43 +98,6 @@ public function tearDown() {
CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'name', TRUE);
}

/**
* Test the LoadObjects function with recurring membership data.
*/
public function testLoadMembershipObjects() {
$this->_setUpMembershipObjects();
$this->_setUpRecurringContribution();
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$this->assertNotEmpty($this->objects['membership']);
$this->assertArrayHasKey($this->_membershipId . '_' . $this->_membershipTypeID, $this->objects['membership']);
$this->assertTrue(is_a($this->objects['membership'][$this->_membershipId . '_' . $this->_membershipTypeID], 'CRM_Member_BAO_Membership'));
$this->assertTrue(is_a($this->objects['financialType'], 'CRM_Financial_BAO_FinancialType'));
$this->assertNotEmpty($this->objects['contributionRecur']);
$this->assertNotEmpty($this->objects['paymentProcessor']);
}

/**
* Test the LoadObjects function with recurring membership data.
*/
public function testLoadMembershipObjectsNoLeakage() {
$this->_setUpMembershipObjects();
$this->_setUpRecurringContribution();
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$this->assertEquals('Anthony', $this->objects['contact']->first_name);

$this->ids['contact'] = $this->_contactId = $this->individualCreate([
'first_name' => 'Donald',
'last_name' => 'Duck',
'email' => 'the-don@duckville.com',
]);
$contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_contributionParams, ['invoice_id' => 'abc']));
$this->_contributionId = $contribution['id'];
$this->_setUpMembershipObjects();
$this->input['invoiceID'] = 'abc';
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$this->assertEquals('Donald', $this->objects['contact']->first_name);
}

/**
* Test the LoadObjects function with recurring membership data.
*/
Expand Down Expand Up @@ -189,8 +152,6 @@ public function testSendMailMembershipObjectsNoLeakage() {
$this->_membershipTypeID = $this->membershipTypeCreate(['name' => 'Fowl']);
$this->_setUpMembershipObjects();
$this->input['invoiceID'] = 'abc';
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$this->assertEquals('Donald', $this->objects['contact']->first_name);
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $this->_contributionId;
$msg = $contribution->composeMessageArray($this->input, $this->ids, $values);
Expand All @@ -211,31 +172,14 @@ public function testSendMailMembershipWithoutLoadObjects() {
$this->assertContains('Membership Type: General', $msg['body']);
}

/**
* Test that loadObjects works with participant values.
*/
public function testLoadParticipantObjects() {
$this->_setUpParticipantObjects();
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$this->assertNotEmpty($this->objects['participant']);
$this->assertTrue(is_a($this->objects['participant'], 'CRM_Event_BAO_Participant'));
$this->assertTrue(is_a($this->objects['financialType'], 'CRM_Financial_BAO_FinancialType'));
$this->assertNotEmpty($this->objects['event']);
$this->assertTrue(is_a($this->objects['event'], 'CRM_Event_BAO_Event'));
$this->assertTrue(is_a($this->objects['contribution'], 'CRM_Contribute_BAO_Contribution'));
$this->assertNotEmpty($this->objects['event']->id);
}

/**
* Test the LoadObjects function with a participant.
*/
public function testComposeMailParticipant() {
$this->_setUpParticipantObjects();
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$values = [];
$this->assertNotEmpty($this->objects['event']);
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $this->_contributionId;
$contribution->loadRelatedObjects($this->input, $this->ids);
$msg = $contribution->composeMessageArray($this->input, $this->ids, $values);
$this->assertContains('registration has been received and your status has been updated to Attended.', $msg['body']);
$this->assertContains('Annual CiviCRM meet', $msg['html']);
Expand Down Expand Up @@ -291,43 +235,6 @@ public function testsendMailParticipantObjectsNoMail() {
$mut->stop();
}

/**
* Test that loadObjects works with participant values.
*/
public function testLoadPledgeObjects() {
$this->_setUpPledgeObjects();
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$this->assertNotEmpty($this->objects['pledge_payment'][0]);
$this->assertTrue(is_a($this->objects['financialType'], 'CRM_Financial_BAO_FinancialType'));
$this->assertTrue(is_a($this->objects['contribution'], 'CRM_Contribute_BAO_Contribution'));
$this->assertTrue(is_a($this->objects['pledge_payment'][0], 'CRM_Pledge_BAO_PledgePayment'));
$this->assertNotEmpty($this->objects['pledge_payment'][0]->id);
$this->assertEquals($this->_financialTypeId, $this->objects['financialType']->id);
$this->assertEquals($this->_processorId, $this->objects['paymentProcessor']['id']);
$this->assertEquals($this->_contributionId, $this->objects['contribution']->id);
$this->assertEquals($this->_contactId, $this->objects['contact']->id);
$this->assertEquals($this->_pledgeId, $this->objects['pledge_payment'][0]->pledge_id);
}

/**
* Test that loadObjects works with participant values.
*/
public function testLoadPledgeObjectsInvalidPledgeID() {
$this->_setUpPledgeObjects();
$this->ids['pledge_payment'][0] = 0;

$this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL);
$this->assertArrayNotHasKey('pledge_payment', $this->objects);

$this->ids['pledge_payment'][0] = 999;
try {
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, $this->_processorId);
}
catch (CRM_Core_Exception $e) {
$this->assertEquals('Could not find pledge payment record: 999', $e->getMessage());
}
}

/**
* Test the LoadObjects function with a pledge.
*/
Expand All @@ -339,27 +246,6 @@ public function testSendMailPledge() {
$this->assertContains('Contribution Information', $msg['html']);
}

/**
* Test that an error is returned if required set & no contribution page.
*/
public function testRequiredWithoutProcessorID() {
$this->_setUpPledgeObjects();
// error is only returned if $required set to True
$result = $this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL);
$this->assertEquals(TRUE, $result);
}

/**
* Test that if part of $input the payment processor loads OK.
*
* It's preferable to pass it in as it cannot be correctly calculated.
*/
public function testPaymentProcessorLoadsAsParam() {
$this->_setUpContributionObjects();
$this->input = array_merge($this->input, ['payment_processor_id' => $this->_processorId]);
$this->assertTrue($this->IPN->loadObjects($this->input, $this->ids, $this->objects, TRUE, NULL));
}

public function testThatCancellingEventPaymentWillCancelAllAdditionalPendingParticipantsAndCreateCancellationActivities() {
$this->_setUpParticipantObjects('Pending from incomplete transaction');
$additionalParticipantId = $this->participantCreate([
Expand Down

0 comments on commit dca7262

Please sign in to comment.