3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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';
31 * Test class for Batch API - civicrm_batch_*
33 * @package CiviCRM_APIv3
35 class api_v3_BatchTest
extends CiviUnitTestCase
{
36 public $_eNoticeCompliant = TRUE;
37 protected $_apiversion;
42 * Initialize configuration
44 function __construct() {
45 parent
::__construct();
49 * Sets up the fixture, for example, opens a network connection.
50 * This method is called before a test is executed.
54 protected function setUp() {
55 $this->_apiversion
= 3;
56 $this->_params
= array(
57 'version' => $this->_apiversion
,
63 * Tears down the fixture, for example, closes a network connection.
64 * This method is called after a test is executed.
68 protected function tearDown() {}
71 * Create a sample batch
73 function batchCreate() {
74 $params = $this->_params
;
75 $params['name'] = $params['title'] = 'Batch_' . mt_rand(0, 999999);
76 $params['status_id'] = 1;
77 $result = civicrm_api('batch', 'create', $params);
81 ///////////////// civicrm_batch_get methods
84 * Test civicrm_batch_get with wrong params type.
86 public function testGetWrongParamsType() {
87 $params = 'is_string';
88 $result = $this->callAPIFailure('batch', 'get', $params);
89 $this->assertEquals('Input variable `params` is not an array', $result['error_message'], 'In line ' . __LINE__
);
93 * Test civicrm_batch_get - success expected.
95 public function testGet() {
97 'id' => $this->batchCreate(),
98 'version' => $this->_apiversion
,
100 $result = civicrm_api('batch', 'get', $params);
101 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
102 $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__
);
103 $this->assertEquals($params['id'], $result['id'], 'In line ' . __LINE__
);
107 ///////////////// civicrm_batch_create methods
110 * Test civicrm_batch_create with empty params.
112 function testCreateEmptyParams() {
113 $this->callAPIFailure('batch', 'create', $this->_params
);
117 * Test civicrm_batch_create - success expected.
119 function testCreate() {
121 'name' => 'New_Batch_03',
122 'title' => 'New Batch 03',
123 'description' => 'This is description for New Batch 03',
127 'version' => $this->_apiversion
,
130 $result = civicrm_api('batch', 'create', $params);
131 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
132 $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__
);
133 $this->assertNotNull($result['id'], 'In line ' . __LINE__
);
135 // Fetch batch and compare values
136 $saved = civicrm_api('batch', 'getSingle', $result);
137 unset($params['version']);
138 foreach ($params as $key => $value) {
139 $this->assertEquals($value, $saved[$key], 'In line ' . __LINE__
);
144 * Test civicrm_batch_create with id.
146 function testUpdate() {
148 'name' => 'New_Batch_04',
149 'title' => 'New Batch 04',
150 'description' => 'This is description for New Batch 04',
153 'version' => $this->_apiversion
,
154 'id' => $this->batchCreate(),
157 $result = civicrm_api('batch', 'create', $params);
158 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
159 $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__
);
160 $this->assertNotNull($result['id'], 'In line ' . __LINE__
);
162 // Fetch batch and compare values
163 $saved = civicrm_api('batch', 'getSingle', $result);
164 unset($params['version']);
165 foreach ($params as $key => $value) {
166 $this->assertEquals($value, $saved[$key], 'In line ' . __LINE__
);
170 ///////////////// civicrm_batch_delete methods
173 * Test civicrm_batch_delete without batch id.
175 function testDeleteWithoutBatchId() {
176 $result = civicrm_api('batch', 'delete', array('version' => $this->_apiversion
));
177 $this->assertEquals(1, $result['is_error'], 'In line ' . __LINE__
);
178 $this->assertEquals('Mandatory key(s) missing from params array: id', $result['error_message'], 'In line ' . __LINE__
);
182 * Test civicrm_batch_delete with wrong batch id type.
184 function testDeleteWrongParams() {
185 $result = $this->callAPIFailure('batch', 'delete', 'tyttyd');
186 $this->assertEquals('Input variable `params` is not an array', $result['error_message'], 'In line ' . __LINE__
);
190 * Test civicrm_batch_delete using the old $params['batch_id'] syntax.
192 function testBatchDeleteOldSyntax() {
193 $batchID = $this->batchCreate();
195 'batch_id' => $batchID,
196 'version' => $this->_apiversion
,
198 $result = civicrm_api('batch', 'delete', $params);
199 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
203 * Test civicrm_batch_delete using the new $params['id'] syntax
205 function testBatchDeleteCorrectSyntax() {
206 $batchID = $this->batchCreate();
209 'version' => $this->_apiversion
,
211 $result = civicrm_api('batch', 'delete', $params);
212 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
213 $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__
);