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;
40 'name' => 'MembershipStatus Calc',
41 'description' => 'Test all MembershipStatus Calc API methods.',
42 'group' => 'CiviCRM API Tests',
48 $this->_contactID
= $this->individualCreate();
49 $this->_membershipTypeID
= $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID
));
50 $this->_membershipStatusID
= $this->membershipStatusCreate('test status');
52 CRM_Member_PseudoConstant
::membershipType($this->_membershipTypeID
, TRUE);
53 CRM_Member_PseudoConstant
::membershipStatus(NULL, NULL, 'name', TRUE);
57 $this->membershipStatusDelete($this->_membershipStatusID
);
58 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
59 $this->contactDelete($this->_contactID
);
62 ///////////////// civicrm_membership_status_get methods
66 * Test civicrm_membership_status_get with empty params
68 function testGetEmptyParams() {
69 $result = $this->callAPISuccess('membership_status', 'get', array());
70 // It should be 8 statuses, 7 default from mysql_data
71 // plus one test status added in setUp
72 $this->assertEquals(8, $result['count']);
76 * Test civicrm_membership_status_get. Success expected.
80 'name' => 'test status',
82 $result = $this->callAPIAndDocument('membership_status', 'get', $params, __FUNCTION__
, __FILE__
);
83 $this->assertEquals($result['values'][$this->_membershipStatusID
]['name'], "test status", "In line " . __LINE__
);
87 * Test civicrm_membership_status_get. Success expected.
89 function testGetLimit() {
90 $result = $this->callAPISuccess('membership_status', 'get', array());
91 $this->assertGreaterThan(1, $result['count'], "Check more than one exists In line " . __LINE__
);
92 $params['option.limit'] = 1;
93 $result = $this->callAPISuccess('membership_status', 'get', $params);
94 $this->assertEquals(1, $result['count'], "Check only 1 retrieved " . __LINE__
);
97 function testCreateDuplicateName() {
98 $params = array('name' => 'name');
99 $result = $this->callAPISuccess('membership_status', 'create', $params);
100 $result = $this->callAPIFailure('membership_status', 'create', $params,
101 'A membership status with this name already exists.'
105 function testCreateWithMissingRequired() {
106 $params = array('title' => 'Does not make sense');
107 $result = $this->callAPIFailure('membership_status', 'create', $params);
110 function testCreate() {
112 'name' => 'test membership status',
114 $result = $this->callAPIAndDocument('membership_status', 'create', $params, __FUNCTION__
, __FILE__
);
116 $this->assertNotNull($result['id']);
117 $this->membershipStatusDelete($result['id']);
120 function testUpdate() {
122 'name' => 'test membership status', );
123 $result = $this->callAPISuccess('membership_status', 'create', $params);
125 $result = $this->callAPISuccess('membership_status', 'get', $params);
126 $this->assertEquals('test membership status', $result['values'][$id]['name']);
129 'name' => 'renamed', );
130 $result = $this->callAPISuccess('membership_status', 'create', $newParams);
131 $result = $this->callAPISuccess('membership_status', 'get', array('id' => $id));
132 $this->assertEquals('renamed', $result['values'][$id]['name']);
133 $this->membershipStatusDelete($result['id']);
137 ///////////////// civicrm_membership_status_delete methods
138 function testDeleteEmptyParams() {
139 $result = $this->callAPIFailure('membership_status', 'delete', array());
142 function testDeleteWithMissingRequired() {
143 $params = array('title' => 'Does not make sense');
144 $result = $this->callAPIFailure('membership_status', 'delete', $params);
147 function testDelete() {
148 $membershipID = $this->membershipStatusCreate();
150 'id' => $membershipID,
152 $result = $this->callAPISuccess('membership_status', 'delete', $params);
155 * Test that trying to delete membership status while membership still exists creates error
157 function testDeleteWithMembershipError() {
158 $membershipStatusID = $this->membershipStatusCreate();
159 $this->_contactID
= $this->individualCreate();
160 $this->_entity
= 'membership';
162 'contact_id' => $this->_contactID
,
163 'membership_type_id' => $this->_membershipTypeID
,
164 'join_date' => '2009-01-21',
165 'start_date' => '2009-01-21',
166 'end_date' => '2009-12-21',
167 'source' => 'Payment',
169 'status_id' => $membershipStatusID,
172 $result = $this->callAPISuccess('membership', 'create', $params);
173 $membershipID = $result['id'];
176 'id' => $membershipStatusID,
178 $result = $this->callAPIFailure('membership_status', 'delete', $params);
180 $this->callAPISuccess('Membership', 'Delete', array(
181 'id' => $membershipID,
183 $result = $this->callAPISuccess('membership_status', 'delete', $params);