Commit | Line | Data |
---|---|---|
5e3757e9 | 1 | <?php |
2 | ||
3 | /** | |
4 | * File for the TestActivityType class | |
5 | * | |
6 | * (PHP 5) | |
7 | * | |
6c6e6187 | 8 | * @package CiviCRM |
5e3757e9 | 9 | * |
10 | * This file is part of CiviCRM | |
11 | * | |
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. | |
16 | * | |
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. | |
21 | * | |
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/>. | |
25 | */ | |
26 | ||
27 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
28 | require_once 'CiviTest/Contact.php'; | |
29 | require_once 'CiviTest/Membership.php'; | |
30 | ||
31 | /** | |
32 | * Test CRM/Member/BAO Membership Log add , delete functions | |
33 | * | |
6c6e6187 | 34 | * @package CiviCRM |
5e3757e9 | 35 | */ |
36 | class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase { | |
5e3757e9 | 37 | /** |
38 | * Membership type name used in test function | |
39 | * @var String | |
40 | */ | |
41 | protected $_membershipTypeName = NULL; | |
42 | ||
43 | /** | |
44 | * Membership type id used in test function | |
45 | * @var String | |
46 | */ | |
47 | protected $_membershipTypeID = NULL; | |
5e3757e9 | 48 | |
00be9182 | 49 | public function setUp() { |
5e3757e9 | 50 | parent::setUp(); |
51 | ||
52 | $params = array( | |
53 | 'contact_type_a' => 'Individual', | |
54 | 'contact_type_b' => 'Organization', | |
55 | 'name_a_b' => 'Test Employee of', | |
56 | 'name_b_a' => 'Test Employer of', | |
57 | ); | |
58 | $this->_relationshipTypeId = $this->relationshipTypeCreate($params); | |
59 | $this->_orgContactID = $this->organizationCreate(); | |
e6ff1593 | 60 | $this->_financialTypeId = 1; |
5e3757e9 | 61 | $this->_membershipTypeName = 'Mickey Mouse Club Member'; |
62 | $params = array( | |
63 | 'name' => $this->_membershipTypeName, | |
64 | 'description' => NULL, | |
65 | 'minimum_fee' => 10, | |
66 | 'duration_unit' => 'year', | |
67 | 'member_of_contact_id' => $this->_orgContactID, | |
68 | 'period_type' => 'fixed', | |
69 | 'duration_interval' => 1, | |
e6ff1593 | 70 | 'financial_type_id' => $this->_financialTypeId, |
5e3757e9 | 71 | 'relationship_type_id' => $this->_relationshipTypeId, |
72 | 'visibility' => 'Public', | |
73 | 'is_active' => 1, | |
74 | 'fixed_period_start_day' => 101, | |
21dfd5f5 | 75 | 'fixed_period_rollover_day' => 1231, |
5e3757e9 | 76 | ); |
3e8ef36b | 77 | $ids = array(); |
5e3757e9 | 78 | $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids); |
79 | $this->_membershipTypeID = $membershipType->id; | |
80 | ||
81 | $this->_mebershipStatusID = $this->membershipStatusCreate('test status'); | |
82 | $session = CRM_Core_Session::singleton(); | |
83 | $session->set('dateTypes', 1); | |
84 | } | |
85 | ||
86 | /** | |
87 | * Tears down the fixture, for example, closes a network connection. | |
88 | * This method is called after a test is executed. | |
5e3757e9 | 89 | */ |
00be9182 | 90 | public function tearDown() { |
92915c55 TO |
91 | $tablesToTruncate = array( |
92 | 'civicrm_membership', | |
93 | 'civicrm_membership_log', | |
94 | 'civicrm_contribution', | |
408b79bf | 95 | 'civicrm_membership_payment', |
92915c55 | 96 | ); |
5e3757e9 | 97 | $this->quickCleanup($tablesToTruncate); |
98 | $this->relationshipTypeDelete($this->_relationshipTypeId); | |
99 | $this->membershipTypeDelete(array('id' => $this->_membershipTypeID)); | |
100 | $this->membershipStatusDelete($this->_mebershipStatusID); | |
5e3757e9 | 101 | $this->contactDelete($this->_orgContactID); |
102 | } | |
103 | ||
104 | /** | |
105 | * Test Import | |
106 | */ | |
00be9182 | 107 | public function testImport() { |
5e3757e9 | 108 | $contactId = $this->individualCreate(); |
109 | $contact2Params = array( | |
110 | 'first_name' => 'Anthonita', | |
111 | 'middle_name' => 'J.', | |
112 | 'last_name' => 'Anderson', | |
113 | 'prefix_id' => 3, | |
114 | 'suffix_id' => 3, | |
115 | 'email' => 'b@c.com', | |
116 | 'contact_type' => 'Individual', | |
117 | ); | |
118 | $contactId = $this->individualCreate($contact2Params); | |
119 | $year = date('Y') - 1; | |
120 | $startDate2 = date('Y-m-d', mktime(0, 0, 0, 9, 10, $year)); | |
121 | $params = array( | |
122 | array( | |
123 | 'anthony_anderson@civicrm.org', | |
92915c55 TO |
124 | $this->_membershipTypeID, |
125 | date('Y-m-d'), | |
5e3757e9 | 126 | ), |
127 | array( | |
128 | $contact2Params['email'], | |
129 | $this->_membershipTypeName, | |
130 | $startDate2, | |
131 | ), | |
132 | ); | |
133 | $fieldMapper = array( | |
134 | 'mapper[0][0]' => 'email', | |
135 | 'mapper[1][0]' => 'membership_type_id', | |
136 | 'mapper[2][0]' => 'membership_start_date', | |
137 | ); | |
6c6e6187 | 138 | /* |
5e3757e9 | 139 | |
140 | $params = array( | |
141 | 'contact_id' => $contactId, | |
142 | 'membership_type_id' => $this->_membershipTypeID, | |
143 | 'join_date' => '2006-01-21', | |
144 | 'start_date' => '2006-01-21', | |
145 | 'end_date' => '2006-12-21', | |
146 | 'source' => 'Payment', | |
147 | 'is_override' => 1, | |
148 | 'status_id' => $this->_mebershipStatusID, | |
149 | ); | |
150 | */ | |
151 | $importObject = new CRM_Member_Import_Parser_Membership($fieldMapper); | |
152 | $importObject->init(); | |
153 | $importObject->_contactType = 'Individual'; | |
154 | foreach ($params as $values) { | |
155 | $this->assertEquals(CRM_Import_Parser::VALID, $importObject->import(CRM_Import_Parser::DUPLICATE_UPDATE, $values), $values[0]); | |
156 | } | |
157 | $result = $this->callAPISuccess('membership', 'get', array()); | |
158 | $this->assertEquals(2, $result['count']); | |
159 | } | |
160 | } |