Action schedule API modifications
[civicrm-core.git] / tests / phpunit / api / v3 / MembershipTypeTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
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 class api_v3_MembershipTypeTest extends CiviUnitTestCase {
31 protected $_contactID;
32 protected $_contributionTypeID;
33 protected $_apiversion;
34 protected $_entity = 'MembershipType';
35 public $_eNoticeCompliant = TRUE;
36
37 function get_info() {
38 return array(
39 'name' => 'MembershipType Create',
40 'description' => 'Test all Membership Type Create API methods.',
41 'group' => 'CiviCRM API Tests',
42 );
43 }
44
45 function setUp() {
46 parent::setUp();
47 $this->_apiversion = 3;
48 $this->_contactID = $this->organizationCreate(NULL);
49 }
50
51 function tearDown() {
52 $tablesToTruncate = array('civicrm_contact');
53 $this->quickCleanup($tablesToTruncate);
54 }
55
56 function testGetWithoutId() {
57 $params = array(
58 'name' => '60+ Membership',
59 'description' => 'people above 60 are given health instructions',
60 'financial_type_id' => 1,
61 'minimum_fee' => '200',
62 'duration_unit' => 'month',
63 'duration_interval' => '10',
64 'visibility' => 'public',
65 );
66
67 $membershiptype = $this->callAPISuccess('membership_type', 'get', $params);
68 $this->assertEquals($membershiptype['count'], 0);
69 }
70
71 function testGet() {
72 $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID));
73
74 $params = array(
75 'id' => $id,
76 );
77 $membershiptype = $this->callAPIAndDocument('membership_type', 'get', $params, __FUNCTION__, __FILE__);
78 $this->assertEquals($membershiptype['values'][$id]['name'], 'General', 'In line ' . __LINE__ . " id is " . $id);
79 $this->assertEquals($membershiptype['values'][$id]['member_of_contact_id'], $this->_contactID, 'In line ' . __LINE__);
80 $this->assertEquals($membershiptype['values'][$id]['financial_type_id'], 1, 'In line ' . __LINE__);
81 $this->assertEquals($membershiptype['values'][$id]['duration_unit'], 'year', 'In line ' . __LINE__);
82 $this->assertEquals($membershiptype['values'][$id]['duration_interval'], '1', 'In line ' . __LINE__);
83 $this->assertEquals($membershiptype['values'][$id]['period_type'], 'rolling', 'In line ' . __LINE__);
84 $this->membershipTypeDelete($params);
85 }
86
87 ///////////////// civicrm_membership_type_create methods
88 function testCreateWithEmptyParams() {
89 $membershiptype = $this->callAPIFailure('membership_type', 'create', array());
90 $this->assertEquals($membershiptype['error_message'],
91 'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name'
92 );
93 }
94
95 function testCreateWithoutMemberOfContactId() {
96 $params = array(
97 'name' => '60+ Membership',
98 'description' => 'people above 60 are given health instructions',
99 'financial_type_id' => 1,
100 'domain_id' => '1',
101 'minimum_fee' => '200',
102 'duration_unit' => 'month',
103 'duration_interval' => '10',
104 'period_type' => 'rolling',
105 'visibility' => 'public',
106 );
107
108 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params,
109 'Mandatory key(s) missing from params array: member_of_contact_id'
110 );
111 }
112
113 function testCreateWithoutContributionTypeId() {
114 $params = array(
115 'name' => '70+ Membership',
116 'description' => 'people above 70 are given health instructions',
117 'member_of_contact_id' => $this->_contactID,
118 'domain_id' => '1',
119 'minimum_fee' => '200',
120 'duration_unit' => 'month',
121 'duration_interval' => '10',
122 'period_type' => 'rolling',
123 'visibility' => 'public', );
124 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
125 $this->assertEquals($membershiptype['error_message'],
126 'Mandatory key(s) missing from params array: financial_type_id'
127 );
128 }
129
130 function testCreateWithoutDurationUnit() {
131 $params = array(
132 'name' => '80+ Membership',
133 'description' => 'people above 80 are given health instructions',
134 'member_of_contact_id' => $this->_contactID,
135 'financial_type_id' => 1,
136 'domain_id' => '1',
137 'minimum_fee' => '200',
138 'duration_interval' => '10',
139 'visibility' => 'public', );
140
141 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
142 $this->assertEquals($membershiptype['error_message'],
143 'Mandatory key(s) missing from params array: duration_unit'
144 );
145 }
146
147 function testCreateWithoutDurationInterval() {
148 $params = array(
149 'name' => '70+ Membership',
150 'description' => 'people above 70 are given health instructions',
151 'member_of_contact_id' => $this->_contactID,
152 'domain_id' => '1',
153 'minimum_fee' => '200',
154 'duration_unit' => 'month',
155 'period_type' => 'rolling',
156 'visibility' => 'public', );
157 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
158 $this->assertEquals($membershiptype['error_message'],
159 'Mandatory key(s) missing from params array: financial_type_id, duration_interval'
160 );
161 }
162
163 function testCreateWithoutNameandDomainIDandDurationUnit() {
164 $params = array(
165 'description' => 'people above 50 are given health instructions',
166 'member_of_contact_id' => $this->_contactID,
167 'financial_type_id' => 1,
168 'minimum_fee' => '200',
169 'duration_interval' => '10',
170 'period_type' => 'rolling',
171 'visibility' => 'public', );
172
173 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
174 $this->assertEquals($membershiptype['error_message'],
175 'Mandatory key(s) missing from params array: domain_id, duration_unit, name'
176 );
177 }
178
179 function testCreateWithoutName() {
180 $params = array(
181 'description' => 'people above 50 are given health instructions',
182 'member_of_contact_id' => $this->_contactID,
183 'financial_type_id' => 1,
184 'domain_id' => '1',
185 'minimum_fee' => '200',
186 'duration_unit' => 'month',
187 'duration_interval' => '10',
188 'period_type' => 'rolling',
189 'visibility' => 'public', );
190
191 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
192 $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: name');
193 }
194
195 function testCreate() {
196 $params = array(
197 'name' => '40+ Membership',
198 'description' => 'people above 40 are given health instructions',
199 'member_of_contact_id' => $this->_contactID,
200 'financial_type_id' => 1,
201 'domain_id' => '1',
202 'minimum_fee' => '200',
203 'duration_unit' => 'month',
204 'duration_interval' => '10',
205 'period_type' => 'rolling',
206 'visibility' => 'public',
207 );
208
209 $membershiptype = $this->callAPIAndDocument('membership_type', 'create', $params, __FUNCTION__, __FILE__);
210 $this->assertNotNull($membershiptype['values']);
211 $this->membershipTypeDelete(array('id' => $membershiptype['id']));
212 }
213
214
215 function testUpdateWithEmptyParams() {
216 $params = array();
217 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
218 $this->assertEquals($membershiptype['error_message'],
219 'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name'
220 );
221 }
222
223 function testUpdateWithoutId() {
224 $params = array(
225 'name' => '60+ Membership',
226 'description' => 'people above 60 are given health instructions',
227 'member_of_contact_id' => $this->_contactID,
228 'financial_type_id' => 1,
229 'minimum_fee' => '1200',
230 'duration_unit' => 'month',
231 'duration_interval' => '10',
232 'period_type' => 'rolling',
233 'visibility' => 'public', );
234
235 $membershiptype = $this->callAPIFailure('membership_type', 'create', $params);
236 $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: domain_id');
237 }
238
239 function testUpdate() {
240 $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID, 'financial_type_id' => 2));
241 $newMembOrgParams = array(
242 'organization_name' => 'New membership organisation',
243 'contact_type' => 'Organization',
244 'visibility' => 1, );
245
246 // create a new contact to update this membership type to
247 $newMembOrgID = $this->organizationCreate($newMembOrgParams);
248
249 $params = array(
250 'id' => $id,
251 'name' => 'Updated General',
252 'member_of_contact_id' => $newMembOrgID,
253 'duration_unit' => 'month',
254 'duration_interval' => '10',
255 'period_type' => 'fixed',
256 'domain_id' => 1, );
257
258 $this->callAPISuccess('membership_type', 'update', $params);
259
260 $this->getAndCheck($params, $id, $this->_entity);
261 }
262
263 function testDeleteNotExists() {
264 $params = array(
265 'id' => 'doesNotExist',
266 );
267 $membershiptype = $this->callAPIFailure('membership_type', 'delete', $params,
268 'Error while deleting membership type. id : ' . $params['id']
269 );
270 }
271
272 function testDelete() {
273 $orgID = $this->organizationCreate(NULL);
274 $membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $orgID));
275 $params = array(
276 'id' => $membershipTypeID,
277 );
278
279 $result = $this->callAPIAndDocument('membership_type', 'delete', $params, __FUNCTION__, __FILE__);
280 }
281 }
282