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';
31 * Class api_v3_MembershipStatusTest
33 class api_v3_MembershipStatusTest
extends CiviUnitTestCase
{
35 protected $_contactID;
36 protected $_contributionTypeID;
37 protected $_membershipTypeID;
38 protected $_membershipStatusID;
40 protected $_apiversion =3;
47 'name' => 'MembershipStatus Calc',
48 'description' => 'Test all MembershipStatus Calc API methods.',
49 'group' => 'CiviCRM API Tests',
55 $this->_contactID
= $this->individualCreate();
56 $this->_membershipTypeID
= $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID
));
57 $this->_membershipStatusID
= $this->membershipStatusCreate('test status');
59 CRM_Member_PseudoConstant
::membershipType($this->_membershipTypeID
, TRUE);
60 CRM_Member_PseudoConstant
::membershipStatus(NULL, NULL, 'name', TRUE);
64 $this->membershipStatusDelete($this->_membershipStatusID
);
65 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
66 $this->contactDelete($this->_contactID
);
69 ///////////////// civicrm_membership_status_get methods
73 * Test civicrm_membership_status_get with empty params
75 function testGetEmptyParams() {
76 $result = $this->callAPISuccess('membership_status', 'get', array());
77 // It should be 8 statuses, 7 default from mysql_data
78 // plus one test status added in setUp
79 $this->assertEquals(8, $result['count']);
83 * Test civicrm_membership_status_get. Success expected.
87 'name' => 'test status',
89 $result = $this->callAPIAndDocument('membership_status', 'get', $params, __FUNCTION__
, __FILE__
);
90 $this->assertEquals($result['values'][$this->_membershipStatusID
]['name'], "test status", "In line " . __LINE__
);
94 * Test civicrm_membership_status_get. Success expected.
96 function testGetLimit() {
97 $result = $this->callAPISuccess('membership_status', 'get', array());
98 $this->assertGreaterThan(1, $result['count'], "Check more than one exists In line " . __LINE__
);
99 $params['option.limit'] = 1;
100 $result = $this->callAPISuccess('membership_status', 'get', $params);
101 $this->assertEquals(1, $result['count'], "Check only 1 retrieved " . __LINE__
);
104 function testCreateDuplicateName() {
105 $params = array('name' => 'name');
106 $result = $this->callAPISuccess('membership_status', 'create', $params);
107 $result = $this->callAPIFailure('membership_status', 'create', $params,
108 'A membership status with this name already exists.'
112 function testCreateWithMissingRequired() {
113 $params = array('title' => 'Does not make sense');
114 $result = $this->callAPIFailure('membership_status', 'create', $params);
117 function testCreate() {
119 'name' => 'test membership status',
121 $result = $this->callAPIAndDocument('membership_status', 'create', $params, __FUNCTION__
, __FILE__
);
123 $this->assertNotNull($result['id']);
124 $this->membershipStatusDelete($result['id']);
127 function testUpdate() {
129 'name' => 'test membership status', );
130 $result = $this->callAPISuccess('membership_status', 'create', $params);
132 $result = $this->callAPISuccess('membership_status', 'get', $params);
133 $this->assertEquals('test membership status', $result['values'][$id]['name']);
136 'name' => 'renamed', );
137 $result = $this->callAPISuccess('membership_status', 'create', $newParams);
138 $result = $this->callAPISuccess('membership_status', 'get', array('id' => $id));
139 $this->assertEquals('renamed', $result['values'][$id]['name']);
140 $this->membershipStatusDelete($result['id']);
144 ///////////////// civicrm_membership_status_delete methods
145 function testDeleteEmptyParams() {
146 $result = $this->callAPIFailure('membership_status', 'delete', array());
149 function testDeleteWithMissingRequired() {
150 $params = array('title' => 'Does not make sense');
151 $result = $this->callAPIFailure('membership_status', 'delete', $params);
154 function testDelete() {
155 $membershipID = $this->membershipStatusCreate();
157 'id' => $membershipID,
159 $result = $this->callAPISuccess('membership_status', 'delete', $params);
162 * Test that trying to delete membership status while membership still exists creates error
164 function testDeleteWithMembershipError() {
165 $membershipStatusID = $this->membershipStatusCreate();
166 $this->_contactID
= $this->individualCreate();
167 $this->_entity
= 'membership';
169 'contact_id' => $this->_contactID
,
170 'membership_type_id' => $this->_membershipTypeID
,
171 'join_date' => '2009-01-21',
172 'start_date' => '2009-01-21',
173 'end_date' => '2009-12-21',
174 'source' => 'Payment',
176 'status_id' => $membershipStatusID,
179 $result = $this->callAPISuccess('membership', 'create', $params);
180 $membershipID = $result['id'];
183 'id' => $membershipStatusID,
185 $result = $this->callAPIFailure('membership_status', 'delete', $params);
187 $this->callAPISuccess('Membership', 'Delete', array(
188 'id' => $membershipID,
190 $result = $this->callAPISuccess('membership_status', 'delete', $params);