3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 +--------------------------------------------------------------------+
29 * Class api_v3_MembershipStatusTest
32 class api_v3_MembershipStatusTest
extends CiviUnitTestCase
{
34 protected $_contactID;
35 protected $_contributionTypeID;
36 protected $_membershipTypeID;
37 protected $_membershipStatusID;
39 protected $_apiversion = 3;
41 public function setUp() {
43 $this->_contactID
= $this->individualCreate();
44 $this->_membershipTypeID
= $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID
));
45 $this->_membershipStatusID
= $this->membershipStatusCreate('test status');
47 CRM_Member_PseudoConstant
::membershipType($this->_membershipTypeID
, TRUE);
48 CRM_Member_PseudoConstant
::membershipStatus(NULL, NULL, 'name', TRUE);
51 public function tearDown() {
52 $this->membershipStatusDelete($this->_membershipStatusID
);
53 $this->membershipTypeDelete(['id' => $this->_membershipTypeID
]);
54 $this->contactDelete($this->_contactID
);
58 ///////////////// civicrm_membership_status_get methods
61 * Test civicrm_membership_status_get with empty params.
63 public function testGetEmptyParams() {
64 $result = $this->callAPISuccess('membership_status', 'get', array());
65 // It should be 8 statuses, 7 default from mysql_data
66 // plus one test status added in setUp
67 $this->assertEquals(8, $result['count']);
71 * Test civicrm_membership_status_get. Success expected.
73 public function testGet() {
75 'name' => 'test status',
77 $result = $this->callAPIAndDocument('membership_status', 'get', $params, __FUNCTION__
, __FILE__
);
78 $this->assertEquals($result['values'][$this->_membershipStatusID
]['name'], "test status", "In line " . __LINE__
);
82 * Test civicrm_membership_status_get. Success expected.
84 public function testGetLimit() {
85 $result = $this->callAPISuccess('membership_status', 'get', array());
86 $this->assertGreaterThan(1, $result['count'], "Check more than one exists In line " . __LINE__
);
87 $params['option.limit'] = 1;
88 $result = $this->callAPISuccess('membership_status', 'get', $params);
89 $this->assertEquals(1, $result['count'], "Check only 1 retrieved " . __LINE__
);
92 public function testCreateDuplicateName() {
93 $params = array('name' => 'name');
94 $result = $this->callAPISuccess('membership_status', 'create', $params);
95 $result = $this->callAPIFailure('membership_status', 'create', $params,
96 'A membership status with this name already exists.'
100 public function testCreateWithMissingRequired() {
101 $params = array('title' => 'Does not make sense');
102 $this->callAPIFailure('membership_status', 'create', $params, 'Mandatory key(s) missing from params array: name');
105 public function testCreate() {
107 'name' => 'test membership status',
109 $result = $this->callAPIAndDocument('membership_status', 'create', $params, __FUNCTION__
, __FILE__
);
111 $this->assertNotNull($result['id']);
112 $this->membershipStatusDelete($result['id']);
115 public function testUpdate() {
117 'name' => 'test membership status',
119 $result = $this->callAPISuccess('membership_status', 'create', $params);
121 $result = $this->callAPISuccess('membership_status', 'get', $params);
122 $this->assertEquals('test membership status', $result['values'][$id]['name']);
127 $result = $this->callAPISuccess('membership_status', 'create', $newParams);
128 $result = $this->callAPISuccess('membership_status', 'get', array('id' => $id));
129 $this->assertEquals('renamed', $result['values'][$id]['name']);
130 $this->membershipStatusDelete($result['id']);
133 ///////////////// civicrm_membership_status_delete methods
136 * Attempt (and fail) to delete membership status without an parameters.
138 public function testDeleteEmptyParams() {
139 $result = $this->callAPIFailure('membership_status', 'delete', array());
142 public function testDeleteWithMissingRequired() {
143 $params = array('title' => 'Does not make sense');
144 $result = $this->callAPIFailure('membership_status', 'delete', $params);
147 public function testDelete() {
148 $membershipID = $this->membershipStatusCreate();
150 'id' => $membershipID,
152 $result = $this->callAPISuccess('membership_status', 'delete', $params);
156 * Test that trying to delete membership status while membership still exists creates error.
158 public function testDeleteWithMembershipError() {
159 $membershipStatusID = $this->membershipStatusCreate();
160 $this->_contactID
= $this->individualCreate();
161 $this->_entity
= 'membership';
163 'contact_id' => $this->_contactID
,
164 'membership_type_id' => $this->_membershipTypeID
,
165 'join_date' => '2009-01-21',
166 'start_date' => '2009-01-21',
167 'end_date' => '2009-12-21',
168 'source' => 'Payment',
170 'status_id' => $membershipStatusID,
173 $result = $this->callAPISuccess('membership', 'create', $params);
174 $membershipID = $result['id'];
177 'id' => $membershipStatusID,
179 $result = $this->callAPIFailure('membership_status', 'delete', $params);
181 $this->callAPISuccess('Membership', 'Delete', array(
182 'id' => $membershipID,
184 $result = $this->callAPISuccess('membership_status', 'delete', $params);