Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | // $Id$ | |
3 | ||
4 | /* | |
5 | +--------------------------------------------------------------------+ | |
6 | | CiviCRM version 4.3 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
9 | +--------------------------------------------------------------------+ | |
10 | | This file is a part of CiviCRM. | | |
11 | | | | |
12 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
13 | | under the terms of the GNU Affero General Public License | | |
14 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
15 | | | | |
16 | | CiviCRM is distributed in the hope that it will be useful, but | | |
17 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
19 | | See the GNU Affero General Public License for more details. | | |
20 | | | | |
21 | | You should have received a copy of the GNU Affero General Public | | |
22 | | License and the CiviCRM Licensing Exception along | | |
23 | | with this program; if not, contact CiviCRM LLC | | |
24 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
25 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
26 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
27 | +--------------------------------------------------------------------+ | |
28 | */ | |
29 | ||
30 | /** | |
31 | * File for the CiviCRM APIv3 job functions | |
32 | * | |
33 | * @package CiviCRM_APIv3 | |
34 | * @subpackage API_Job | |
35 | * | |
36 | * @copyright CiviCRM LLC (c) 2004-2013 | |
37 | * @version $Id: Job.php 30879 2010-11-22 15:45:55Z shot $ | |
38 | * | |
39 | */ | |
40 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
41 | class api_v3_JobTest extends CiviUnitTestCase { | |
42 | protected $_apiversion; | |
43 | ||
44 | public $_eNoticeCompliant = TRUE; | |
45 | public $DBResetRequired = FALSE; | |
46 | public $_entity = 'Job'; | |
47 | public $_apiVersion = 3; | |
48 | ||
49 | function setUp() { | |
50 | parent::setUp(); | |
51 | $this->quickCleanup(array('civicrm_job')); | |
52 | } | |
53 | ||
54 | function tearDown() { | |
55 | $this->quickCleanup(array('civicrm_job')); | |
56 | parent::tearDown(); | |
57 | } | |
58 | ||
59 | /** | |
60 | * check with no name | |
61 | */ | |
62 | function testCreateWithoutName() { | |
63 | $params = array( | |
64 | 'is_active' => 1, | |
65 | 'version' => $this->_apiVersion, | |
66 | ); | |
67 | $result = civicrm_api('job', 'create', $params); | |
68 | ||
69 | $this->assertEquals($result['is_error'], 1); | |
70 | $this->assertEquals($result['error_message'], | |
71 | 'Mandatory key(s) missing from params array: run_frequency, name, api_entity, api_action' | |
72 | ); | |
73 | } | |
74 | ||
75 | /** | |
76 | * create job with an invalid "run_frequency" value | |
77 | */ | |
78 | function testCreateWithInvalidFrequency() { | |
79 | $params = array( | |
80 | 'version' => $this->_apiVersion, | |
81 | 'sequential' => 1, | |
82 | 'name' => 'API_Test_Job', | |
83 | 'description' => 'A long description written by hand in cursive', | |
84 | 'run_frequency' => 'Fortnightly', | |
85 | 'api_entity' => 'ApiTestEntity', | |
86 | 'api_action' => 'apitestaction', | |
87 | 'parameters' => 'Semi-formal explanation of runtime job parameters', | |
88 | 'is_active' => 1, | |
89 | ); | |
90 | $result = civicrm_api('job', 'create', $params); | |
91 | $this->assertEquals($result['is_error'], 1); | |
92 | } | |
93 | ||
94 | /** | |
95 | * create job | |
96 | */ | |
97 | function testCreate() { | |
98 | $params = array( | |
99 | 'version' => $this->_apiVersion, | |
100 | 'sequential' => 1, | |
101 | 'name' => 'API_Test_Job', | |
102 | 'description' => 'A long description written by hand in cursive', | |
103 | 'run_frequency' => 'Daily', | |
104 | 'api_entity' => 'ApiTestEntity', | |
105 | 'api_action' => 'apitestaction', | |
106 | 'parameters' => 'Semi-formal explanation of runtime job parameters', | |
107 | 'is_active' => 1, | |
108 | ); | |
109 | $result = civicrm_api('job', 'create', $params); | |
110 | $this->assertAPISuccess($result); | |
111 | $this->documentMe($params, $result, __FUNCTION__, __FILE__); | |
112 | $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__); | |
113 | ||
114 | // mutate $params to match expected return value | |
115 | unset($params['version']); | |
116 | unset($params['sequential']); | |
117 | //assertDBState compares expected values in $result to actual values in the DB | |
118 | $this->assertDBState('CRM_Core_DAO_Job', $result['id'], $params); | |
119 | } | |
120 | ||
121 | /** | |
122 | * check with empty array | |
123 | */ | |
124 | function testDeleteEmpty() { | |
125 | $params = array(); | |
126 | $result = civicrm_api('job', 'delete', $params); | |
127 | $this->assertEquals($result['is_error'], 1); | |
128 | } | |
129 | ||
130 | /** | |
131 | * check with No array | |
132 | */ | |
133 | function testDeleteParamsNotArray() { | |
134 | $result = civicrm_api('job', 'delete', 'string'); | |
135 | $this->assertEquals($result['is_error'], 1); | |
136 | } | |
137 | ||
138 | /** | |
139 | * check if required fields are not passed | |
140 | */ | |
141 | function testDeleteWithoutRequired() { | |
142 | $params = array( | |
143 | 'name' => 'API_Test_PP', | |
144 | 'title' => 'API Test Payment Processor', | |
145 | 'class_name' => 'CRM_Core_Payment_APITest', | |
146 | ); | |
147 | ||
148 | $result = civicrm_api('job', 'delete', $params); | |
149 | $this->assertEquals($result['is_error'], 1); | |
150 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: version, id'); | |
151 | } | |
152 | ||
153 | /** | |
154 | * check with incorrect required fields | |
155 | */ | |
156 | function testDeleteWithIncorrectData() { | |
157 | $params = array( | |
158 | 'id' => 'abcd', | |
159 | 'version' => $this->_apiVersion, | |
160 | ); | |
161 | ||
162 | $result = civicrm_api('job', 'delete', $params); | |
163 | ||
164 | $this->assertEquals($result['is_error'], 1); | |
165 | $this->assertEquals($result['error_message'], 'Invalid value for job ID'); | |
166 | } | |
167 | ||
168 | /** | |
169 | * check job delete | |
170 | */ | |
171 | function testDelete() { | |
172 | $createParams = array( | |
173 | 'version' => $this->_apiVersion, | |
174 | 'sequential' => 1, | |
175 | 'name' => 'API_Test_Job', | |
176 | 'description' => 'A long description written by hand in cursive', | |
177 | 'run_frequency' => 'Daily', | |
178 | 'api_entity' => 'ApiTestEntity', | |
179 | 'api_action' => 'apitestaction', | |
180 | 'parameters' => 'Semi-formal explanation of runtime job parameters', | |
181 | 'is_active' => 1, | |
182 | ); | |
183 | $createResult = civicrm_api('job', 'create', $createParams); | |
184 | $this->assertAPISuccess($createResult); | |
185 | ||
186 | $params = array( | |
187 | 'id' => $createResult['id'], | |
188 | 'version' => $this->_apiVersion, | |
189 | ); | |
190 | $result = civicrm_api('job', 'delete', $params); | |
191 | $this->documentMe($params, $result, __FUNCTION__, __FILE__); | |
192 | $this->assertAPISuccess($result); | |
193 | } | |
194 | ||
195 | /** | |
196 | ||
197 | public function testCallUpdateGreetingMissingParams() { | |
198 | $result = civicrm_api($this->_entity, 'update_greeting', array('gt' => 1, 'version' => $this->_apiVersion)); | |
199 | $this->assertEquals('Mandatory key(s) missing from params array: ct', $result['error_message']); | |
200 | } | |
201 | ||
202 | public function testCallUpdateGreetingIncorrectParams() { | |
203 | $result = civicrm_api($this->_entity, 'update_greeting', array('gt' => 1, 'ct' => 'djkfhdskjfhds', 'version' => $this->_apiVersion)); | |
204 | $this->assertEquals('ct `djkfhdskjfhds` is not valid.', $result['error_message']); | |
205 | } | |
206 | /* | |
207 | * Note that this test is about tesing the metadata / calling of the function & doesn't test the success of the called function | |
208 | */ | |
209 | public function testCallUpdateGreetingSuccess() { | |
210 | $result = civicrm_api($this->_entity, 'update_greeting', array('gt' => 'postal_greeting', 'ct' => 'Individual', 'version' => $this->_apiVersion)); | |
211 | $this->assertAPISuccess($result); | |
212 | } | |
213 | ||
214 | public function testCallUpdateGreetingCommaSeparatedParamsSuccess() { | |
215 | $gt = 'postal_greeting,email_greeting,addressee'; | |
216 | $ct = 'Individual,Household'; | |
217 | $result = civicrm_api($this->_entity, 'update_greeting', array('gt' => $gt, 'ct' => $ct, 'version' => $this->_apiVersion)); | |
218 | $this->assertAPISuccess($result); | |
219 | } | |
220 | } | |
221 |