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