From: eileen Date: Wed, 25 Nov 2015 11:26:17 +0000 (+1300) Subject: CRM-17519 add test to (fail to) demonstrate leakage X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=03a8656c19a45f20449b9dac93c34980128544f3;p=civicrm-core.git CRM-17519 add test to (fail to) demonstrate leakage --- 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 ff9767786e..d70d0ee183 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); } /** @@ -329,4 +340,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 66a45add0b..9d8a751c9f 100755 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -3237,7 +3237,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, @@ -3382,4 +3384,65 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) )); } + /** + * Create a price set for an event. + * + * @param int $feeTotal + * + * @return int + * Price Set ID. + */ + protected function eventPriceSetCreate($feeTotal) { + // creating price set, price field + $paramsSet['title'] = 'Price Set'; + $paramsSet['name'] = CRM_Utils_String::titleToVar('Price Set'); + $paramsSet['is_active'] = FALSE; + $paramsSet['extends'] = 1; + + $priceset = CRM_Price_BAO_PriceSet::create($paramsSet); + $priceSetId = $priceset->id; + + //Checking for priceset added in the table. + $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', + 'id', $paramsSet['title'], 'Check DB for created priceset' + ); + $paramsField = array( + 'label' => 'Price Field', + 'name' => CRM_Utils_String::titleToVar('Price Field'), + 'html_type' => 'Text', + 'price' => $feeTotal, + 'option_label' => array('1' => 'Price Field'), + 'option_value' => array('1' => $feeTotal), + 'option_name' => array('1' => $feeTotal), + 'option_weight' => array('1' => 1), + 'option_amount' => array('1' => 1), + 'is_display_amounts' => 1, + 'weight' => 1, + 'options_per_line' => 1, + 'is_active' => array('1' => 1), + 'price_set_id' => $priceset->id, + 'is_enter_qty' => 1, + 'financial_type_id' => CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', 'Event Fee', 'id', 'name'), + ); + CRM_Price_BAO_PriceField::create($paramsField); + + 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, + )); + } + }