From 5e3757e9e16dedf87f8a730c4c537b2f8db33416 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 17 Jul 2013 21:46:59 +1200 Subject: [PATCH] CRM-13067 add membership import test --- .../Member/Import/Parser/MembershipTest.php | 170 ++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php diff --git a/tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php b/tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php new file mode 100644 index 0000000000..7ad1ae7bf6 --- /dev/null +++ b/tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php @@ -0,0 +1,170 @@ +. + */ + +require_once 'CiviTest/CiviUnitTestCase.php'; +require_once 'CiviTest/Contact.php'; +require_once 'CiviTest/Membership.php'; + +/** + * Test CRM/Member/BAO Membership Log add , delete functions + * + * @package CiviCRM + */ +class CRM_Member_Import_Parser_MembershipTest 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; + /** + * 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'); + $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->_orgContactID); + } + + /** + * Test Import + */ + function testImport() { + $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', + ); + $contactId = $this->individualCreate($contact2Params); + $year = date('Y') - 1; + $startDate2 = date('Y-m-d', mktime(0, 0, 0, 9, 10, $year)); + $params = array( + array( + 'anthony_anderson@civicrm.org', + $this->_membershipTypeID, + date('Y-m-d'), + ), + array( + $contact2Params['email'], + $this->_membershipTypeName, + $startDate2, + ), + ); + $fieldMapper = array( + 'mapper[0][0]' => 'email', + 'mapper[1][0]' => 'membership_type_id', + 'mapper[2][0]' => 'membership_start_date', + ); +/* + + $params = array( + 'contact_id' => $contactId, + 'membership_type_id' => $this->_membershipTypeID, + 'join_date' => '2006-01-21', + 'start_date' => '2006-01-21', + 'end_date' => '2006-12-21', + 'source' => 'Payment', + 'is_override' => 1, + 'status_id' => $this->_mebershipStatusID, + ); + */ + $importObject = new CRM_Member_Import_Parser_Membership($fieldMapper); + $importObject->init(); + $importObject->_contactType = 'Individual'; + foreach ($params as $values) { + $this->assertEquals(CRM_Import_Parser::VALID, $importObject->import(CRM_Import_Parser::DUPLICATE_UPDATE, $values), $values[0]); + } + $result = $this->callAPISuccess('membership', 'get', array()); + $this->assertEquals(2, $result['count']); + } +} + -- 2.25.1