3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
32 * Test APIv3 civicrm_grant* functions
34 * @package CiviCRM_APIv3
35 * @subpackage API_Grant
38 class api_v3_GrantTest
extends CiviUnitTestCase
{
39 protected $_apiversion = 3;
41 protected $ids = array();
42 protected $_entity = 'Grant';
44 public $DBResetRequired = FALSE;
48 $this->ids
['contact'][0] = $this->individualCreate();
49 $this->params
= array(
50 'contact_id' => $this->ids
['contact'][0],
51 'application_received_date' => 'now',
52 'decision_date' => 'next Monday',
53 'amount_total' => '500',
55 'rationale' => 'Just Because',
62 foreach ($this->ids
as $entity => $entities) {
63 foreach ($entities as $id) {
64 $this->callAPISuccess($entity, 'delete', array( 'id' => $id));
69 public function testCreateGrant() {
70 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->params
, __FUNCTION__
, __FILE__
);
71 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
72 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__
);
73 $this->getAndCheck($this->params
, $result['id'], $this->_entity
);
76 public function testGetGrant() {
77 $result = $this->callAPISuccess($this->_entity
, 'create', $this->params
);
78 $this->ids
['grant'][0] = $result['id'];
79 $result = $this->callAPIAndDocument($this->_entity
, 'get', array('rationale' => 'Just Because'), __FUNCTION__
, __FILE__
);
80 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
81 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
84 public function testDeleteGrant() {
85 $result = $this->callAPISuccess($this->_entity
, 'create', $this->params
);
86 $result = $this->callAPIAndDocument($this->_entity
, 'delete', array('id' => $result['id']), __FUNCTION__
, __FILE__
);
87 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
88 $checkDeleted = $this->callAPISuccess($this->_entity
, 'get', array(
90 $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__
);
93 * This is a test to check if setting fields one at a time alters other fields
95 * 1) Currency keeps getting reset to USD - BUT this may be the only enabled currency
96 * - in which case it is valid
100 public function testCreateAutoGrant() {
101 $entityName = $this->_entity
;
102 $baoString = 'CRM_Grant_BAO_Grant';
103 $fields = $this->callAPISuccess($entityName, 'getfields', array(
104 'action' => 'create',
108 $fields = $fields['values'];
109 $return = array_keys($fields);
110 $baoObj = new CRM_Core_DAO();
111 $baoObj->createTestObject($baoString, array('currency' => 'USD'), 2, 0);
112 $getentities = $this->callAPISuccess($entityName, 'get', array(
117 // lets use first rather than assume only one exists
118 $entity = $getentities['values'][0];
119 $entity2 = $getentities['values'][1];
120 foreach ($fields as $field => $specs) {
121 if ($field == 'currency' ||
$field == 'id') {
124 switch ($specs['type']) {
125 case CRM_Utils_Type
::T_DATE
:
126 case CRM_Utils_Type
::T_TIMESTAMP
:
127 $entity[$field] = '2012-05-20';
130 case CRM_Utils_Type
::T_STRING
:
131 case CRM_Utils_Type
::T_BLOB
:
132 case CRM_Utils_Type
::T_MEDIUMBLOB
:
133 case CRM_Utils_Type
::T_TEXT
:
134 case CRM_Utils_Type
::T_LONGTEXT
:
135 case CRM_Utils_Type
::T_EMAIL
:
136 $entity[$field] = 'New String';
139 case CRM_Utils_Type
::T_INT
:
140 // probably created with a 1
142 if (!empty($specs['FKClassName'])) {
143 $entity[$field] = empty($entity2[$field]) ?
$entity2[$specs]['uniqueName'] : $entity2[$field];
147 case CRM_Utils_Type
::T_BOOLEAN
:
148 // probably created with a 1
152 case CRM_Utils_Type
::T_FLOAT
:
153 case CRM_Utils_Type
::T_MONEY
:
154 $entity[$field] = 222;
157 case CRM_Utils_Type
::T_URL
:
158 $entity[$field] = 'warm.beer.com';
160 $updateParams = array(
161 'id' => $entity['id'],
162 $field => $entity[$field],
165 $update = $this->callAPISuccess($entityName, 'create', $updateParams);
166 $this->assertAPISuccess($update, "setting $field to {$entity[$field]} in line " . __LINE__
);
167 $checkParams = array(
168 'id' => $entity['id'],
171 $checkEntity = $this->callAPISuccess($entityName, 'getsingle', $checkParams);
172 $this->assertAPIArrayComparison((array) $entity, $checkEntity);
174 $baoObj->deleteTestObjects($baoString);