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