3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
29 class api_v3_MembershipStatusTest
extends CiviUnitTestCase
{
31 protected $_contactID;
32 protected $_contributionTypeID;
33 protected $_membershipTypeID;
34 protected $_membershipStatusID;
36 protected $_apiversion =3;
43 'name' => 'MembershipStatus Calc',
44 'description' => 'Test all MembershipStatus Calc API methods.',
45 'group' => 'CiviCRM API Tests',
51 $this->_contactID
= $this->individualCreate();
52 $this->_membershipTypeID
= $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID
));
53 $this->_membershipStatusID
= $this->membershipStatusCreate('test status');
55 CRM_Member_PseudoConstant
::membershipType($this->_membershipTypeID
, TRUE);
56 CRM_Member_PseudoConstant
::membershipStatus(NULL, NULL, 'name', TRUE);
60 $this->membershipStatusDelete($this->_membershipStatusID
);
61 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
62 $this->contactDelete($this->_contactID
);
65 ///////////////// civicrm_membership_status_get methods
69 * Test civicrm_membership_status_get with empty params
71 function testGetEmptyParams() {
72 $result = $this->callAPISuccess('membership_status', 'get', array());
73 // It should be 8 statuses, 7 default from mysql_data
74 // plus one test status added in setUp
75 $this->assertEquals(8, $result['count']);
79 * Test civicrm_membership_status_get. Success expected.
83 'name' => 'test status',
85 $result = $this->callAPIAndDocument('membership_status', 'get', $params, __FUNCTION__
, __FILE__
);
86 $this->assertEquals($result['values'][$this->_membershipStatusID
]['name'], "test status", "In line " . __LINE__
);
90 * Test civicrm_membership_status_get. Success expected.
92 function testGetLimit() {
93 $result = $this->callAPISuccess('membership_status', 'get', array());
94 $this->assertGreaterThan(1, $result['count'], "Check more than one exists In line " . __LINE__
);
95 $params['option.limit'] = 1;
96 $result = $this->callAPISuccess('membership_status', 'get', $params);
97 $this->assertEquals(1, $result['count'], "Check only 1 retrieved " . __LINE__
);
100 function testCreateDuplicateName() {
101 $params = array('name' => 'name');
102 $result = $this->callAPISuccess('membership_status', 'create', $params);
103 $result = $this->callAPIFailure('membership_status', 'create', $params,
104 'A membership status with this name already exists.'
108 function testCreateWithMissingRequired() {
109 $params = array('title' => 'Does not make sense');
110 $result = $this->callAPIFailure('membership_status', 'create', $params);
113 function testCreate() {
115 'name' => 'test membership status',
117 $result = $this->callAPIAndDocument('membership_status', 'create', $params, __FUNCTION__
, __FILE__
);
119 $this->assertNotNull($result['id']);
120 $this->membershipStatusDelete($result['id']);
123 function testUpdate() {
125 'name' => 'test membership status', );
126 $result = $this->callAPISuccess('membership_status', 'create', $params);
128 $result = $this->callAPISuccess('membership_status', 'get', $params);
129 $this->assertEquals('test membership status', $result['values'][$id]['name']);
132 'name' => 'renamed', );
133 $result = $this->callAPISuccess('membership_status', 'create', $newParams);
134 $result = $this->callAPISuccess('membership_status', 'get', array('id' => $id));
135 $this->assertEquals('renamed', $result['values'][$id]['name']);
136 $this->membershipStatusDelete($result['id']);
140 ///////////////// civicrm_membership_status_delete methods
141 function testDeleteEmptyParams() {
142 $result = $this->callAPIFailure('membership_status', 'delete', array());
145 function testDeleteWithMissingRequired() {
146 $params = array('title' => 'Does not make sense');
147 $result = $this->callAPIFailure('membership_status', 'delete', $params);
150 function testDelete() {
151 $membershipID = $this->membershipStatusCreate();
153 'id' => $membershipID,
155 $result = $this->callAPISuccess('membership_status', 'delete', $params);
158 * Test that trying to delete membership status while membership still exists creates error
160 function testDeleteWithMembershipError() {
161 $membershipStatusID = $this->membershipStatusCreate();
162 $this->_contactID
= $this->individualCreate();
163 $this->_entity
= 'membership';
165 'contact_id' => $this->_contactID
,
166 'membership_type_id' => $this->_membershipTypeID
,
167 'join_date' => '2009-01-21',
168 'start_date' => '2009-01-21',
169 'end_date' => '2009-12-21',
170 'source' => 'Payment',
172 'status_id' => $membershipStatusID,
175 $result = $this->callAPISuccess('membership', 'create', $params);
176 $membershipID = $result['id'];
179 'id' => $membershipStatusID,
181 $result = $this->callAPIFailure('membership_status', 'delete', $params);
183 $this->callAPISuccess('Membership', 'Delete', array(
184 'id' => $membershipID,
186 $result = $this->callAPISuccess('membership_status', 'delete', $params);