File tree 3 files changed +51
-7
lines changed
3 files changed +51
-7
lines changed Original file line number Diff line number Diff line change @@ -200,11 +200,6 @@ public function toRequest($prependKey = true)
200
200
201
201
/** @var AutopilotField $field */
202
202
foreach ($ this ->fields as $ field ) {
203
- //TODO: how do you "unset" fields with Autopilot? Their API doesn't say anything about it
204
- if ($ field ->getValue () === null ) {
205
- continue ;
206
- }
207
-
208
203
if (! $ field ->isReserved ()) {
209
204
$ result ['custom ' ][$ field ->formatName ()] = $ field ->getValue ();
210
205
} else {
@@ -246,4 +241,4 @@ function jsonSerialize()
246
241
{
247
242
return $ this ->toArray ();
248
243
}
249
- }
244
+ }
Original file line number Diff line number Diff line change @@ -229,7 +229,7 @@ public function setValue($value)
229
229
}
230
230
231
231
// type of field is set in the constructor
232
- if ($ this ->getType () !== $ type ) {
232
+ if (( $ this ->getType () !== $ type) && ! is_null ( $ value ) ) {
233
233
throw AutopilotException::typeMismatch ($ this ->getType (), $ type );
234
234
}
235
235
Original file line number Diff line number Diff line change @@ -163,6 +163,55 @@ public function testContactToRequest(UnitTester $I)
163
163
$ I ->assertEquals ($ expected ['contact ' ], $ contact ->toRequest ($ prependKey = false ));
164
164
}
165
165
166
+ public function testContactFieldsCanBeCleared (UnitTester $ I )
167
+ {
168
+ $ I ->wantTo ('clear contact fields ' );
169
+
170
+ $ values = [
171
+ 'FirstName ' => null ,
172
+ 'LastName ' => null ,
173
+ 'custom_fields ' => [
174
+ [
175
+ 'kind ' => 'Age ' ,
176
+ 'value ' => null ,
177
+ 'fieldType ' => 'integer ' ,
178
+ ],
179
+ [
180
+ 'kind ' => 'Birthday ' ,
181
+ 'value ' => null ,
182
+ 'fieldType ' => 'date ' ,
183
+ ],
184
+ [
185
+ 'kind ' => 'Category ' ,
186
+ 'value ' => null ,
187
+ 'fieldType ' => 'string ' ,
188
+ ],
189
+ [
190
+ 'kind ' => 'Completed Status ' ,
191
+ 'value ' => null ,
192
+ 'fieldType ' => 'float ' ,
193
+ ],
194
+ ],
195
+ ];
196
+
197
+ $ contact = new AutopilotContact ($ values );
198
+
199
+ $ expected = [
200
+ 'contact ' => [
201
+ 'FirstName ' => null ,
202
+ 'LastName ' => null ,
203
+ 'custom ' => [
204
+ 'integer--Age ' => null ,
205
+ 'date--Birthday ' => null ,
206
+ 'string--Category ' => null ,
207
+ 'float--Completed--Status ' => null ,
208
+ ],
209
+ ],
210
+ ];
211
+
212
+ $ I ->assertEquals ($ expected , $ contact ->toRequest ());
213
+ }
214
+
166
215
public function testContactMagicGettersAndSetters (UnitTester $ I )
167
216
{
168
217
$ I ->wantTo ('set and get values using magic methods ' );
You can’t perform that action at this time.
0 commit comments