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.
39 protected $_membershipTypeName = NULL;
42 * Membership type id used in test function.
46 protected $_membershipTypeID = NULL;
48 public function setUp() {
52 'contact_type_a' => 'Individual',
53 'contact_type_b' => 'Organization',
54 'name_a_b' => 'Test Employee of',
55 'name_b_a' => 'Test Employer of',
57 $this->_relationshipTypeId
= $this->relationshipTypeCreate($params);
58 $this->_orgContactID
= $this->organizationCreate();
59 $this->_financialTypeId
= 1;
60 $this->_membershipTypeName
= 'Mickey Mouse Club Member';
62 'name' => $this->_membershipTypeName
,
63 'description' => NULL,
65 'duration_unit' => 'year',
66 'member_of_contact_id' => $this->_orgContactID
,
67 'period_type' => 'fixed',
68 'duration_interval' => 1,
69 'financial_type_id' => $this->_financialTypeId
,
70 'relationship_type_id' => $this->_relationshipTypeId
,
71 'visibility' => 'Public',
73 'fixed_period_start_day' => 101,
74 'fixed_period_rollover_day' => 1231,
77 $membershipType = CRM_Member_BAO_MembershipType
::add($params, $ids);
78 $this->_membershipTypeID
= $membershipType->id
;
80 $this->_mebershipStatusID
= $this->membershipStatusCreate('test status');
81 $session = CRM_Core_Session
::singleton();
82 $session->set('dateTypes', 1);
86 * Tears down the fixture, for example, closes a network connection.
87 * This method is called after a test is executed.
89 public function tearDown() {
90 $tablesToTruncate = array(
92 'civicrm_membership_log',
93 'civicrm_contribution',
94 'civicrm_membership_payment',
96 $this->quickCleanup($tablesToTruncate);
97 $this->relationshipTypeDelete($this->_relationshipTypeId
);
98 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
99 $this->membershipStatusDelete($this->_mebershipStatusID
);
100 $this->contactDelete($this->_orgContactID
);
106 public function testImport() {
107 $this->individualCreate();
108 $contact2Params = array(
109 'first_name' => 'Anthonita',
110 'middle_name' => 'J.',
111 'last_name' => 'Anderson',
114 'email' => 'b@c.com',
115 'contact_type' => 'Individual',
118 $this->individualCreate($contact2Params);
119 $year = date('Y') - 1;
120 $startDate2 = date('Y-m-d', mktime(0, 0, 0, 9, 10, $year));
123 'anthony_anderson@civicrm.org',
124 $this->_membershipTypeID
,
128 $contact2Params['email'],
129 $this->_membershipTypeName
,
133 $fieldMapper = array(
134 'mapper[0][0]' => 'email',
135 'mapper[1][0]' => 'membership_type_id',
136 'mapper[2][0]' => 'membership_start_date',
139 $importObject = new CRM_Member_Import_Parser_Membership($fieldMapper);
140 $importObject->init();
141 $importObject->_contactType
= 'Individual';
142 foreach ($params as $values) {
143 $this->assertEquals(CRM_Import_Parser
::VALID
, $importObject->import(CRM_Import_Parser
::DUPLICATE_UPDATE
, $values), $values[0]);
145 $result = $this->callAPISuccess('membership', 'get', array());
146 $this->assertEquals(2, $result['count']);
149 public function testImportOverriddenMembershipButWithoutStatus() {
150 $this->individualCreate(array('email' => 'anthony_anderson2@civicrm.org'));
152 $fieldMapper = array(
153 'mapper[0][0]' => 'email',
154 'mapper[1][0]' => 'membership_type_id',
155 'mapper[2][0]' => 'membership_start_date',
156 'mapper[3][0]' => 'is_override',
158 $membershipImporter = new CRM_Member_Import_Parser_Membership($fieldMapper);
159 $membershipImporter->init();
160 $membershipImporter->_contactType
= 'Individual';
162 $importValues = array(
163 'anthony_anderson2@civicrm.org',
164 $this->_membershipTypeID
,
169 $importResponse = $membershipImporter->import(CRM_Import_Parser
::DUPLICATE_UPDATE
, $importValues);
170 $this->assertEquals(CRM_Import_Parser
::ERROR
, $importResponse);
171 $this->assertContains('Required parameter missing: Status', $importValues);
174 public function testImportOverriddenMembershipWithStatus() {
175 $this->individualCreate(array('email' => 'anthony_anderson3@civicrm.org'));
177 $fieldMapper = array(
178 'mapper[0][0]' => 'email',
179 'mapper[1][0]' => 'membership_type_id',
180 'mapper[2][0]' => 'membership_start_date',
181 'mapper[3][0]' => 'is_override',
182 'mapper[4][0]' => 'status_id',
184 $membershipImporter = new CRM_Member_Import_Parser_Membership($fieldMapper);
185 $membershipImporter->init();
186 $membershipImporter->_contactType
= 'Individual';
188 $importValues = array(
189 'anthony_anderson3@civicrm.org',
190 $this->_membershipTypeID
,
196 $importResponse = $membershipImporter->import(CRM_Import_Parser
::DUPLICATE_UPDATE
, $importValues);
197 $this->assertEquals(CRM_Import_Parser
::VALID
, $importResponse);
200 public function testImportOverriddenMembershipWithValidOverrideEndDate() {
201 $this->individualCreate(array('email' => 'anthony_anderson4@civicrm.org'));
203 $fieldMapper = array(
204 'mapper[0][0]' => 'email',
205 'mapper[1][0]' => 'membership_type_id',
206 'mapper[2][0]' => 'membership_start_date',
207 'mapper[3][0]' => 'is_override',
208 'mapper[4][0]' => 'status_id',
209 'mapper[5][0]' => 'status_override_end_date',
211 $membershipImporter = new CRM_Member_Import_Parser_Membership($fieldMapper);
212 $membershipImporter->init();
213 $membershipImporter->_contactType
= 'Individual';
215 $importValues = array(
216 'anthony_anderson4@civicrm.org',
217 $this->_membershipTypeID
,
224 $importResponse = $membershipImporter->import(CRM_Import_Parser
::DUPLICATE_UPDATE
, $importValues);
225 $this->assertEquals(CRM_Import_Parser
::VALID
, $importResponse);
228 public function testImportOverriddenMembershipWithInvalidOverrideEndDate() {
229 $this->individualCreate(array('email' => 'anthony_anderson5@civicrm.org'));
231 $fieldMapper = array(
232 'mapper[0][0]' => 'email',
233 'mapper[1][0]' => 'membership_type_id',
234 'mapper[2][0]' => 'membership_start_date',
235 'mapper[3][0]' => 'is_override',
236 'mapper[4][0]' => 'status_id',
237 'mapper[5][0]' => 'status_override_end_date',
239 $membershipImporter = new CRM_Member_Import_Parser_Membership($fieldMapper);
240 $membershipImporter->init();
241 $membershipImporter->_contactType
= 'Individual';
243 $importValues = array(
244 'anthony_anderson5@civicrm.org',
248 $this->_mebershipStatusID
,
252 $importResponse = $membershipImporter->import(CRM_Import_Parser
::DUPLICATE_UPDATE
, $importValues);
253 $this->assertEquals(CRM_Import_Parser
::ERROR
, $importResponse);
254 $this->assertContains('Required parameter missing: Status', $importValues);