Skip to content

Commit

Permalink
Merge pull request #17982 from eileenmcnaughton/isreceipt
Browse files Browse the repository at this point in the history
[Ref] Move noisily deprecate  BaseIPN->sendMail, call api from it rather than BAO function
  • Loading branch information
seamuslee001 authored Jul 31, 2020
2 parents b908c76 + 5909727 commit 2aec04e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 44 deletions.
19 changes: 6 additions & 13 deletions CRM/Core/Payment/BaseIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,21 +518,14 @@ public function getBillingID(&$ids) {
* @param array $ids
* Related object IDs.
* @param array $objects
* @param array $values
* Values related to objects that have already been loaded.
* @param bool $recur
* Is it part of a recurring contribution.
* @param bool $returnMessageText
* Should text be returned instead of sent. This.
* is because the function is also used to generate pdfs
*
* @return array
* @throws \CRM_Core_Exception
*
* @throws \CiviCRM_API3_Exception
*/
public function sendMail(&$input, &$ids, &$objects, &$values, $recur = FALSE, $returnMessageText = FALSE) {
return CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $objects['contribution']->id, $values,
$returnMessageText);
public function sendMail($input, $ids, $objects) {
CRM_Core_Error::deprecatedFunctionWarning('this should be done via completetransaction api');
civicrm_api3('Contribution', 'sendconfirmation', [
'id' => $objects['contribution']->id,
]);
}

}
70 changes: 39 additions & 31 deletions tests/phpunit/CRM/Core/Payment/BaseIPNTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ public function testLoadMembershipObjects() {
$this->_setUpMembershipObjects();
$this->_setUpRecurringContribution();
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$this->assertFalse(empty($this->objects['membership']));
$this->assertNotEmpty($this->objects['membership']);
$this->assertArrayHasKey($this->_membershipTypeID, $this->objects['membership']);
$this->assertTrue(is_a($this->objects['membership'][$this->_membershipTypeID], 'CRM_Member_BAO_Membership'));
$this->assertTrue(is_a($this->objects['financialType'], 'CRM_Financial_BAO_FinancialType'));
$this->assertFalse(empty($this->objects['contributionRecur']));
$this->assertFalse(empty($this->objects['paymentProcessor']));
$this->assertNotEmpty($this->objects['contributionRecur']);
$this->assertNotEmpty($this->objects['paymentProcessor']);
}

/**
Expand Down Expand Up @@ -144,7 +144,7 @@ public function testLoadMembershipObjectsLoadAll() {
$contribution->id = $this->_contributionId;
$contribution->find(TRUE);
$contribution->loadRelatedObjects($this->input, $this->ids, TRUE);
$this->assertFalse(empty($contribution->_relatedObjects['membership']));
$this->assertNotEmpty($contribution->_relatedObjects['membership']);
$this->assertArrayHasKey($this->_membershipTypeID, $contribution->_relatedObjects['membership']);
$this->assertTrue(is_a($contribution->_relatedObjects['membership'][$this->_membershipTypeID], 'CRM_Member_BAO_Membership'));
$this->assertTrue(is_a($contribution->_relatedObjects['financialType'], 'CRM_Financial_BAO_FinancialType'));
Expand All @@ -155,12 +155,13 @@ public function testLoadMembershipObjectsLoadAll() {
/**
* Test the LoadObjects function with recurring membership data.
*/
public function testsendMailMembershipObjects() {
public function testSendMailMembershipObjects() {
$this->_setUpMembershipObjects();
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $this->_contributionId;
$values = [];
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
$this->assertTrue(is_array($msg), "Message returned as an array in line");
$msg = $contribution->composeMessageArray($this->input, $this->ids, $values);
$this->assertInternalType('array', $msg, 'Message returned as an array in line');
$this->assertEquals('Mr. Anthony Anderson II', $msg['to']);
$this->assertContains('Membership Type: General', $msg['body']);
}
Expand All @@ -172,9 +173,10 @@ public function testsendMailMembershipObjects() {
*/
public function testSendMailMembershipObjectsNoLeakage() {
$this->_setUpMembershipObjects();
$contribution = new CRM_Contribute_BAO_Contribution();
$values = [];
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
$contribution->id = $this->_contributionId;
$msg = $contribution->composeMessageArray($this->input, $this->ids, $values);
$this->assertEquals('Mr. Anthony Anderson II', $msg['to']);
$this->assertContains('Membership Type: General', $msg['body']);

Expand All @@ -187,19 +189,22 @@ public function testSendMailMembershipObjectsNoLeakage() {
$this->input['invoiceID'] = 'abc';
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$this->assertEquals('Donald', $this->objects['contact']->first_name);
$msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $this->_contributionId;
$msg = $contribution->composeMessageArray($this->input, $this->ids, $values);
$this->assertEquals('Dr. Donald Duck II', $msg['to']);
$this->assertContains('Membership Type: Fowl', $msg['body']);
}

/**
* Test the LoadObjects function with recurring membership data.
*/
public function testsendMailMembershipWithoutLoadObjects() {
public function testSendMailMembershipWithoutLoadObjects() {
$this->_setUpMembershipObjects();
$values = [];
$msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
$this->assertTrue(is_array($msg), "Message returned as an array in line" . __LINE__);
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $this->_contributionId;
$msg = $contribution->composeMessageArray($this->input, $this->ids, $values);
$this->assertInternalType('array', $msg, 'Message not returned as an array');
$this->assertEquals('Mr. Anthony Anderson II', $msg['to']);
$this->assertContains('Membership Type: General', $msg['body']);
}
Expand All @@ -216,7 +221,7 @@ public function testLoadParticipantObjects() {
$this->assertFalse(empty($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->assertFalse(empty($this->objects['event']->id));
$this->assertNotEmpty($this->objects['event']->id);
}

/**
Expand All @@ -226,8 +231,10 @@ public function testComposeMailParticipant() {
$this->_setUpParticipantObjects();
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$values = [];
$this->assertFalse(empty($this->objects['event']));
$msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
$this->assertNotEmpty($this->objects['event']);
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $this->_contributionId;
$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 All @@ -236,22 +243,22 @@ public function testComposeMailParticipant() {
*/
public function testComposeMailParticipantObjects() {
$this->_setUpParticipantObjects();
$values = [];
$msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
$this->assertTrue(is_array($msg), "Message returned as an array in line" . __LINE__);
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $this->_contributionId;
$msg = $contribution->composeMessageArray($this->input, $this->ids, $values);
$this->assertEquals('Mr. Anthony Anderson II', $msg['to']);
$this->assertContains('Thank you for your registration', $msg['body']);
}

/**
* Test the LoadObjects function with recurring membership data.
*/
public function testsendMailParticipantObjectsCheckLog() {
public function testSendMailParticipantObjectsCheckLog() {
$this->_setUpParticipantObjects();
$values = [];
$mut = new CiviMailUtils($this, TRUE);
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, FALSE);
$this->callAPISuccess('Contribution', 'sendconfirmation', [
'id' => $this->_contributionId,
]);
$mut->checkMailLog([
'Thank you for your registration',
'Annual CiviCRM meet',
Expand All @@ -275,8 +282,9 @@ public function testsendMailParticipantObjectsNoMail() {
];
$this->quickCleanup($tablesToTruncate, FALSE);
$mut = new CiviMailUtils($this, TRUE);
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, $this->_processorId);
$this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, FALSE);
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $this->_contributionId;
$msg = $contribution->composeMessageArray($this->input, $this->ids, $values);
$mut->assertMailLogEmpty('no mail should have been send as event set to no confirm');
$mut->stop();
}
Expand Down Expand Up @@ -329,11 +337,11 @@ public function testLoadPledgeObjectsInvalidPledgeID() {
/**
* Test the LoadObjects function with a pledge.
*/
public function testsendMailPledge() {
public function testSendMailPledge() {
$this->_setUpPledgeObjects();
$values = [];
$this->IPN->loadObjects($this->input, $this->ids, $this->objects, FALSE, NULL);
$msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE);
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $this->_contributionId;
$msg = $contribution->composeMessageArray($this->input, $this->ids, $values);
$this->assertContains('Contribution Information', $msg['html']);
}

Expand Down

0 comments on commit 2aec04e

Please sign in to comment.