<?php
require_once 'CiviTest/CiviUnitTestCase.php';
+require_once 'CiviTest/CiviMailUtils.php';
/**
* Class CRM_Core_Payment_PayPalProIPNTest
'financial_type_id' => $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'];
}
}
/**
+ * 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" <anthony_anderson@civicrm.org>',
+ '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" => "",
"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',
'x_response_reason_text' => 'This transaction has been approved.',
'x_response_reason_code' => '1',
'x_response_code' => '1',
- );
+ ), $params);
}
/**
*/
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);
}
/**
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;
+ }
+
}
'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,
));
}
+ /**
+ * 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,
+ ));
+ }
+
}