Just a test.
authoreileen <emcnaughton@wikimedia.org>
Fri, 7 Sep 2018 08:01:08 +0000 (20:01 +1200)
committereileen <emcnaughton@wikimedia.org>
Fri, 7 Sep 2018 08:07:05 +0000 (20:07 +1200)
I was trying to replicate something & failed but adding the test

tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php

index a4c3946247e0a074cd6a9285d5b0059f825f335e..57ab7a7e3e054ee052a3d2ec303be378c6ef51d0 100644 (file)
  +--------------------------------------------------------------------+
  */
 
-/**
- *  File for the MembershipTest class
- *
- *  (PHP 5)
- *
- * @author Walt Haas <walt@dharmatech.org> (801) 534-1262
- */
-
 /**
  *  Test CRM_Member_Form_Membership functions.
  *
@@ -81,6 +73,12 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase {
    */
   protected $paymentInstruments = array();
 
+
+  /**
+   * @var CiviMailUtils
+   */
+  protected $mut;
+
   /**
    * Test setup for every test.
    *
@@ -307,7 +305,7 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase {
    */
   public function testSubmitRecurCompleteInstant() {
     $form = $this->getForm();
-
+    /** @var \CRM_Core_Payment_Dummy $processor */
     $processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID);
     $processor->setDoDirectPaymentResult(array(
       'payment_status_id' => 1,
@@ -355,15 +353,57 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase {
 
     $this->assertEquals('kettles boil water', $contribution['trxn_id']);
     $this->assertEquals(.29, $contribution['fee_amount']);
-    $this->assertEquals(78, $contribution['total_amount']);
-    $this->assertEquals(77.71, $contribution['net_amount']);
+    $this->assertEquals(7800.90, $contribution['total_amount']);
+    $this->assertEquals(7800.61, $contribution['net_amount']);
 
     $this->callAPISuccessGetCount('LineItem', array(
       'entity_id' => $membership['id'],
       'entity_table' => 'civicrm_membership',
       'contribution_id' => $contribution['id'],
     ), 1);
+  }
+
+  /**
+   * Test the submit function of the membership form.
+   *
+   * @param string $thousandSeparator
+   *
+   * @dataProvider getThousandSeparators
+   */
+  public function testSubmitRecurCompleteInstantWithMail($thousandSeparator) {
+    $this->setCurrencySeparators($thousandSeparator);
+    $form = $this->getForm();
+    $this->mut = new CiviMailUtils($this, TRUE);
+    /** @var \CRM_Core_Payment_Dummy $processor */
+    $processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID);
+    $processor->setDoDirectPaymentResult(array(
+      'payment_status_id' => 1,
+      'trxn_id' => 'kettles boil water',
+      'fee_amount' => .29,
+    ));
+
+    $this->callAPISuccess('MembershipType', 'create', array(
+      'id' => $this->membershipTypeAnnualFixedID,
+      'duration_unit' => 'month',
+      'duration_interval' => 1,
+      'auto_renew' => TRUE,
+    ));
+    $this->createLoggedInUser();
+    $form->preProcess();
+
+    $form->_contactID = $this->_individualId;
+    $params = $this->getBaseSubmitParams();
+    $params['send_receipt'] = 1;
+    $form->_mode = 'test';
 
+    $form->testSubmit($params);
+    $contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', array('contact_id' => $this->_individualId));
+    $this->assertEquals(1, $contributionRecur['is_email_receipt']);
+    $this->mut->checkMailLog([
+      '$ ' . $this->formatMoneyInput(7800.90)
+    ]);
+    $this->mut->stop();
+    $this->setCurrencySeparators(',');
   }
 
   /**
@@ -570,7 +610,7 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase {
       'max_related' => 0,
       'num_terms' => '1',
       'source' => '',
-      'total_amount' => '78.00',
+      'total_amount' => $this->formatMoneyInput('7800.90'),
       'financial_type_id' => '2', //Member dues, see data.xml
       'soft_credit_type_id' => 11,
       'soft_credit_contact_id' => '',