From: eileen Date: Wed, 25 Nov 2015 08:36:28 +0000 (+1300) Subject: CRM-17519 add test to catch any leakage at IPN level X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c3543e4a2c9ea22d84abedcf95f3d18caa4eb008;p=civicrm-core.git CRM-17519 add test to catch any leakage at IPN level --- diff --git a/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php b/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php index e06eefc2ba..98d594bc39 100644 --- a/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/BaseIPNTest.php @@ -49,6 +49,16 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { protected $input; protected $ids; protected $objects; + + /** + * @var int + */ + protected $_membershipTypeID; + + /** + * @var int + */ + protected $_membershipStatusID; public $DBResetRequired = FALSE; public function setUp() { @@ -63,7 +73,6 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { $this->_contributionParams = array( 'contact_id' => $this->_contactId, - 'version' => 3, 'financial_type_id' => $this->_financialTypeId, 'receive_date' => date('Ymd'), 'total_amount' => 150.00, @@ -102,6 +111,24 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { $this->assertFalse(empty($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(array('first_name' => 'Donald', 'last_name' => 'Duck', 'email' => 'the-don@duckville.com')); + $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_contributionParams, array('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. */ @@ -135,6 +162,33 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { $this->assertContains('Membership Type: General', $msg['body']); } + /** + * Test the LoadObjects function data does not leak. + * + * If more than one iteration takes place the variables should not leak. + */ + public function testSendMailMembershipObjectsNoLeakage() { + $this->_setUpMembershipObjects(); + $values = array(); + $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->assertEquals('Mr. Anthony Anderson II', $msg['to']); + $this->assertContains('Membership Type: General', $msg['body']); + + $this->ids['contact'] = $this->_contactId = $this->individualCreate(array('prefix_id' => 'Dr.', 'first_name' => 'Donald', 'last_name' => 'Duck', 'email' => 'the-don@duckville.com')); + $contribution = $this->callAPISuccess('contribution', 'create', array_merge($this->_contributionParams, array('invoice_id' => 'abc'))); + $this->_contributionId = $contribution['id']; + + $this->_membershipTypeID = $this->membershipTypeCreate(array('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); + $msg = $this->IPN->sendMail($this->input, $this->ids, $this->objects, $values, FALSE, TRUE); + $this->assertEquals('Dr. Donald Duck II', $msg['to']); + $this->assertContains('Membership Type: Fowl', $msg['body']); + } + /** * Test the LoadObjects function with recurring membership data. */ @@ -459,8 +513,12 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { */ public function _setUpMembershipObjects() { try { - $this->_membershipTypeID = $this->membershipTypeCreate(); - $this->_membershipStatusID = $this->membershipStatusCreate('test status'); + if (!$this->_membershipTypeID) { + $this->_membershipTypeID = $this->membershipTypeCreate(); + } + if (!$this->_membershipStatusID) { + $this->_membershipStatusID = $this->membershipStatusCreate('test status'); + } } catch (Exception$e) { echo $e->getMessage(); @@ -480,7 +538,12 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { ); $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 = array('contribution' => $contribution); + } $this->_membershipId = $membership['id']; //we'll create membership payment here because to make setup more re-usable $this->callAPISuccess('membership_payment', 'create', array( @@ -493,7 +556,7 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase { 'total_amount' => 150.00, 'invoiceID' => "c8acb91e080ad7bd8a2adc119c192885", 'contactID' => $this->_contactId, - 'contributionID' => $this->objects['contribution']->id, + 'contributionID' => $this->_contributionId, 'membershipID' => $this->_membershipId, );