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