Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
3 | * Test Generated example of using grant create API. | |
4 | * | |
5 | * | |
6 | * @return array | |
7 | * API result array | |
8 | */ | |
9 | function grant_create_example() { | |
10 | $params = array( | |
11 | 'contact_id' => 3, | |
12 | 'application_received_date' => 'now', | |
13 | 'decision_date' => 'next Monday', | |
14 | 'amount_total' => '500', | |
15 | 'status_id' => 1, | |
16 | 'rationale' => 'Just Because', | |
17 | 'currency' => 'USD', | |
18 | 'grant_type_id' => 1, | |
19 | ); | |
6a488035 | 20 | |
50fb255d | 21 | try{ |
22 | $result = civicrm_api3('grant', 'create', $params); | |
23 | } | |
24 | catch (CiviCRM_API3_Exception $e) { | |
25 | // Handle error here. | |
26 | $errorMessage = $e->getMessage(); | |
27 | $errorCode = $e->getErrorCode(); | |
28 | $errorData = $e->getExtraParams(); | |
29 | return array( | |
30 | 'error' => $errorMessage, | |
31 | 'error_code' => $errorCode, | |
32 | 'error_data' => $errorData, | |
33 | ); | |
34 | } | |
35 | ||
36 | return $result; | |
6a488035 TO |
37 | } |
38 | ||
fb32de45 | 39 | /** |
50fb255d | 40 | * Function returns array of result expected from previous function. |
41 | * | |
42 | * @return array | |
43 | * API result array | |
6a488035 | 44 | */ |
50fb255d | 45 | function grant_create_expectedresult() { |
6a488035 | 46 | |
53ca8fd7 | 47 | $expectedResult = array( |
50fb255d | 48 | 'is_error' => 0, |
49 | 'version' => 3, | |
50 | 'count' => 1, | |
51 | 'id' => 1, | |
52 | 'values' => array( | |
53ca8fd7 | 53 | '1' => array( |
50fb255d | 54 | 'id' => '1', |
55 | 'contact_id' => '3', | |
56 | 'application_received_date' => '20130728084957', | |
57 | 'decision_date' => '20130805000000', | |
58 | 'money_transfer_date' => '', | |
59 | 'grant_due_date' => '', | |
60 | 'grant_report_received' => '', | |
61 | 'grant_type_id' => '1', | |
62 | 'amount_total' => '500', | |
63 | 'amount_requested' => '', | |
64 | 'amount_granted' => '', | |
65 | 'currency' => 'USD', | |
66 | 'rationale' => 'Just Because', | |
67 | 'status_id' => '1', | |
68 | 'financial_type_id' => '', | |
69 | ), | |
6a488035 | 70 | ), |
50fb255d | 71 | ); |
6a488035 | 72 | |
fb32de45 | 73 | return $expectedResult; |
6a488035 TO |
74 | } |
75 | ||
50fb255d | 76 | /** |
77 | * This example has been generated from the API test suite. | |
78 | * The test that created it is called | |
79 | * testCreateGrant | |
80 | * and can be found in | |
69d79249 | 81 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/GrantTest.php |
6a488035 TO |
82 | * |
83 | * You can see the outcome of the API tests at | |
69d79249 | 84 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
85 | * |
86 | * To Learn about the API read | |
69d79249 | 87 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 88 | * |
69d79249 E |
89 | * Browse the api on your own site with the api explorer |
90 | * http://MYSITE.ORG/path/to/civicrm/api/explorer | |
6a488035 TO |
91 | * |
92 | * Read more about testing here | |
93 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
94 | * | |
95 | * API Standards documentation: | |
96 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 97 | */ |