From 481312d9c47ee5ef4d87dc3d753299ea1757f2e4 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 26 Nov 2015 00:26:17 +1300 Subject: [PATCH] CRM-17519 add test to (fail to) demonstrate leakage --- .../CRM/Core/Payment/AuthorizeNetIPNTest.php | 70 +++++++++++++++++-- tests/phpunit/CiviTest/CiviMailUtils.php | 42 +++++++++-- tests/phpunit/CiviTest/CiviUnitTestCase.php | 20 +++++- 3 files changed, 120 insertions(+), 12 deletions(-) diff --git a/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php b/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php index b8c1a1ff1a..aef2a788dc 100644 --- a/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php @@ -1,6 +1,7 @@ $this->_financialTypeID, 'currency' => 'USD', 'payment_processor' => $this->_paymentProcessorID, + 'max_amount' => 1000, + 'receipt_from_email' => 'gaia@the.cosmos', + 'receipt_from_name' => 'Pachamama', + 'is_email_receipt' => TRUE, )); $this->_contributionPageID = $contributionPage['id']; } @@ -85,9 +90,66 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { } /** + * Test IPN response mails don't leak. */ - public function getRecurTransaction() { - return array( + public function testIPNPaymentMembershipRecurSuccessNoLeakage() { + $mut = new CiviMailUtils($this, TRUE); + $this->setupMembershipRecurringPaymentProcessorTransaction(array('is_email_receipt' => TRUE)); + $this->addProfile('supporter_profile', $this->_contributionPageID); + $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction()); + $IPN->main(); + $mut->checkAllMailLog(array( + 'Membership Type: General', + 'Mr. Anthony Anderson II" ', + 'Amount: $ 200.00', + 'Membership Start Date:', + 'Supporter Profile', + 'First Name: Anthony', + 'Last Name: Anderson', + 'Email Address: anthony_anderson@civicrm.org', + 'This membership will be automatically renewed every', + 'Dear Mr. Anthony Anderson II', + 'Thanks for your auto renew membership sign-up', + )); + $mut->clearMessages(); + $this->_contactID = $this->individualCreate(array('first_name' => 'Antonia', 'prefix_id' => 'Mrs.', 'email' => 'antonia_anderson@civicrm.org')); + $this->_invoiceID = uniqid(); + + $this->setupMembershipRecurringPaymentProcessorTransaction(array('is_email_receipt' => TRUE)); + $IPN = new CRM_Core_Payment_AuthorizeNetIPN($this->getRecurTransaction(array('x_trans_id' => 'hers'))); + $IPN->main(); + + $mut->checkAllMailLog(array( + 'Membership Type: General', + 'Mrs. Antonia Anderson II', + 'antonia_anderson@civicrm.org', + 'Amount: $ 200.00', + 'Membership Start Date:', + 'Transaction #: hers', + 'Supporter Profile', + 'First Name: Antonia', + 'Last Name: Anderson', + 'Email Address: antonia_anderson@civicrm.org', + 'This membership will be automatically renewed every', + 'Dear Mrs. Antonia Anderson II', + 'Thanks for your auto renew membership sign-up', + )); + + $mut->stop(); + $mut->clearMessages(); + } + + /** + * Get detail for recurring transaction. + * + * @param array $params + * Additional parameters. + * + * @return array + * Parameters like AuthorizeNet silent post paramters. + */ + public function getRecurTransaction($params = array()) { + return array_merge(array( "x_amount" => "200.00", "x_country" => 'US', "x_phone" => "", @@ -112,7 +174,7 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { "x_cvv2_resp_code" => "", "x_cavv_response" => "", "x_test_request" => "false", - "x_subscription_id" => $this->_contributionRecurID, + "x_subscription_id" => $this->_contactID, "x_subscription_paynum" => "1", 'x_first_name' => 'Robert', 'x_zip' => '90210', @@ -132,7 +194,7 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { 'x_response_reason_text' => 'This transaction has been approved.', 'x_response_reason_code' => '1', 'x_response_code' => '1', - ); + ), $params); } /** diff --git a/tests/phpunit/CiviTest/CiviMailUtils.php b/tests/phpunit/CiviTest/CiviMailUtils.php index 1f365db796..0584d75650 100644 --- a/tests/phpunit/CiviTest/CiviMailUtils.php +++ b/tests/phpunit/CiviTest/CiviMailUtils.php @@ -260,13 +260,24 @@ class CiviMailUtils extends PHPUnit_Framework_TestCase { */ public function checkMailLog($strings, $absentStrings = array(), $prefix = '') { $mail = $this->getMostRecentEmail('raw'); - foreach ($strings as $string) { - $this->_ut->assertContains($string, $mail, "$string . not found in $mail $prefix"); - } - foreach ($absentStrings as $string) { - $this->_ut->assertEmpty(strstr($mail, $string), "$string incorrectly found in $mail $prefix");; - } - return $mail; + return $this->checkMailForStrings($strings, $absentStrings, $prefix, $mail); + } + + /** + * Check contents of mail log. + * + * @param array $strings + * Strings that should be included. + * @param array $absentStrings + * Strings that should not be included. + * @param string $prefix + * + * @return \ezcMail|string + */ + public function checkAllMailLog($strings, $absentStrings = array(), $prefix = '') { + $mails = $this->getAllMessages('raw'); + $mail = implode(',', $mails); + return $this->checkMailForStrings($strings, $absentStrings, $prefix, $mail); } /** @@ -350,4 +361,21 @@ class CiviMailUtils extends PHPUnit_Framework_TestCase { return $mail[0]; } + /** + * @param $strings + * @param $absentStrings + * @param $prefix + * @param $mail + * @return mixed + */ + public function checkMailForStrings($strings, $absentStrings, $prefix, $mail) { + foreach ($strings as $string) { + $this->_ut->assertContains($string, $mail, "$string . not found in $mail $prefix"); + } + foreach ($absentStrings as $string) { + $this->_ut->assertEmpty(strstr($mail, $string), "$string incorrectly found in $mail $prefix");; + } + return $mail; + } + } diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 631dfc530a..1400c9bdff 100755 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -3187,7 +3187,9 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) 'frequency_interval' => 1, 'invoice_id' => $this->_invoiceID, 'contribution_status_id' => 2, - 'processor_id' => $this->_paymentProcessorID, + 'payment_processor_id' => $this->_paymentProcessorID, + // processor provided ID - use contact ID as proxy. + 'processor_id' => $this->_contactID, 'api.contribution.create' => array( 'total_amount' => '200', 'invoice_id' => $this->_invoiceID, @@ -3384,4 +3386,20 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) return $priceSetId; } + /** + * Add a profile to a contribution page. + * + * @param string $name + * @param int $contributionPageID + */ + protected function addProfile($name, $contributionPageID) { + $this->callAPISuccess('UFJoin', 'create', array( + 'uf_group_id' => $name, + 'module' => 'CiviContribute', + 'entity_table' => 'civicrm_contribution_page', + 'entity_id' => $contributionPageID, + 'weight' => 1, + )); + } + } -- 2.25.1