tests/phpunit - Declare `@group headless`
[civicrm-core.git] / tests / phpunit / CRM / Member / Form / MembershipTest.php
index 3c88f645154e74b3ed3d6e6f5893cf80971fd652..ce9291ba50a8e2c9c29974e9ccb87fce8337d0d5 100644 (file)
  * @author Walt Haas <walt@dharmatech.org> (801) 534-1262
  */
 
-/**
- *  Include class definitions
- */
-require_once 'CiviTest/CiviUnitTestCase.php';
-
-require_once 'HTML/QuickForm/Page.php';
-
 /**
  *  Test CRM_Member_Form_Membership functions.
  *
  * @package   CiviCRM
+ * @group headless
  */
 class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
 
@@ -98,8 +92,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
     parent::setUp();
 
     $this->_individualId = $this->individualCreate();
-    $processor = $this->processorCreate();
-    $this->_paymentProcessorID = $processor->id;
+    $this->_paymentProcessorID = $this->processorCreate();
     // Insert test data.
     $op = new PHPUnit_Extensions_Database_Operation_Insert();
     $op->execute($this->_dbconn,
@@ -468,7 +461,8 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
       'billing_postal_code-5' => '90210',
       'billing_country_id-5' => '1228',
     );
-    $form->submit($params);
+    $form->_contactID = $this->_individualId;
+    $form->testSubmit($params);
     $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
     $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 0);
     $contribution = $this->callAPISuccess('Contribution', 'get', array(
@@ -499,8 +493,8 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
     $this->createLoggedInUser();
     $params = $this->getBaseSubmitParams();
     $form->_mode = 'test';
-
-    $form->submit($params);
+    $form->_contactID = $this->_individualId;
+    $form->testSubmit($params);
     $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
     $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 1);
 
@@ -517,14 +511,77 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
     ), 1);
   }
 
+  /**
+   * Test the submit function of the membership form.
+   */
+  public function testSubmitPayLaterWithBilling() {
+    $form = $this->getForm(NULL);
+    $this->createLoggedInUser();
+    $params = array(
+      'cid' => $this->_individualId,
+      'join_date' => date('m/d/Y', time()),
+      'start_date' => '',
+      'end_date' => '',
+      // This format reflects the 23 being the organisation & the 25 being the type.
+      'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID),
+      'auto_renew' => '0',
+      'max_related' => '',
+      'num_terms' => '2',
+      'source' => '',
+      'total_amount' => '50.00',
+      //Member dues, see data.xml
+      'financial_type_id' => '2',
+      'soft_credit_type_id' => '',
+      'soft_credit_contact_id' => '',
+      'payment_instrument_id' => 4,
+      'from_email_address' => '"Demonstrators Anonymous" <info@example.org>',
+      'receipt_text_signup' => 'Thank you text',
+      'payment_processor_id' => $this->_paymentProcessorID,
+      'record_contribution' => TRUE,
+      'trxn_id' => 777,
+      'contribution_status_id' => 2,
+      'billing_first_name' => 'Test',
+      'billing_middlename' => 'Last',
+      'billing_street_address-5' => '10 Test St',
+      'billing_city-5' => 'Test',
+      'billing_state_province_id-5' => '1003',
+      'billing_postal_code-5' => '90210',
+      'billing_country_id-5' => '1228',
+    );
+    $form->_contactID = $this->_individualId;
+
+    $form->testSubmit($params);
+    $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
+    $contribution = $this->callAPISuccessGetSingle('Contribution', array(
+      'contact_id' => $this->_individualId,
+      'contribution_status_id' => 2,
+    ));
+    $this->assertEquals($contribution['trxn_id'], 777);
+
+    $this->callAPISuccessGetCount('LineItem', array(
+      'entity_id' => $membership['id'],
+      'entity_table' => 'civicrm_membership',
+      'contribution_id' => $contribution['id'],
+    ), 1);
+    $this->callAPISuccessGetSingle('address', array(
+      'contact_id' => $this->_individualId,
+      'street_address' => '10 Test St',
+      'postal_code' => 90210,
+    ));
+  }
+
   /**
    * Test the submit function of the membership form.
    */
   public function testSubmitRecurCompleteInstant() {
     $form = $this->getForm();
-
+    $mut = new CiviMailUtils($this, TRUE);
     $processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID);
-    $processor->setDoDirectPaymentResult(array('payment_status_id' => 1, 'trxn_id' => 'kettles boil water'));
+    $processor->setDoDirectPaymentResult(array(
+      'payment_status_id' => 1,
+      'trxn_id' => 'kettles boil water',
+      'fee_amount' => .14,
+    ));
     $this->callAPISuccess('MembershipType', 'create', array(
       'id' => $this->membershipTypeAnnualFixedID,
       'duration_unit' => 'month',
@@ -535,21 +592,46 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
     $this->createLoggedInUser();
     $params = $this->getBaseSubmitParams();
     $form->_mode = 'test';
-
-    $form->submit($params);
+    $form->_contactID = $this->_individualId;
+    $form->testSubmit($params);
     $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
     $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 1);
 
-    $contribution = $this->callAPISuccess('Contribution', 'get', array(
+    $contribution = $this->callAPISuccess('Contribution', 'getsingle', array(
       'contact_id' => $this->_individualId,
       'is_test' => TRUE,
     ));
 
+    $this->assertEquals(.14, $contribution['fee_amount']);
+    $this->assertEquals('kettles boil water', $contribution['trxn_id']);
+
     $this->callAPISuccessGetCount('LineItem', array(
       'entity_id' => $membership['id'],
       'entity_table' => 'civicrm_membership',
       'contribution_id' => $contribution['id'],
     ), 1);
+    $mut->checkMailLog(array(
+        '===========================================================
+Billing Name and Address
+===========================================================
+Test
+10 Test St
+Test, AR 90210
+US',
+        '===========================================================
+Membership Information
+===========================================================
+Membership Type: AnnualFixed
+Membership Start Date: ',
+        '===========================================================
+Credit Card Information
+===========================================================
+Visa
+************1111
+Expires: ',
+      )
+    );
+    $mut->stop();
 
   }
 
@@ -607,6 +689,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
       'billing_state_province_id-5' => '1003',
       'billing_postal_code-5' => '90210',
       'billing_country_id-5' => '1228',
+      'send_receipt' => 1,
     );
     return $params;
   }