test failure fix2
[civicrm-core.git] / tests / phpunit / api / v3 / MembershipTypeTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27 */
28
29 require_once 'CiviTest/CiviUnitTestCase.php';
30
31 /**
32 * Class api_v3_MembershipTypeTest
33 */
34 class api_v3_MembershipTypeTest extends CiviUnitTestCase {
35 protected $_contactID;
36 protected $_contributionTypeID;
37 protected $_apiversion;
38 protected $_entity = 'MembershipType';
39
40 public function setUp() {
41 parent::setUp();
42 $this->useTransaction(TRUE);
43 $this->_apiversion = 3;
44 $this->_contactID = $this->organizationCreate(NULL);
45 }
46
47 public function testGetWithoutId() {
48 $params = array(
49 'name' => '60+ Membership',
50 'description' => 'people above 60 are given health instructions',
51 'financial_type_id' => 1,
52 'minimum_fee' => '200',
53 'duration_unit' => 'month',
54 'duration_interval' => '10',
55 'visibility' => 'public',
56 );
57
58 $membershiptype = $this->callAPISuccess('membership_type', 'get', $params);
59 $this->assertEquals($membershiptype['count'], 0);
60 }
61
62 public function testGet() {
63 $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID));
64
65 $params = array(
66 'id' => $id,
67 );
68 $membershiptype = $this->callAPIAndDocument('membership_type', 'get', $params, __FUNCTION__, __FILE__);
69 $this->assertEquals($membershiptype['values'][$id]['name'], 'General', 'In line ' . __LINE__ . " id is " . $id);
70 $this->assertEquals($membershiptype['values'][$id]['member_of_contact_id'], $this->_contactID, 'In line ' . __LINE__);
71 $this->assertEquals($membershiptype['values'][$id]['financial_type_id'], 1, 'In line ' . __LINE__);
72 $this->assertEquals($membershiptype['values'][$id]['duration_unit'], 'year', 'In line ' . __LINE__);
73 $this->assertEquals($membershiptype['values'][$id]['duration_interval'], '1', 'In line ' . __LINE__);
74 $this->assertEquals($membershiptype['values'][$id]['period_type'], 'rolling', 'In line ' . __LINE__);
75 $this->membershipTypeDelete($params);
76 }
77
78 ///////////////// civicrm_membership_type_create methods
79 public function testCreateWithEmptyParams() {
80 $membershiptype = $this->callAPIFailure('membership_type', 'create', array());
81 $this->assertEquals($membershiptype['error_message'],
82 'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name'
83 );
84 }
85
86 public function testCreateWithoutMemberOfContactId() {
87 $params = array(
88 'name' => '60+ Membership',
89 'description' => 'people above 60 are given health instructions',
90 'financial_type_id' => 1,
91 'domain_id' => '1',
92 'minimum_fee' => '200',
93 'duration_unit' => 'month',
94 'duration_interval' => '10',
95 'period_type' => 'rolling',
96 'visibility' => 'public',
97 );
98
99 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params,
100 'Mandatory key(s) missing from params array: member_of_contact_id'
101 );
102 }
103
104 public function testCreateWithoutContributionTypeId() {
105 $params = array(
106 'name' => '70+ Membership',
107 'description' => 'people above 70 are given health instructions',
108 'member_of_contact_id' => $this->_contactID,
109 'domain_id' => '1',
110 'minimum_fee' => '200',
111 'duration_unit' => 'month',
112 'duration_interval' => '10',
113 'period_type' => 'rolling',
114 'visibility' => 'public',
115 );
116 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
117 $this->assertEquals($membershiptype['error_message'],
118 'Mandatory key(s) missing from params array: financial_type_id'
119 );
120 }
121
122 public function testCreateWithoutDurationUnit() {
123 $params = array(
124 'name' => '80+ Membership',
125 'description' => 'people above 80 are given health instructions',
126 'member_of_contact_id' => $this->_contactID,
127 'financial_type_id' => 1,
128 'domain_id' => '1',
129 'minimum_fee' => '200',
130 'duration_interval' => '10',
131 'visibility' => 'public',
132 );
133
134 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
135 $this->assertEquals($membershiptype['error_message'],
136 'Mandatory key(s) missing from params array: duration_unit'
137 );
138 }
139
140 public function testCreateWithoutDurationInterval() {
141 $params = array(
142 'name' => '70+ Membership',
143 'description' => 'people above 70 are given health instructions',
144 'member_of_contact_id' => $this->_contactID,
145 'domain_id' => '1',
146 'minimum_fee' => '200',
147 'duration_unit' => 'month',
148 'period_type' => 'rolling',
149 'visibility' => 'public',
150 );
151 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
152 $this->assertEquals($membershiptype['error_message'],
153 'Mandatory key(s) missing from params array: financial_type_id, duration_interval'
154 );
155 }
156
157 public function testCreateWithoutNameandDomainIDandDurationUnit() {
158 $params = array(
159 'description' => 'people above 50 are given health instructions',
160 'member_of_contact_id' => $this->_contactID,
161 'financial_type_id' => 1,
162 'minimum_fee' => '200',
163 'duration_interval' => '10',
164 'period_type' => 'rolling',
165 'visibility' => 'public',
166 );
167
168 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
169 $this->assertEquals($membershiptype['error_message'],
170 'Mandatory key(s) missing from params array: domain_id, duration_unit, name'
171 );
172 }
173
174 public function testCreateWithoutName() {
175 $params = array(
176 'description' => 'people above 50 are given health instructions',
177 'member_of_contact_id' => $this->_contactID,
178 'financial_type_id' => 1,
179 'domain_id' => '1',
180 'minimum_fee' => '200',
181 'duration_unit' => 'month',
182 'duration_interval' => '10',
183 'period_type' => 'rolling',
184 'visibility' => 'public',
185 );
186
187 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
188 $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: name');
189 }
190
191 public function testCreate() {
192 $params = array(
193 'name' => '40+ Membership',
194 'description' => 'people above 40 are given health instructions',
195 'member_of_contact_id' => $this->_contactID,
196 'financial_type_id' => 1,
197 'domain_id' => '1',
198 'minimum_fee' => '200',
199 'duration_unit' => 'month',
200 'duration_interval' => '10',
201 'period_type' => 'rolling',
202 'visibility' => 'public',
203 );
204
205 $membershiptype = $this->callAPIAndDocument('membership_type', 'create', $params, __FUNCTION__, __FILE__);
206 $this->assertNotNull($membershiptype['values']);
207 $this->membershipTypeDelete(array('id' => $membershiptype['id']));
208 }
209
210
211 public function testUpdateWithEmptyParams() {
212 $params = array();
213 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
214 $this->assertEquals($membershiptype['error_message'],
215 'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name'
216 );
217 }
218
219 public function testUpdateWithoutId() {
220 $params = array(
221 'name' => '60+ Membership',
222 'description' => 'people above 60 are given health instructions',
223 'member_of_contact_id' => $this->_contactID,
224 'financial_type_id' => 1,
225 'minimum_fee' => '1200',
226 'duration_unit' => 'month',
227 'duration_interval' => '10',
228 'period_type' => 'rolling',
229 'visibility' => 'public',
230 );
231
232 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
233 $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: domain_id');
234 }
235
236 public function testUpdate() {
237 $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID, 'financial_type_id' => 2));
238 $newMembOrgParams = array(
239 'organization_name' => 'New membership organisation',
240 'contact_type' => 'Organization',
241 'visibility' => 1,
242 );
243
244 // create a new contact to update this membership type to
245 $newMembOrgID = $this->organizationCreate($newMembOrgParams);
246
247 $params = array(
248 'id' => $id,
249 'name' => 'Updated General',
250 'member_of_contact_id' => $newMembOrgID,
251 'duration_unit' => 'month',
252 'duration_interval' => '10',
253 'period_type' => 'fixed',
254 'domain_id' => 1,
255 );
256
257 $this->callAPISuccess('membership_type', 'update', $params);
258
259 $this->getAndCheck($params, $id, $this->_entity);
260 }
261
262 public function testDeleteNotExists() {
263 $params = array(
264 'id' => 'doesNotExist',
265 );
266 $membershiptype = $this->callAPIFailure('membership_type', 'delete', $params,
267 'Error while deleting membership type. id : ' . $params['id']
268 );
269 }
270
271 public function testDelete() {
272 $orgID = $this->organizationCreate(NULL);
273 $membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $orgID));
274 $params = array(
275 'id' => $membershipTypeID,
276 );
277
278 $result = $this->callAPIAndDocument('membership_type', 'delete', $params, __FUNCTION__, __FILE__);
279 }
280 }