Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
15a4309a | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 | 27 | |
e9479dcf EM |
28 | /** |
29 | * Class api_v3_MembershipStatusTest | |
acb109b7 | 30 | * @group headless |
e9479dcf | 31 | */ |
6a488035 TO |
32 | class api_v3_MembershipStatusTest extends CiviUnitTestCase { |
33 | ||
34 | protected $_contactID; | |
35 | protected $_contributionTypeID; | |
36 | protected $_membershipTypeID; | |
37 | protected $_membershipStatusID; | |
b7c9bc4c | 38 | |
6c6e6187 | 39 | protected $_apiversion = 3; |
6a488035 | 40 | |
00be9182 | 41 | public function setUp() { |
6a488035 | 42 | parent::setUp(); |
6a488035 | 43 | $this->_contactID = $this->individualCreate(); |
75638074 | 44 | $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID)); |
6a488035 TO |
45 | $this->_membershipStatusID = $this->membershipStatusCreate('test status'); |
46 | ||
47 | CRM_Member_PseudoConstant::membershipType($this->_membershipTypeID, TRUE); | |
48 | CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'name', TRUE); | |
49 | } | |
50 | ||
00be9182 | 51 | public function tearDown() { |
6a488035 TO |
52 | $this->membershipStatusDelete($this->_membershipStatusID); |
53 | $this->membershipTypeDelete(array('id' => $this->_membershipTypeID)); | |
54 | $this->contactDelete($this->_contactID); | |
55 | } | |
56 | ||
57 | ///////////////// civicrm_membership_status_get methods | |
58 | ||
6a488035 TO |
59 | |
60 | /** | |
fe482240 | 61 | * Test civicrm_membership_status_get with empty params. |
6a488035 | 62 | */ |
00be9182 | 63 | public function testGetEmptyParams() { |
6901eb18 | 64 | $result = $this->callAPISuccess('membership_status', 'get', array()); |
6a488035 TO |
65 | // It should be 8 statuses, 7 default from mysql_data |
66 | // plus one test status added in setUp | |
6901eb18 | 67 | $this->assertEquals(8, $result['count']); |
6a488035 TO |
68 | } |
69 | ||
70 | /** | |
d177a2a6 | 71 | * Test civicrm_membership_status_get. Success expected. |
6a488035 | 72 | */ |
00be9182 | 73 | public function testGet() { |
6a488035 TO |
74 | $params = array( |
75 | 'name' => 'test status', | |
6a488035 | 76 | ); |
6901eb18 | 77 | $result = $this->callAPIAndDocument('membership_status', 'get', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
78 | $this->assertEquals($result['values'][$this->_membershipStatusID]['name'], "test status", "In line " . __LINE__); |
79 | } | |
80 | ||
81 | /** | |
d177a2a6 | 82 | * Test civicrm_membership_status_get. Success expected. |
6a488035 | 83 | */ |
00be9182 | 84 | public function testGetLimit() { |
8cdb5f76 | 85 | $result = $this->callAPISuccess('membership_status', 'get', array()); |
86 | $this->assertGreaterThan(1, $result['count'], "Check more than one exists In line " . __LINE__); | |
6a488035 | 87 | $params['option.limit'] = 1; |
6901eb18 | 88 | $result = $this->callAPISuccess('membership_status', 'get', $params); |
8cdb5f76 | 89 | $this->assertEquals(1, $result['count'], "Check only 1 retrieved " . __LINE__); |
6a488035 TO |
90 | } |
91 | ||
00be9182 | 92 | public function testCreateDuplicateName() { |
6901eb18 | 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.' | |
97 | ); | |
6a488035 TO |
98 | } |
99 | ||
00be9182 | 100 | public function testCreateWithMissingRequired() { |
6a488035 | 101 | $params = array('title' => 'Does not make sense'); |
d235daf6 | 102 | $this->callAPIFailure('membership_status', 'create', $params, 'Mandatory key(s) missing from params array: name'); |
6a488035 TO |
103 | } |
104 | ||
00be9182 | 105 | public function testCreate() { |
6a488035 TO |
106 | $params = array( |
107 | 'name' => 'test membership status', | |
6a488035 | 108 | ); |
6901eb18 | 109 | $result = $this->callAPIAndDocument('membership_status', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 | 110 | |
6a488035 TO |
111 | $this->assertNotNull($result['id']); |
112 | $this->membershipStatusDelete($result['id']); | |
113 | } | |
114 | ||
00be9182 | 115 | public function testUpdate() { |
6a488035 | 116 | $params = array( |
92915c55 TO |
117 | 'name' => 'test membership status', |
118 | ); | |
6901eb18 | 119 | $result = $this->callAPISuccess('membership_status', 'create', $params); |
6a488035 | 120 | $id = $result['id']; |
6901eb18 | 121 | $result = $this->callAPISuccess('membership_status', 'get', $params); |
6a488035 TO |
122 | $this->assertEquals('test membership status', $result['values'][$id]['name']); |
123 | $newParams = array( | |
124 | 'id' => $id, | |
92915c55 TO |
125 | 'name' => 'renamed', |
126 | ); | |
6901eb18 | 127 | $result = $this->callAPISuccess('membership_status', 'create', $newParams); |
128 | $result = $this->callAPISuccess('membership_status', 'get', array('id' => $id)); | |
6a488035 TO |
129 | $this->assertEquals('renamed', $result['values'][$id]['name']); |
130 | $this->membershipStatusDelete($result['id']); | |
131 | } | |
132 | ||
133 | ||
6a488035 | 134 | ///////////////// civicrm_membership_status_delete methods |
a1a2a83d TO |
135 | |
136 | /** | |
137 | * Attempt (and fail) to delete membership status without an parameters. | |
138 | */ | |
00be9182 | 139 | public function testDeleteEmptyParams() { |
8cdb5f76 | 140 | $result = $this->callAPIFailure('membership_status', 'delete', array()); |
6a488035 TO |
141 | } |
142 | ||
00be9182 | 143 | public function testDeleteWithMissingRequired() { |
6a488035 | 144 | $params = array('title' => 'Does not make sense'); |
d0e1eff2 | 145 | $result = $this->callAPIFailure('membership_status', 'delete', $params); |
6a488035 TO |
146 | } |
147 | ||
00be9182 | 148 | public function testDelete() { |
6a488035 TO |
149 | $membershipID = $this->membershipStatusCreate(); |
150 | $params = array( | |
151 | 'id' => $membershipID, | |
6a488035 | 152 | ); |
8cdb5f76 | 153 | $result = $this->callAPISuccess('membership_status', 'delete', $params); |
6a488035 | 154 | } |
c490a46a CW |
155 | |
156 | /** | |
eceb18cc | 157 | * Test that trying to delete membership status while membership still exists creates error. |
c490a46a | 158 | */ |
00be9182 | 159 | public function testDeleteWithMembershipError() { |
6a488035 TO |
160 | $membershipStatusID = $this->membershipStatusCreate(); |
161 | $this->_contactID = $this->individualCreate(); | |
162 | $this->_entity = 'membership'; | |
163 | $params = array( | |
164 | 'contact_id' => $this->_contactID, | |
165 | 'membership_type_id' => $this->_membershipTypeID, | |
166 | 'join_date' => '2009-01-21', | |
167 | 'start_date' => '2009-01-21', | |
168 | 'end_date' => '2009-12-21', | |
169 | 'source' => 'Payment', | |
170 | 'is_override' => 1, | |
171 | 'status_id' => $membershipStatusID, | |
6a488035 TO |
172 | ); |
173 | ||
8cdb5f76 | 174 | $result = $this->callAPISuccess('membership', 'create', $params); |
6a488035 TO |
175 | $membershipID = $result['id']; |
176 | ||
177 | $params = array( | |
178 | 'id' => $membershipStatusID, | |
6a488035 | 179 | ); |
d0e1eff2 | 180 | $result = $this->callAPIFailure('membership_status', 'delete', $params); |
6a488035 | 181 | |
8cdb5f76 | 182 | $this->callAPISuccess('Membership', 'Delete', array( |
6a488035 | 183 | 'id' => $membershipID, |
8cdb5f76 | 184 | )); |
185 | $result = $this->callAPISuccess('membership_status', 'delete', $params); | |
6a488035 | 186 | } |
96025800 | 187 | |
6a488035 | 188 | } |