|
13 | 13 | use FormStack\FSField; |
14 | 14 | use FormStack\FSForm; |
15 | 15 | use FormStack\FSSubmission; |
| 16 | +use GuzzleHttp\Exception\RequestException; |
16 | 17 | use PHPUnit\Framework\TestCase; |
17 | 18 |
|
18 | 19 | class FSFormUnitTest extends TestCase { |
19 | 20 |
|
20 | 21 | public function testForm_whenFormMethods_givenRequiredParams_thenPrintAPIResponse() { |
21 | 22 |
|
22 | | - $fsForm = new FSForm(); |
| 23 | + try { |
| 24 | + $fsForm = new FSForm(); |
23 | 25 |
|
24 | | - print("There are " . count($fsForm->all()) . " forms in record\n"); |
| 26 | + print("There are " . count($fsForm->all()) . " forms in record\n"); |
25 | 27 |
|
26 | | - print("\nTrying to create a form with the api\n"); |
27 | | - print_r( $newForm = $fsForm->create(["name" => "Created by API"])); |
| 28 | + print("\nTrying to create a form with the api\n"); |
| 29 | + print_r($newForm = $fsForm->create(["name" => "Created by API"])); |
28 | 30 |
|
29 | | - print("\nThere are ". count($allForms = $fsForm->all()) . " forms in record after api creation\n"); |
| 31 | + print("\nThere are " . count($allForms = $fsForm->all()) . " forms in record after api creation\n"); |
30 | 32 |
|
31 | | - $formId = $newForm["id"]; |
| 33 | + $formId = $newForm["id"]; |
32 | 34 |
|
33 | | - /* |
34 | | - * testing FSField |
35 | | - * */ |
| 35 | + /* |
| 36 | + * testing FSField |
| 37 | + * */ |
36 | 38 |
|
37 | | - $fsField = new FSField(); |
| 39 | + $fsField = new FSField(); |
38 | 40 |
|
39 | | - print("\nGetting all fields for the created form\n"); |
40 | | - print_r($allFields = $fsField->all($formId)); |
| 41 | + print("\nGetting all fields for the created form\n"); |
| 42 | + print_r($allFields = $fsField->all($formId)); |
41 | 43 |
|
42 | | - print_r("\nAdding a new field to the created form"); |
43 | | - $param = ["field_type" => "text", "label" => "Dev API Created Field"]; |
44 | | - print_r($field = $fsField->newField($formId, $param)); |
| 44 | + print_r("\nAdding a new field to the created form"); |
| 45 | + $param = ["field_type" => "text", "label" => "Dev API Created Field"]; |
| 46 | + print_r($field = $fsField->newField($formId, $param)); |
45 | 47 |
|
46 | | - $fieldId = $field["id"]; |
| 48 | + $fieldId = $field["id"]; |
47 | 49 |
|
48 | | - print("\nDetails of created field \n"); |
49 | | - print_r($fieldDetail = $fsField->get($fieldId)); |
| 50 | + print("\nDetails of created field \n"); |
| 51 | + print_r($fieldDetail = $fsField->get($fieldId)); |
50 | 52 |
|
51 | | - print_r("\nUpdating created field ". $fieldDetail["label"]); |
| 53 | + print_r("\nUpdating created field " . $fieldDetail["label"]); |
52 | 54 |
|
53 | | - $param = ["field_type" => "text", "label" => "Dev API Updated"]; |
54 | | - print_r($fsField->update($fieldId, $param)); |
| 55 | + $param = ["field_type" => "text", "label" => "Dev API Updated"]; |
| 56 | + print_r($fsField->update($fieldId, $param)); |
55 | 57 |
|
56 | | - print("\nDetails of updated field"); |
57 | | - print_r( $fsField->get($fieldId)); |
| 58 | + print("\nDetails of updated field"); |
| 59 | + print_r($fsField->get($fieldId)); |
58 | 60 |
|
59 | 61 |
|
60 | | - print("\nGetting details for form ". $newForm["name"]."\n"); |
61 | | - print_r($detail = $fsForm->get($formId)); |
| 62 | + print("\nGetting details for form " . $newForm["name"] . "\n"); |
| 63 | + print_r($detail = $fsForm->get($formId)); |
62 | 64 |
|
63 | | - print_r("\nUpdating the details - name \n"); |
64 | | - print_r($fsForm->update($formId, ["name" => $detail["name"] . " updated by API"])); |
| 65 | + print_r("\nUpdating the details - name \n"); |
| 66 | + print_r($fsForm->update($formId, ["name" => $detail["name"] . " updated by API"])); |
65 | 67 |
|
66 | | - print("\nGetting details for form after update\n"); |
67 | | - print_r($fsForm->get($formId)); |
| 68 | + print("\nGetting details for form after update\n"); |
| 69 | + print_r($fsForm->get($formId)); |
68 | 70 |
|
69 | | - /* |
70 | | - * Testing FSSubmission |
71 | | - * */ |
| 71 | + /* |
| 72 | + * Testing FSSubmission |
| 73 | + * */ |
72 | 74 |
|
73 | | - $fsSubmission = new FSSubmission(); |
| 75 | + $fsSubmission = new FSSubmission(); |
74 | 76 |
|
75 | | - print("\nMaking a Submission to the Created Form\n"); |
76 | | - $data = [ |
77 | | - "field_".$fieldId => "Demo Organization", |
78 | | - ]; |
79 | | - print_r($fsSubmission->newSubmission($formId, $data)); |
| 77 | + print("\nMaking a Submission to the Created Form\n"); |
| 78 | + $data = [ |
| 79 | + "field_" . $fieldId => "Demo Organization", |
| 80 | + ]; |
| 81 | + print_r($fsSubmission->newSubmission($formId, $data)); |
80 | 82 |
|
81 | | - print("\nCounting all Submissions to the Form\n"); |
82 | | - $allSubmissions = $fsSubmission->all($formId); |
83 | | - print("\nThere are " . count($allSubmissions) . " submissions"); |
| 83 | + print("\nCounting all Submissions to the Form\n"); |
| 84 | + $allSubmissions = $fsSubmission->all($formId); |
| 85 | + print("\nThere are " . count($allSubmissions) . " submissions"); |
84 | 86 |
|
85 | | - print("\nDetails of a Single Submission\n"); |
86 | | - print_r($fsSubmission->get($allSubmissions["submissions"][0]["id"])); |
| 87 | + print("\nDetails of a Single Submission\n"); |
| 88 | + print_r($fsSubmission->get($allSubmissions["submissions"][0]["id"])); |
87 | 89 |
|
88 | | - print("\nUpdating a Submission\n"); |
89 | | - $data = [ |
90 | | - "field_".$fieldId => "Demo Organization Updated", |
91 | | - ]; |
92 | | - print_r($fsSubmission->update($allSubmissions["submissions"][0]["id"], $data)); |
| 90 | + print("\nUpdating a Submission\n"); |
| 91 | + $data = [ |
| 92 | + "field_" . $fieldId => "Demo Organization Updated", |
| 93 | + ]; |
| 94 | + print_r($fsSubmission->update($allSubmissions["submissions"][0]["id"], $data)); |
93 | 95 |
|
94 | 96 |
|
| 97 | + /* |
| 98 | + * Deleting Operations |
| 99 | + * */ |
95 | 100 |
|
| 101 | + print("\nDeleting API Submitted Submission\n"); |
| 102 | + print_r($fsSubmission->delete($allSubmissions["submissions"][0]["id"])); |
96 | 103 |
|
| 104 | + print("\nDeleting API Created field\n"); |
| 105 | + print_r($fsField->delete($fieldId)); |
97 | 106 |
|
98 | | - /* |
99 | | - * Deleting Operations |
100 | | - * */ |
| 107 | + print("\nDeleting API created form\n"); |
| 108 | + print_r($fsForm->delete($formId)); |
101 | 109 |
|
102 | | - print("\nDeleting API Submitted Submission\n"); |
103 | | - print_r($fsSubmission->delete($allSubmissions["submissions"][0]["id"])); |
104 | | - |
105 | | - print("\nDeleting API Created field\n"); |
106 | | - print_r($fsField->delete($fieldId)); |
107 | | - |
108 | | - print("\nDeleting API created form\n"); |
109 | | - print_r($fsForm->delete($formId)); |
| 110 | + }catch (RequestException $e) { |
| 111 | + print_r($e->getResponse()->getBody()); |
| 112 | + } |
110 | 113 |
|
111 | 114 | } |
112 | 115 |
|
|
0 commit comments