4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
30 * File for the CiviCRM APIv3 job functions
32 * @package CiviCRM_APIv3
35 * @copyright CiviCRM LLC (c) 2004-2013
36 * @version $Id: Job.php 30879 2010-11-22 15:45:55Z shot $
39 require_once 'CiviTest/CiviUnitTestCase.php';
40 class api_v3_JobTest
extends CiviUnitTestCase
{
41 protected $_apiversion;
43 public $_eNoticeCompliant = TRUE;
44 public $DBResetRequired = FALSE;
45 public $_entity = 'Job';
46 public $_apiVersion = 3;
50 $this->quickCleanup(array('civicrm_job'));
54 $this->quickCleanup(array('civicrm_job'));
61 function testCreateWithoutName() {
64 'version' => $this->_apiVersion
,
66 $result = civicrm_api('job', 'create', $params);
68 $this->assertEquals($result['is_error'], 1);
69 $this->assertEquals($result['error_message'],
70 'Mandatory key(s) missing from params array: run_frequency, name, api_entity, api_action'
75 * create job with an invalid "run_frequency" value
77 function testCreateWithInvalidFrequency() {
79 'version' => $this->_apiVersion
,
81 'name' => 'API_Test_Job',
82 'description' => 'A long description written by hand in cursive',
83 'run_frequency' => 'Fortnightly',
84 'api_entity' => 'ApiTestEntity',
85 'api_action' => 'apitestaction',
86 'parameters' => 'Semi-formal explanation of runtime job parameters',
89 $result = civicrm_api('job', 'create', $params);
90 $this->assertEquals($result['is_error'], 1);
96 function testCreate() {
98 'version' => $this->_apiVersion
,
100 'name' => 'API_Test_Job',
101 'description' => 'A long description written by hand in cursive',
102 'run_frequency' => 'Daily',
103 'api_entity' => 'ApiTestEntity',
104 'api_action' => 'apitestaction',
105 'parameters' => 'Semi-formal explanation of runtime job parameters',
108 $result = civicrm_api('job', 'create', $params);
109 $this->assertAPISuccess($result);
110 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
111 $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__
);
113 // mutate $params to match expected return value
114 unset($params['version']);
115 unset($params['sequential']);
116 //assertDBState compares expected values in $result to actual values in the DB
117 $this->assertDBState('CRM_Core_DAO_Job', $result['id'], $params);
121 * check with empty array
123 function testDeleteEmpty() {
125 $result = civicrm_api('job', 'delete', $params);
126 $this->assertEquals($result['is_error'], 1);
130 * check with No array
132 function testDeleteParamsNotArray() {
133 $result = civicrm_api('job', 'delete', 'string');
134 $this->assertEquals($result['is_error'], 1);
138 * check if required fields are not passed
140 function testDeleteWithoutRequired() {
142 'name' => 'API_Test_PP',
143 'title' => 'API Test Payment Processor',
144 'class_name' => 'CRM_Core_Payment_APITest',
147 $result = civicrm_api('job', 'delete', $params);
148 $this->assertEquals($result['is_error'], 1);
149 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, id');
153 * check with incorrect required fields
155 function testDeleteWithIncorrectData() {
158 'version' => $this->_apiVersion
,
161 $result = civicrm_api('job', 'delete', $params);
163 $this->assertEquals($result['is_error'], 1);
164 $this->assertEquals($result['error_message'], 'Invalid value for job ID');
170 function testDelete() {
171 $createParams = array(
172 'version' => $this->_apiVersion
,
174 'name' => 'API_Test_Job',
175 'description' => 'A long description written by hand in cursive',
176 'run_frequency' => 'Daily',
177 'api_entity' => 'ApiTestEntity',
178 'api_action' => 'apitestaction',
179 'parameters' => 'Semi-formal explanation of runtime job parameters',
182 $createResult = civicrm_api('job', 'create', $createParams);
183 $this->assertAPISuccess($createResult);
186 'id' => $createResult['id'],
187 'version' => $this->_apiVersion
,
189 $result = civicrm_api('job', 'delete', $params);
190 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
191 $this->assertAPISuccess($result);
196 public function testCallUpdateGreetingMissingParams() {
197 $result = civicrm_api($this->_entity, 'update_greeting', array('gt' => 1, 'version' => $this->_apiVersion));
198 $this->assertEquals('Mandatory key(s) missing from params array: ct', $result['error_message']);
201 public function testCallUpdateGreetingIncorrectParams() {
202 $result = civicrm_api($this->_entity, 'update_greeting', array('gt' => 1, 'ct' => 'djkfhdskjfhds', 'version' => $this->_apiVersion));
203 $this->assertEquals('ct `djkfhdskjfhds` is not valid.', $result['error_message']);
206 * Note that this test is about tesing the metadata / calling of the function & doesn't test the success of the called function
208 public function testCallUpdateGreetingSuccess() {
209 $result = civicrm_api($this->_entity
, 'update_greeting', array('gt' => 'postal_greeting', 'ct' => 'Individual', 'version' => $this->_apiVersion
));
210 $this->assertAPISuccess($result);
213 public function testCallUpdateGreetingCommaSeparatedParamsSuccess() {
214 $gt = 'postal_greeting,email_greeting,addressee';
215 $ct = 'Individual,Household';
216 $result = civicrm_api($this->_entity
, 'update_greeting', array('gt' => $gt, 'ct' => $ct, 'version' => $this->_apiVersion
));
217 $this->assertAPISuccess($result);