From afe349ef2c17cd615e20d7d0957de387384536a7 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 22 Jul 2013 17:42:39 +1200 Subject: [PATCH] CRM-13067 add test on membership batch entry --- CRM/Batch/Form/Entry.php | 21 ++- CRM/Contact/Form/Task/Batch.php | 5 + tests/phpunit/CRM/Batch/Form/EntryTest.php | 196 +++++++++++++++++++++ 3 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/CRM/Batch/Form/EntryTest.php diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php index b4cde294b5..e135ec2b26 100644 --- a/CRM/Batch/Form/Entry.php +++ b/CRM/Batch/Form/Entry.php @@ -76,6 +76,15 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { */ protected $_contactFields = array(); + /** + * Fields array of fields in the batch profile + * (based on the uf_field table data) + * (this can't be protected as it is passed into the CRM_Contact_Form_Task_Batch::parseStreetAddress function + * (although a future refactoring might hopefully change that so it uses the api & the function is not + * required + * @var array + */ + public $_fields = array(); /** * build all the data structures needed to build the form * @@ -602,7 +611,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { } // handle soft credit - if (CRM_Utils_Array::value($key, $params['soft_credit_contact_select_id']) && CRM_Utils_Array::value($key, $params['soft_credit_amount'])) { + if (is_array(CRM_Utils_Array::value('soft_credit_contact_select_id', $params)) && CRM_Utils_Array::value($key, $params['soft_credit_contact_select_id']) && CRM_Utils_Array::value($key, $params['soft_credit_amount'])) { $value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_select_id'][$key]; $value['soft_credit'][$key]['amount'] = CRM_Utils_Rule::cleanMoney($params['soft_credit_amount'][$key]); } @@ -726,6 +735,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { } } } + return TRUE; } /** @@ -747,5 +757,14 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { $value['contact_id'] ); } + /** + * Function exists purely for unit testing purposes. If you feel tempted to use this in live code + * then it probably means there is some functionality that needs to be moved + * out of the form layer + * @param unknown_type $params + */ + function testProcessMembership($params) { + return $this->processMembership($params); + } } diff --git a/CRM/Contact/Form/Task/Batch.php b/CRM/Contact/Form/Task/Batch.php index e86a1f3b18..d5ce99e284 100644 --- a/CRM/Contact/Form/Task/Batch.php +++ b/CRM/Contact/Form/Task/Batch.php @@ -289,6 +289,11 @@ class CRM_Contact_Form_Task_Batch extends CRM_Contact_Form_Task { } //end of function + /** + * parse street address + * @param unknown_type $contactValues + * @param unknown_type $form + */ function parseStreetAddress(&$contactValues, &$form) { if (!is_array($contactValues) || !is_array($form->_fields) diff --git a/tests/phpunit/CRM/Batch/Form/EntryTest.php b/tests/phpunit/CRM/Batch/Form/EntryTest.php new file mode 100644 index 0000000000..d408d2237c --- /dev/null +++ b/tests/phpunit/CRM/Batch/Form/EntryTest.php @@ -0,0 +1,196 @@ +. + */ + +require_once 'CiviTest/CiviUnitTestCase.php'; + + +/** + * Test CRM/Member/BAO Membership Log add , delete functions + * + * @package CiviCRM + */ +class CRM_Batch_Form_EntryTest extends CiviUnitTestCase { + + public $_eNoticeCompliant = TRUE; + /** + * Membership type name used in test function + * @var String + */ + protected $_membershipTypeName = NULL; + + /** + * Membership type id used in test function + * @var String + */ + protected $_membershipTypeID = NULL; + + /** + * Contact id used in test function + * @var String + */ + protected $_contactID = NULL; + /** + * Contact id used in test function + * @var String + */ + protected $_contactID2 = NULL; + /** + * Describe test class + * @return array + */ + function get_info() { + return array( + 'name' => 'MembershipParserTest', + 'description' => 'Test import parser function', + 'group' => 'CiviCRM BAO Tests', + ); + } + + function setUp() { + parent::setUp(); + + $params = array( + 'contact_type_a' => 'Individual', + 'contact_type_b' => 'Organization', + 'name_a_b' => 'Test Employee of', + 'name_b_a' => 'Test Employer of', + ); + $this->_relationshipTypeId = $this->relationshipTypeCreate($params); + $this->_orgContactID = $this->organizationCreate(); + $this->_contributionTypeId = $this->contributionTypeCreate(); + $this->_membershipTypeName = 'Mickey Mouse Club Member'; + $params = array( + 'name' => $this->_membershipTypeName, + 'description' => NULL, + 'minimum_fee' => 10, + 'duration_unit' => 'year', + 'member_of_contact_id' => $this->_orgContactID, + 'period_type' => 'fixed', + 'duration_interval' => 1, + 'financial_type_id' => $this->_contributionTypeId, + 'relationship_type_id' => $this->_relationshipTypeId, + 'visibility' => 'Public', + 'is_active' => 1, + 'fixed_period_start_day' => 101, + 'fixed_period_rollover_day' => 1231 + ); + $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids); + $this->_membershipTypeID = $membershipType->id; + + $this->_mebershipStatusID = $this->membershipStatusCreate('test status'); + $this->_contactID = $this->individualCreate(); + $contact2Params = array( + 'first_name' => 'Anthonita', + 'middle_name' => 'J.', + 'last_name' => 'Anderson', + 'prefix_id' => 3, + 'suffix_id' => 3, + 'email' => 'b@c.com', + 'contact_type' => 'Individual', + ); + $this->_contactID2 = $this->individualCreate($contact2Params); + $session = CRM_Core_Session::singleton(); + $session->set('dateTypes', 1); + + } + + /** + * Tears down the fixture, for example, closes a network connection. + * 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); + $this->relationshipTypeDelete($this->_relationshipTypeId); + $this->membershipTypeDelete(array('id' => $this->_membershipTypeID)); + $this->membershipStatusDelete($this->_mebershipStatusID); + $this->contributionTypeDelete(NULL); + $this->contactDelete($this->_contactID); + $this->contactDelete($this->_contactID2); + $this->contactDelete($this->_orgContactID); + } + + /** + * Test Import + */ + 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']); + } + + /* + * data provider for test process membership + */ + function getMembershipData() { + + /* + Array ( + + ); + */ + return array( + 'batch_id' => 4, + 'primary_profiles' => array(1 => NULL, 2 => NULL), + 'primary_contact_select_id' => Array (1 => $this->_contactID, 2 => $this->_contactID2), + '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 + 'join_date' => '07/22/2013', + 'membership_start_date' => NULL, + 'membership_end_date' => NULL, + 'membership_source' => NULL, + 'financial_type' => 2, + 'total_amount' => 1, + 'receive_date' => '07/24/2013', + 'receive_date_time' => NULL, + 'payment_instrument' => 1, + 'check_number' => NULL, + 'contribution_status_id' => 1, + ), + 2 => array( + 'membership_type' => Array (0 => 1, 1 => 1 ), + 'join_date' => '07/03/2013', + 'membership_start_date' => NULL, + 'membership_end_date' => NULL, + '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, + ); + } +} + -- 2.25.1