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