Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
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 | ||
28 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
29 | ||
30 | ||
31 | /** | |
32 | * Test APIv3 civicrm_grant* functions | |
33 | * | |
34 | * @package CiviCRM_APIv3 | |
35 | * @subpackage API_Grant | |
36 | */ | |
37 | ||
38 | class api_v3_GrantTest extends CiviUnitTestCase { | |
39 | protected $_apiversion = 3; | |
40 | protected $params; | |
41 | protected $ids = array(); | |
42 | protected $_entity = 'Grant'; | |
43 | public $_eNoticeCompliant = TRUE; | |
44 | public $DBResetRequired = FALSE; | |
45 | ||
46 | function setUp() { | |
47 | parent::setUp(); | |
48 | $this->ids['contact'][0] = $this->individualCreate(); | |
49 | $this->params = array( | |
50 | 'version' => 3, | |
51 | 'contact_id' => $this->ids['contact'][0], | |
52 | 'application_received_date' => 'now', | |
53 | 'decision_date' => 'next Monday', | |
54 | 'amount_total' => '500', | |
55 | 'status_id' => 1, | |
56 | 'rationale' => 'Just Because', | |
57 | 'currency' => 'USD', | |
58 | 'grant_type_id' => 1, | |
59 | ); | |
60 | } | |
61 | ||
62 | function tearDown() { | |
63 | foreach ($this->ids as $entity => $entities) { | |
64 | foreach ($entities as $id) { | |
65 | civicrm_api($entity, 'delete', array('version' => $this->_apiversion, 'id' => $id)); | |
66 | } | |
67 | } | |
68 | } | |
69 | ||
70 | public function testCreateGrant() { | |
71 | $result = civicrm_api($this->_entity, 'create', $this->params); | |
72 | $this->documentMe($this->params, $result, __FUNCTION__, __FILE__); | |
73 | $this->assertAPISuccess($result, 'In line ' . __LINE__); | |
74 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); | |
75 | $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__); | |
76 | $this->getAndCheck($this->params, $result['id'], $this->_entity); | |
77 | } | |
78 | ||
79 | public function testGetGrant() { | |
80 | $result = civicrm_api($this->_entity, 'create', $this->params); | |
81 | $this->ids['grant'][0] = $result['id']; | |
82 | $result = civicrm_api($this->_entity, 'get', array('version' => $this->_apiversion, 'rationale' => 'Just Because')); | |
83 | $this->documentMe($this->params, $result, __FUNCTION__, __FILE__); | |
84 | $this->assertAPISuccess($result, 'In line ' . __LINE__); | |
85 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); | |
86 | } | |
87 | ||
88 | public function testDeleteGrant() { | |
89 | $result = civicrm_api($this->_entity, 'create', $this->params); | |
90 | $result = civicrm_api($this->_entity, 'delete', array('version' => 3, 'id' => $result['id'])); | |
91 | $this->documentMe($this->params, $result, __FUNCTION__, __FILE__); | |
92 | $this->assertAPISuccess($result, 'In line ' . __LINE__); | |
93 | $checkDeleted = civicrm_api($this->_entity, 'get', array( | |
94 | 'version' => 3, | |
95 | )); | |
96 | $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__); | |
97 | } | |
98 | /* | |
99 | * This is a test to check if setting fields one at a time alters other fields | |
100 | * Issues Hit so far = | |
101 | * 1) Currency keeps getting reset to USD - BUT this may be the only enabled currency | |
102 | * - in which case it is valid | |
103 | * 2) | |
104 | */ | |
105 | ||
106 | public function testCreateAutoGrant() { | |
107 | $entityName = $this->_entity; | |
108 | $baoString = 'CRM_Grant_BAO_Grant'; | |
109 | $fields = civicrm_api($entityName, 'getfields', array( | |
110 | 'version' => 3, | |
111 | 'action' => 'create', | |
112 | ) | |
113 | ); | |
114 | ||
115 | $fields = $fields['values']; | |
116 | $return = array_keys($fields); | |
117 | $baoObj = new CRM_Core_DAO(); | |
118 | $baoObj->createTestObject($baoString, array('currency' => 'USD'), 2, 0); | |
119 | $getentities = civicrm_api($entityName, 'get', array( | |
120 | 'version' => 3, | |
121 | 'sequential' => 1, | |
122 | 'return' => $return, | |
123 | )); | |
124 | ||
125 | // lets use first rather than assume only one exists | |
126 | $entity = $getentities['values'][0]; | |
127 | $entity2 = $getentities['values'][1]; | |
128 | foreach ($fields as $field => $specs) { | |
129 | if ($field == 'currency' || $field == 'id') { | |
130 | continue; | |
131 | } | |
132 | switch ($specs['type']) { | |
133 | case CRM_Utils_Type::T_DATE: | |
134 | case CRM_Utils_Type::T_TIMESTAMP: | |
135 | $entity[$field] = '2012-05-20'; | |
136 | break; | |
137 | ||
138 | case CRM_Utils_Type::T_STRING: | |
139 | case CRM_Utils_Type::T_BLOB: | |
140 | case CRM_Utils_Type::T_MEDIUMBLOB: | |
141 | case CRM_Utils_Type::T_TEXT: | |
142 | case CRM_Utils_Type::T_LONGTEXT: | |
143 | case CRM_Utils_Type::T_EMAIL: | |
144 | $entity[$field] = 'New String'; | |
145 | break; | |
146 | ||
147 | case CRM_Utils_Type::T_INT: | |
148 | // probably created with a 1 | |
149 | $entity[$field] = 2; | |
150 | if (CRM_Utils_Array::value('FKClassName', $specs)) { | |
151 | $entity[$field] = empty($entity2[$field]) ? $entity2[$specs]['uniqueName'] : $entity2[$field]; | |
152 | } | |
153 | break; | |
154 | ||
155 | case CRM_Utils_Type::T_BOOL: | |
156 | case CRM_Utils_Type::T_BOOLEAN: | |
157 | // probably created with a 1 | |
158 | $entity[$field] = 0; | |
159 | break; | |
160 | ||
161 | case CRM_Utils_Type::T_FLOAT: | |
162 | case CRM_Utils_Type::T_MONEY: | |
163 | $entity[$field] = 222; | |
164 | break; | |
165 | ||
166 | case CRM_Utils_Type::T_URL: | |
167 | $entity[$field] = 'warm.beer.com'; | |
168 | } | |
169 | $updateParams = array( | |
170 | 'version' => 3, | |
171 | 'id' => $entity['id'], | |
172 | $field => $entity[$field], | |
173 | 'debug' => 1, | |
174 | ); | |
175 | $update = civicrm_api($entityName, 'create', $updateParams); | |
176 | $this->assertAPISuccess($update, "setting $field to {$entity[$field]} in line " . __LINE__); | |
177 | $checkParams = array( | |
178 | 'id' => $entity['id'], | |
179 | 'version' => 3, | |
180 | 'sequential' => 1, | |
181 | ); | |
182 | $checkEntity = civicrm_api($entityName, 'getsingle', $checkParams); | |
183 | $this->assertEquals($entity, $checkEntity, "changing field $field"); | |
184 | } | |
185 | $baoObj->deleteTestObjects($baoString); | |
186 | $baoObj->free(); | |
187 | } | |
188 | } | |
189 |