CRM-13072 upgrade Paritipant Payment test classes to pass
[civicrm-core.git] / tests / phpunit / api / v3 / JobTest.php
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 /**
29 * File for the CiviCRM APIv3 job functions
30 *
31 * @package CiviCRM_APIv3
32 * @subpackage API_Job
33 *
34 * @copyright CiviCRM LLC (c) 2004-2013
35 * @version $Id: Job.php 30879 2010-11-22 15:45:55Z shot $
36 *
37 */
38 require_once 'CiviTest/CiviUnitTestCase.php';
39 class api_v3_JobTest extends CiviUnitTestCase {
40 protected $_apiversion = 3;
41
42 public $_eNoticeCompliant = TRUE;
43 public $DBResetRequired = FALSE;
44 public $_entity = 'Job';
45
46 function setUp() {
47 parent::setUp();
48 $this->quickCleanup(array('civicrm_job'));
49 }
50
51 function tearDown() {
52 $this->quickCleanup(array('civicrm_job'));
53 parent::tearDown();
54 }
55
56 /**
57 * check with no name
58 */
59 function testCreateWithoutName() {
60 $params = array('is_active' => 1);
61 $result = $this->callAPIFailure('job', 'create', $params,
62 'Mandatory key(s) missing from params array: run_frequency, name, api_entity, api_action'
63 );
64 }
65 /**
66 * create job with an valid "run_frequency" value
67 */
68 function testCreateWithValidFrequency() {
69 $params = array(
70 'sequential' => 1,
71 'name' => 'API_Test_Job',
72 'description' => 'A long description written by hand in cursive',
73 'run_frequency' => 'Hourly',
74 'api_entity' => 'ApiTestEntity',
75 'api_action' => 'apitestaction',
76 'parameters' => 'Semi-formal explanation of runtime job parameters',
77 'is_active' => 1,
78 );
79 $result = $this->callAPISuccess('job', 'create', $params);
80 }
81
82 /**
83 * create job with an invalid "run_frequency" value
84 */
85 function testCreateWithInvalidFrequency() {
86 $params = array(
87 'sequential' => 1,
88 'name' => 'API_Test_Job',
89 'description' => 'A long description written by hand in cursive',
90 'run_frequency' => 'Fortnightly',
91 'api_entity' => 'ApiTestEntity',
92 'api_action' => 'apitestaction',
93 'parameters' => 'Semi-formal explanation of runtime job parameters',
94 'is_active' => 1,
95 );
96 $result = $this->callAPIFailure('job', 'create', $params);
97 }
98
99 /**
100 * create job
101 */
102 function testCreate() {
103 $params = array(
104 'sequential' => 1,
105 'name' => 'API_Test_Job',
106 'description' => 'A long description written by hand in cursive',
107 'run_frequency' => 'Daily',
108 'api_entity' => 'ApiTestEntity',
109 'api_action' => 'apitestaction',
110 'parameters' => 'Semi-formal explanation of runtime job parameters',
111 'is_active' => 1,
112 );
113 $result = $this->callAPIAndDocument('job', 'create', $params, __FUNCTION__, __FILE__);
114 $this->assertNotNull($result['values'][0]['id'], 'in line ' . __LINE__);
115
116 // mutate $params to match expected return value
117 unset($params['sequential']);
118 //assertDBState compares expected values in $result to actual values in the DB
119 $this->assertDBState('CRM_Core_DAO_Job', $result['id'], $params);
120 }
121
122 /**
123 * check with empty array
124 */
125 function testDeleteEmpty() {
126 $params = array();
127 $result = $this->callAPIFailure('job', 'delete', $params);
128 }
129
130 /**
131 * check with No array
132 */
133 function testDeleteParamsNotArray() {
134 $result = $this->callAPIFailure('job', 'delete', 'string');
135 }
136
137 /**
138 * check if required fields are not passed
139 */
140 function testDeleteWithoutRequired() {
141 $params = array(
142 'name' => 'API_Test_PP',
143 'title' => 'API Test Payment Processor',
144 'class_name' => 'CRM_Core_Payment_APITest',
145 );
146
147 $result = $this->callAPIFailure('job', 'delete', $params);
148 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: id');
149 }
150
151 /**
152 * check with incorrect required fields
153 * note to copy & pasters - this test is of marginal value
154 * and effort would be better put into making the one in syntax
155 * conformance work for all entities
156 */
157 function testDeleteWithIncorrectData() {
158 $params = array(
159 'id' => 'abcd');
160 $result = $this->callAPIFailure('job', 'delete', $params);
161 }
162
163 /**
164 * check job delete
165 */
166 function testDelete() {
167 $createParams = array(
168 'sequential' => 1,
169 'name' => 'API_Test_Job',
170 'description' => 'A long description written by hand in cursive',
171 'run_frequency' => 'Daily',
172 'api_entity' => 'ApiTestEntity',
173 'api_action' => 'apitestaction',
174 'parameters' => 'Semi-formal explanation of runtime job parameters',
175 'is_active' => 1,
176 );
177 $createResult = $this->callAPISuccess('job', 'create', $createParams);
178 $this->assertAPISuccess($createResult);
179
180 $params = array(
181 'id' => $createResult['id'],
182 );
183 $result = $this->callAPIAndDocument('job', 'delete', $params, __FUNCTION__, __FILE__);
184 }
185
186 /**
187
188 public function testCallUpdateGreetingMissingParams() {
189 $result = $this->callAPISuccess($this->_entity, 'update_greeting', array('gt' => 1));
190 $this->assertEquals('Mandatory key(s) missing from params array: ct', $result['error_message']);
191 }
192
193 public function testCallUpdateGreetingIncorrectParams() {
194 $result = $this->callAPISuccess($this->_entity, 'update_greeting', array('gt' => 1, 'ct' => 'djkfhdskjfhds'));
195 $this->assertEquals('ct `djkfhdskjfhds` is not valid.', $result['error_message']);
196 }
197 /*
198 * Note that this test is about tesing the metadata / calling of the function & doesn't test the success of the called function
199 */
200 public function testCallUpdateGreetingSuccess() {
201 $result = $this->callAPISuccess($this->_entity, 'update_greeting', array('gt' => 'postal_greeting', 'ct' => 'Individual'));
202 $this->assertAPISuccess($result);
203 }
204
205 public function testCallUpdateGreetingCommaSeparatedParamsSuccess() {
206 $gt = 'postal_greeting,email_greeting,addressee';
207 $ct = 'Individual,Household';
208 $result = $this->callAPISuccess($this->_entity, 'update_greeting', array('gt' => $gt, 'ct' => $ct));
209 $this->assertAPISuccess($result);
210 }
211 }
212