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