Merge pull request #1833 from dakshayani/hr-13603
[civicrm-core.git] / api / v3 / examples / JobCreate.php
CommitLineData
6a488035 1<?php
fb32de45 2/**
3 * Test Generated example of using job create API
4 * *
6a488035
TO
5 */
6function job_create_example(){
53ca8fd7 7$params = array(
6a488035
TO
8 'sequential' => 1,
9 'name' => 'API_Test_Job',
10 'description' => 'A long description written by hand in cursive',
11 'run_frequency' => 'Daily',
12 'api_entity' => 'ApiTestEntity',
13 'api_action' => 'apitestaction',
14 'parameters' => 'Semi-formal explanation of runtime job parameters',
15 'is_active' => 1,
16);
17
fb32de45 18try{
19 $result = civicrm_api3('job', 'create', $params);
20}
21catch (CiviCRM_API3_Exception $e) {
22 // handle error here
23 $errorMessage = $e->getMessage();
24 $errorCode = $e->getErrorCode();
25 $errorData = $e->getExtraParams();
26 return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
27}
6a488035 28
fb32de45 29return $result;
6a488035
TO
30}
31
fb32de45 32/**
6a488035
TO
33 * Function returns array of result expected from previous function
34 */
35function job_create_expectedresult(){
36
53ca8fd7 37 $expectedResult = array(
6a488035
TO
38 'is_error' => 0,
39 'version' => 3,
40 'count' => 1,
41 'id' => 1,
53ca8fd7 42 'values' => array(
43 '0' => array(
6a488035
TO
44 'id' => '1',
45 'domain_id' => '1',
46 'run_frequency' => 'Daily',
47 'last_run' => '',
48 'name' => 'API_Test_Job',
49 'description' => 'A long description written by hand in cursive',
50 'api_entity' => 'ApiTestEntity',
51 'api_action' => 'apitestaction',
52 'parameters' => 'Semi-formal explanation of runtime job parameters',
53 'is_active' => '1',
54 ),
55 ),
56);
57
fb32de45 58 return $expectedResult;
6a488035
TO
59}
60
61
62/*
63* This example has been generated from the API test suite. The test that created it is called
64*
65* testCreate and can be found in
66* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/JobTest.php
67*
68* You can see the outcome of the API tests at
69* http://tests.dev.civicrm.org/trunk/results-api_v3
70*
71* To Learn about the API read
72* http://book.civicrm.org/developer/current/techniques/api/
73*
74* and review the wiki at
75* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
76*
77* Read more about testing here
78* http://wiki.civicrm.org/confluence/display/CRM/Testing
79*
80* API Standards documentation:
81* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
82*/