INFRA-132 - Fix misc oddball syntax
[civicrm-core.git] / tests / phpunit / CRM / Batch / Form / EntryTest.php
index 5eba99d7c310fcba1e7341dd913b61c6f477150f..c19d8114510eae1d7f948b8b272a91f264e8b0d8 100644 (file)
@@ -5,7 +5,7 @@
  *
  *  (PHP 5)
  *
- *   @package   CiviCRM
+ * @package   CiviCRM
  *
  *   This file is part of CiviCRM
  *
@@ -30,11 +30,10 @@ require_once 'CiviTest/CiviUnitTestCase.php';
 /**
  *  Test CRM/Member/BAO Membership Log add , delete functions
  *
- *  @package   CiviCRM
+ * @package   CiviCRM
  */
 class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
 
-  public $_eNoticeCompliant = TRUE;
   /**
    * Membership type name used in test function
    * @var String
@@ -57,19 +56,20 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
    * @var String
    */
   protected $_contactID2 = NULL;
+
   /**
-   * Describe test class
-   * @return array
+   * Contact id used in test function
+   * @var String
    */
-  function get_info() {
-    return array(
-      'name' => 'MembershipParserTest',
-      'description' => 'Test import parser function',
-      'group' => 'CiviCRM BAO Tests',
-    );
-  }
+  protected $_contactID3 = NULL;
 
-  function setUp() {
+  /**
+   * Contact id used in test function
+   * @var String
+   */
+  protected $_contactID4 = NULL;
+
+  public function setUp() {
     parent::setUp();
 
     $params = array(
@@ -95,12 +95,13 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
       'visibility' => 'Public',
       'is_active' => 1,
       'fixed_period_start_day' => 101,
-      'fixed_period_rollover_day' => 1231
+      'fixed_period_rollover_day' => 1231,
+      'domain_id' => CRM_Core_Config::domainID(),
     );
-    $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
-    $this->_membershipTypeID = $membershipType->id;
+    $membershipType = $this->callAPISuccess('membership_type', 'create', $params);
+    $this->_membershipTypeID = $membershipType['id'];
 
-    $this->_mebershipStatusID = $this->membershipStatusCreate('test status');
+    $this->_membershipStatusID = $this->membershipStatusCreate('test status');
     $this->_contactID = $this->individualCreate();
     $contact2Params = array(
       'first_name' => 'Anthonita',
@@ -112,8 +113,12 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
       'contact_type' => 'Individual',
     );
     $this->_contactID2 = $this->individualCreate($contact2Params);
+    $this->_contactID3 = $this->individualCreate(array('first_name' => 'bobby', 'email' => 'c@d.com'));
+    $this->_contactID4 = $this->individualCreate(array('first_name' => 'bobbynita', 'email' => 'c@de.com'));
+
     $session = CRM_Core_Session::singleton();
     $session->set('dateTypes', 1);
+    $this->_sethtmlGlobals();
 
   }
 
@@ -122,12 +127,14 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
    * This method is called after a test is executed.
    *
    */
-  function tearDown() {
-    $tablesToTruncate = array('civicrm_membership', 'civicrm_membership_log', 'civicrm_contribution', 'civicrm_membership_payment');
-    $this->quickCleanup($tablesToTruncate);
+  public function tearDown()
+  {
+    $this->quickCleanUpFinancialEntities();
     $this->relationshipTypeDelete($this->_relationshipTypeId);
-    $this->membershipTypeDelete(array('id' => $this->_membershipTypeID));
-    $this->membershipStatusDelete($this->_mebershipStatusID);
+    if ($this->callAPISuccessGetCount('membership', array('id' => $this->_membershipTypeID))) {
+      $this->membershipTypeDelete(array('id' => $this->_membershipTypeID));
+    }
+    $this->membershipStatusDelete($this->_membershipStatusID);
     $this->contactDelete($this->_contactID);
     $this->contactDelete($this->_contactID2);
     $this->contactDelete($this->_orgContactID);
@@ -136,31 +143,71 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
   /**
    *  Test Import
    */
-  function testProcessMembership() {
+  public function testProcessMembership() {
     $form = new CRM_Batch_Form_Entry();
     $params = $this->getMembershipData();
     $this->assertTrue($form->testProcessMembership($params));
     $result = $this->callAPISuccess('membership', 'get', array());
-    $this->assertEquals(2, $result['count']);
+    $this->assertEquals(3, $result['count']);
+    //check start dates #1 should default to 1 Jan this year, #2 should be as entered
+    $this->assertEquals(date('Y-m-d', strtotime('first day of January 2013')), $result['values'][1]['start_date']);
+    $this->assertEquals('2013-02-03', $result['values'][2]['start_date']);
+
+    //check start dates #1 should default to 1 Jan this year, #2 should be as entered
+    $this->assertEquals(date('Y-m-d', strtotime('last day of December 2013')), $result['values'][1]['end_date']);
+    $this->assertEquals(date('Y-m-d', strtotime('last day of December 2013')), $result['values'][2]['end_date']);
+    $this->assertEquals('2013-12-01', $result['values'][3]['end_date']);
+
+    //check start dates #1 should default to 1 Jan this year, #2 should be as entered
+    $this->assertEquals(date('Y-m-d', strtotime('07/22/2013')), $result['values'][1]['join_date']);
+    $this->assertEquals(date('Y-m-d', strtotime('07/03/2013')), $result['values'][2]['join_date']);
+    $this->assertEquals(date('Y-m-d', strtotime('now')), $result['values'][3]['join_date']);
+    $result = $this->callAPISuccess('contribution', 'get', array('return' => 'total_amount'));
+    $this->assertEquals(3, $result['count']);
+    foreach ($result['values'] as $contribution) {
+      $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', array(
+        'contribution_id' => $contribution['id'],
+        'return' => 'line_total',
+
+      )), $contribution['total_amount']);
+    }
   }
 
-  /*
-   * data provider for test process membership
+  /**
+   *  Test Contribution Import
    */
-  function getMembershipData() {
+  public function testProcessContribution() {
+    $this->offsetDefaultPriceSet();
+    $form = new CRM_Batch_Form_Entry();
+    $params = $this->getContributionData();
+    $this->assertTrue($form->testProcessContribution($params));
+    $result = $this->callAPISuccess('contribution', 'get', array('return' => 'total_amount'));
+    $this->assertEquals(2, $result['count']);
+    foreach ($result['values'] as $contribution) {
+      $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', array(
+       'contribution_id' => $contribution['id'],
+       'return' => 'line_total',
 
-    /*
-     Array (
+      )), $contribution['total_amount']);
+    }
+  }
+  /**
+   * Data provider for test process membership
+   * @return array
+   */
+  public function getMembershipData() {
 
-    );
-    */
     return array(
       'batch_id' => 4,
-      'primary_profiles' => array(1 => NULL, 2 => NULL),
-      'primary_contact_select_id' => Array (1 => $this->_contactID, 2 => $this->_contactID2),
+      'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL),
+      'primary_contact_id' => array(
+        1 => $this->_contactID,
+        2 => $this->_contactID2,
+        3 => $this->_contactID3,
+        ),
       'field' => array(
         1 => array(
-          'membership_type' => Array (0 => 1, 1 => 1),// (I was unable to determine what these both mean but both are refered to in code
+          'membership_type' => array(0 => $this->_orgContactID, 1 => $this->_membershipTypeID),
           'join_date' => '07/22/2013',
           'membership_start_date' => NULL,
           'membership_end_date' => NULL,
@@ -174,9 +221,9 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
           'contribution_status_id' => 1,
         ),
       2 => array(
-        'membership_type' => Array (0 => 1, 1 => 1 ),
+        'membership_type' => array(0 => $this->_orgContactID, 1 => $this->_membershipTypeID),
         'join_date' => '07/03/2013',
-        'membership_start_date' => NULL,
+        'membership_start_date' => '02/03/2013',
         'membership_end_date' => NULL,
         'membership_source' => NULL,
         'financial_type' => 2,
@@ -186,10 +233,63 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
         'payment_instrument' => NULL,
         'check_number' => NULL,
         'contribution_status_id' => 1,
-       )
+       ),
+        // no join date, coded end date
+       3 => array(
+         'membership_type' => array(0 => $this->_orgContactID, 1 => $this->_membershipTypeID),
+         'join_date' => NULL,
+         'membership_start_date' => NULL,
+         'membership_end_date' => '2013-12-01',
+         'membership_source' => NULL,
+         'financial_type' => 2,
+         'total_amount' => 1,
+         'receive_date' => '07/17/2013',
+         'receive_date_time' => NULL,
+         'payment_instrument' => NULL,
+         'check_number' => NULL,
+         'contribution_status_id' => 1,
+       ),
+
       ),
       'actualBatchTotal' => 0,
+
     );
   }
-}
 
+  /**
+   * @return array
+   */
+  public function getContributionData() {
+    return array(
+      //'batch_id' => 4,
+      'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL),
+      'primary_contact_id' => array(
+        1 => $this->_contactID,
+        2 => $this->_contactID2,
+        3 => $this->_contactID3,
+      ),
+      'field' => array(
+        1 => array(
+          'financial_type' => 1,
+          'total_amount' => 15,
+          'receive_date' => '07/24/2013',
+          'receive_date_time' => NULL,
+          'payment_instrument' => 1,
+          'check_number' => NULL,
+          'contribution_status_id' => 1,
+        ),
+        2 => array(
+          'financial_type' => 1,
+          'total_amount' => 15,
+          'receive_date' => '07/24/2013',
+          'receive_date_time' => NULL,
+          'payment_instrument' => 1,
+          'check_number' => NULL,
+          'contribution_status_id' => 1,
+        ),
+      ),
+      'actualBatchTotal' => 30,
+
+    );
+  }
+}