CRM-17519 add test to (fail to) demonstrate leakage
authoreileen <emcnaughton@wikimedia.org>
Wed, 25 Nov 2015 11:26:17 +0000 (00:26 +1300)
committereileenmcnaugton <eileen@fuzion.co.nz>
Wed, 25 Nov 2015 22:07:51 +0000 (11:07 +1300)
tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php
tests/phpunit/CiviTest/CiviMailUtils.php
tests/phpunit/CiviTest/CiviUnitTestCase.php

index b8c1a1ff1a68c8e9f4eb2e23233a913098bcace6..aef2a788dca0bec886aa07f7d6ea73b71cf93ff2 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 require_once 'CiviTest/CiviUnitTestCase.php';
+require_once 'CiviTest/CiviMailUtils.php';
 
 /**
  * Class CRM_Core_Payment_PayPalProIPNTest
@@ -23,6 +24,10 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase {
       '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'];
   }
@@ -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" <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" => "",
@@ -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);
   }
 
   /**
index 1f365db7964aaa5a0daf1173b21bf089fd3157e5..0584d7565013a762c9730560b843e28d3a4c563b 100644 (file)
@@ -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;
+  }
+
 }
index 631dfc530a2515f7a6449eec75e73baf6a1bf954..1400c9bdffd93d060115c7c1c90b3687ef5dae6f 100755 (executable)
@@ -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,
+    ));
+  }
+
 }