4 * File for the TestActivityType class
10 * This file is part of CiviCRM
12 * CiviCRM is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Affero General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
17 * CiviCRM is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Affero General Public License for more details.
22 * You should have received a copy of the GNU Affero General Public
23 * License along with this program. If not, see
24 * <http://www.gnu.org/licenses/>.
28 * Test CRM/Member/BAO Membership Log add , delete functions
33 class CRM_Member_Import_Parser_MembershipTest
extends CiviUnitTestCase
{
35 * Membership type name used in test function.
38 protected $_membershipTypeName = NULL;
41 * Membership type id used in test function.
44 protected $_membershipTypeID = NULL;
46 public function setUp() {
50 'contact_type_a' => 'Individual',
51 'contact_type_b' => 'Organization',
52 'name_a_b' => 'Test Employee of',
53 'name_b_a' => 'Test Employer of',
55 $this->_relationshipTypeId
= $this->relationshipTypeCreate($params);
56 $this->_orgContactID
= $this->organizationCreate();
57 $this->_financialTypeId
= 1;
58 $this->_membershipTypeName
= 'Mickey Mouse Club Member';
60 'name' => $this->_membershipTypeName
,
61 'description' => NULL,
63 'duration_unit' => 'year',
64 'member_of_contact_id' => $this->_orgContactID
,
65 'period_type' => 'fixed',
66 'duration_interval' => 1,
67 'financial_type_id' => $this->_financialTypeId
,
68 'relationship_type_id' => $this->_relationshipTypeId
,
69 'visibility' => 'Public',
71 'fixed_period_start_day' => 101,
72 'fixed_period_rollover_day' => 1231,
75 $membershipType = CRM_Member_BAO_MembershipType
::add($params, $ids);
76 $this->_membershipTypeID
= $membershipType->id
;
78 $this->_mebershipStatusID
= $this->membershipStatusCreate('test status');
79 $session = CRM_Core_Session
::singleton();
80 $session->set('dateTypes', 1);
84 * Tears down the fixture, for example, closes a network connection.
85 * This method is called after a test is executed.
87 public function tearDown() {
88 $tablesToTruncate = array(
90 'civicrm_membership_log',
91 'civicrm_contribution',
92 'civicrm_membership_payment',
94 $this->quickCleanup($tablesToTruncate);
95 $this->relationshipTypeDelete($this->_relationshipTypeId
);
96 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
97 $this->membershipStatusDelete($this->_mebershipStatusID
);
98 $this->contactDelete($this->_orgContactID
);
104 public function testImport() {
105 $this->individualCreate();
106 $contact2Params = array(
107 'first_name' => 'Anthonita',
108 'middle_name' => 'J.',
109 'last_name' => 'Anderson',
112 'email' => 'b@c.com',
113 'contact_type' => 'Individual',
116 $this->individualCreate($contact2Params);
117 $year = date('Y') - 1;
118 $startDate2 = date('Y-m-d', mktime(0, 0, 0, 9, 10, $year));
121 'anthony_anderson@civicrm.org',
122 $this->_membershipTypeID
,
126 $contact2Params['email'],
127 $this->_membershipTypeName
,
131 $fieldMapper = array(
132 'mapper[0][0]' => 'email',
133 'mapper[1][0]' => 'membership_type_id',
134 'mapper[2][0]' => 'membership_start_date',
137 $importObject = new CRM_Member_Import_Parser_Membership($fieldMapper);
138 $importObject->init();
139 $importObject->_contactType
= 'Individual';
140 foreach ($params as $values) {
141 $this->assertEquals(CRM_Import_Parser
::VALID
, $importObject->import(CRM_Import_Parser
::DUPLICATE_UPDATE
, $values), $values[0]);
143 $result = $this->callAPISuccess('membership', 'get', array());
144 $this->assertEquals(2, $result['count']);
147 public function testImportOverriddenMembershipButWithoutStatus() {
148 $this->individualCreate(array('email' => 'anthony_anderson2@civicrm.org'));
150 $fieldMapper = array(
151 'mapper[0][0]' => 'email',
152 'mapper[1][0]' => 'membership_type_id',
153 'mapper[2][0]' => 'membership_start_date',
154 'mapper[3][0]' => 'is_override',
156 $membershipImporter = new CRM_Member_Import_Parser_Membership($fieldMapper);
157 $membershipImporter->init();
158 $membershipImporter->_contactType
= 'Individual';
160 $importValues = array(
161 'anthony_anderson2@civicrm.org',
162 $this->_membershipTypeID
,
167 $importResponse = $membershipImporter->import(CRM_Import_Parser
::DUPLICATE_UPDATE
, $importValues);
168 $this->assertEquals(CRM_Import_Parser
::ERROR
, $importResponse);
169 $this->assertContains('Required parameter missing: Status', $importValues);
172 public function testImportOverriddenMembershipWithStatus() {
173 $this->individualCreate(array('email' => 'anthony_anderson3@civicrm.org'));
175 $fieldMapper = array(
176 'mapper[0][0]' => 'email',
177 'mapper[1][0]' => 'membership_type_id',
178 'mapper[2][0]' => 'membership_start_date',
179 'mapper[3][0]' => 'is_override',
180 'mapper[4][0]' => 'status_id',
182 $membershipImporter = new CRM_Member_Import_Parser_Membership($fieldMapper);
183 $membershipImporter->init();
184 $membershipImporter->_contactType
= 'Individual';
186 $importValues = array(
187 'anthony_anderson3@civicrm.org',
188 $this->_membershipTypeID
,
194 $importResponse = $membershipImporter->import(CRM_Import_Parser
::DUPLICATE_UPDATE
, $importValues);
195 $this->assertEquals(CRM_Import_Parser
::VALID
, $importResponse);
198 public function testImportOverriddenMembershipWithValidOverrideEndDate() {
199 $this->individualCreate(array('email' => 'anthony_anderson4@civicrm.org'));
201 $fieldMapper = array(
202 'mapper[0][0]' => 'email',
203 'mapper[1][0]' => 'membership_type_id',
204 'mapper[2][0]' => 'membership_start_date',
205 'mapper[3][0]' => 'is_override',
206 'mapper[4][0]' => 'status_id',
207 'mapper[5][0]' => 'status_override_end_date',
209 $membershipImporter = new CRM_Member_Import_Parser_Membership($fieldMapper);
210 $membershipImporter->init();
211 $membershipImporter->_contactType
= 'Individual';
213 $importValues = array(
214 'anthony_anderson4@civicrm.org',
215 $this->_membershipTypeID
,
222 $importResponse = $membershipImporter->import(CRM_Import_Parser
::DUPLICATE_UPDATE
, $importValues);
223 $this->assertEquals(CRM_Import_Parser
::VALID
, $importResponse);
226 public function testImportOverriddenMembershipWithInvalidOverrideEndDate() {
227 $this->individualCreate(array('email' => 'anthony_anderson5@civicrm.org'));
229 $fieldMapper = array(
230 'mapper[0][0]' => 'email',
231 'mapper[1][0]' => 'membership_type_id',
232 'mapper[2][0]' => 'membership_start_date',
233 'mapper[3][0]' => 'is_override',
234 'mapper[4][0]' => 'status_id',
235 'mapper[5][0]' => 'status_override_end_date',
237 $membershipImporter = new CRM_Member_Import_Parser_Membership($fieldMapper);
238 $membershipImporter->init();
239 $membershipImporter->_contactType
= 'Individual';
241 $importValues = array(
242 'anthony_anderson5@civicrm.org',
246 $this->_mebershipStatusID
,
250 $importResponse = $membershipImporter->import(CRM_Import_Parser
::DUPLICATE_UPDATE
, $importValues);
251 $this->assertEquals(CRM_Import_Parser
::ERROR
, $importResponse);
252 $this->assertContains('Required parameter missing: Status', $importValues);