| 1 | <?php |
| 2 | /** |
| 3 | * Test Generated example of using custom_group create API |
| 4 | * * |
| 5 | */ |
| 6 | function custom_group_create_example(){ |
| 7 | $params = array( |
| 8 | 'title' => 'Test_Group_1', |
| 9 | 'name' => 'test_group_1', |
| 10 | 'extends' => array( |
| 11 | '0' => 'Individual', |
| 12 | ), |
| 13 | 'weight' => 4, |
| 14 | 'collapse_display' => 1, |
| 15 | 'style' => 'Inline', |
| 16 | 'help_pre' => 'This is Pre Help For Test Group 1', |
| 17 | 'help_post' => 'This is Post Help For Test Group 1', |
| 18 | 'is_active' => 1, |
| 19 | ); |
| 20 | |
| 21 | try{ |
| 22 | $result = civicrm_api3('custom_group', '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('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData); |
| 30 | } |
| 31 | |
| 32 | return $result; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Function returns array of result expected from previous function |
| 37 | */ |
| 38 | function custom_group_create_expectedresult(){ |
| 39 | |
| 40 | $expectedResult = array( |
| 41 | 'is_error' => 0, |
| 42 | 'version' => 3, |
| 43 | 'count' => 1, |
| 44 | 'id' => 1, |
| 45 | 'values' => array( |
| 46 | '1' => array( |
| 47 | 'id' => '1', |
| 48 | 'name' => 'test_group_1', |
| 49 | 'title' => 'Test_Group_1', |
| 50 | 'extends' => 'Individual', |
| 51 | 'extends_entity_column_id' => '', |
| 52 | 'extends_entity_column_value' => '', |
| 53 | 'style' => 'Inline', |
| 54 | 'collapse_display' => '1', |
| 55 | 'help_pre' => 'This is Pre Help For Test Group 1', |
| 56 | 'help_post' => 'This is Post Help For Test Group 1', |
| 57 | 'weight' => '2', |
| 58 | 'is_active' => '1', |
| 59 | 'table_name' => 'civicrm_value_test_group_1_1', |
| 60 | 'is_multiple' => '', |
| 61 | 'min_multiple' => '', |
| 62 | 'max_multiple' => '', |
| 63 | 'collapse_adv_display' => '', |
| 64 | 'created_id' => '', |
| 65 | 'created_date' => '', |
| 66 | 'is_reserved' => '', |
| 67 | ), |
| 68 | ), |
| 69 | ); |
| 70 | |
| 71 | return $expectedResult; |
| 72 | } |
| 73 | |
| 74 | |
| 75 | /* |
| 76 | * This example has been generated from the API test suite. The test that created it is called |
| 77 | * |
| 78 | * testCustomGroupCreate and can be found in |
| 79 | * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/CustomGroupTest.php |
| 80 | * |
| 81 | * You can see the outcome of the API tests at |
| 82 | * http://tests.dev.civicrm.org/trunk/results-api_v3 |
| 83 | * |
| 84 | * To Learn about the API read |
| 85 | * http://book.civicrm.org/developer/current/techniques/api/ |
| 86 | * |
| 87 | * and review the wiki at |
| 88 | * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs |
| 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 |
| 95 | */ |