Merge pull request #5020 from pratikshad/4.6-alpha4
[civicrm-core.git] / api / v3 / examples / Phone / Create.php
CommitLineData
6a488035 1<?php
fb32de45 2/**
50fb255d 3 * @file
4 * Test Generated API Example.
5 * See bottom of this file for more detail.
6a488035 6 */
6a488035 7
50fb255d 8/**
9 * Test Generated example of using phone create API.
10 *
11 *
12 * @return array
13 * API result array
14 */
15function phone_create_example() {
16 $params = array(
17 'contact_id' => 3,
18 'location_type_id' => 6,
19 'phone' => '(123) 456-7890',
20 'is_primary' => 1,
21 'phone_type_id' => 1,
22 );
6a488035 23
50fb255d 24 try{
25 $result = civicrm_api3('phone', 'create', $params);
26 }
27 catch (CiviCRM_API3_Exception $e) {
28 // Handle error here.
29 $errorMessage = $e->getMessage();
30 $errorCode = $e->getErrorCode();
31 $errorData = $e->getExtraParams();
32 return array(
33 'error' => $errorMessage,
34 'error_code' => $errorCode,
35 'error_data' => $errorData,
36 );
37 }
38
39 return $result;
6a488035
TO
40}
41
fb32de45 42/**
50fb255d 43 * Function returns array of result expected from previous function.
44 *
45 * @return array
46 * API result array
6a488035 47 */
50fb255d 48function phone_create_expectedresult() {
6a488035 49
53ca8fd7 50 $expectedResult = array(
50fb255d 51 'is_error' => 0,
52 'version' => 3,
53 'count' => 1,
54 'id' => 2,
55 'values' => array(
56 '2' => array(
57 'id' => '2',
58 'contact_id' => '3',
59 'location_type_id' => '6',
60 'is_primary' => '1',
61 'is_billing' => '',
62 'mobile_provider_id' => '',
63 'phone' => '(123) 456-7890',
64 'phone_ext' => '',
65 'phone_numeric' => '',
66 'phone_type_id' => '1',
67 ),
6a488035 68 ),
50fb255d 69 );
6a488035 70
fb32de45 71 return $expectedResult;
6a488035
TO
72}
73
50fb255d 74/**
75* This example has been generated from the API test suite.
76* The test that created it is called
77* testCreatePhone
78* and can be found in
69d79249 79* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/PhoneTest.php
6a488035
TO
80*
81* You can see the outcome of the API tests at
69d79249 82* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
83*
84* To Learn about the API read
69d79249 85* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 86*
69d79249
E
87* Browse the api on your own site with the api explorer
88* http://MYSITE.ORG/path/to/civicrm/api/explorer
6a488035
TO
89*
90* Read more about testing here
91* http://wiki.civicrm.org/confluence/display/CRM/Testing
92*
93* API Standards documentation:
94* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 95*/