1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package userforms |
5
|
|
|
*/ |
6
|
|
|
class UserDefinedFormTest extends FunctionalTest |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
|
9
|
|
|
public static $fixture_file = 'UserDefinedFormTest.yml'; |
10
|
|
|
|
11
|
|
View Code Duplication |
public function testRollbackToVersion() |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
$this->markTestSkipped( |
|
|
|
|
14
|
|
|
'UserDefinedForm::rollback() has not been implemented completely' |
15
|
|
|
); |
16
|
|
|
|
17
|
|
|
// @todo |
18
|
|
|
$this->logInWithPermission('ADMIN'); |
19
|
|
|
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page'); |
20
|
|
|
|
21
|
|
|
$form->SubmitButtonText = 'Button Text'; |
22
|
|
|
$form->write(); |
23
|
|
|
$form->doPublish(); |
24
|
|
|
$origVersion = $form->Version; |
25
|
|
|
|
26
|
|
|
$form->SubmitButtonText = 'Updated Button Text'; |
27
|
|
|
$form->write(); |
28
|
|
|
$form->doPublish(); |
29
|
|
|
|
30
|
|
|
// check published site |
31
|
|
|
$updated = Versioned::get_one_by_stage("UserDefinedForm", "Stage", "\"UserDefinedForm\".\"ID\" = $form->ID"); |
32
|
|
|
$this->assertEquals($updated->SubmitButtonText, 'Updated Button Text'); |
|
|
|
|
33
|
|
|
|
34
|
|
|
$form->doRollbackTo($origVersion); |
35
|
|
|
|
36
|
|
|
$orignal = Versioned::get_one_by_stage("UserDefinedForm", "Stage", "\"UserDefinedForm\".\"ID\" = $form->ID"); |
37
|
|
|
$this->assertEquals($orignal->SubmitButtonText, 'Button Text'); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testGetCMSFields() |
41
|
|
|
{ |
42
|
|
|
$this->logInWithPermission('ADMIN'); |
43
|
|
|
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page'); |
44
|
|
|
|
45
|
|
|
$fields = $form->getCMSFields(); |
46
|
|
|
|
47
|
|
|
$this->assertTrue($fields->dataFieldByName('Fields') !== null); |
|
|
|
|
48
|
|
|
$this->assertTrue($fields->dataFieldByName('EmailRecipients') != null); |
|
|
|
|
49
|
|
|
$this->assertTrue($fields->dataFieldByName('Submissions') != null); |
|
|
|
|
50
|
|
|
$this->assertTrue($fields->dataFieldByName('OnCompleteMessage') != null); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function testGetCMSFieldsShowInSummary() |
55
|
|
|
{ |
56
|
|
|
$this->logInWithPermission('ADMIN'); |
57
|
|
|
$form = $this->objFromFixture('UserDefinedForm', 'summary-rules-form'); |
58
|
|
|
|
59
|
|
|
$fields = $form->getCMSFields(); |
60
|
|
|
|
61
|
|
|
$this->assertInstanceOf('GridField', $fields->dataFieldByName('Submissions')); |
|
|
|
|
62
|
|
|
|
63
|
|
|
$submissionsgrid = $fields->dataFieldByName('Submissions'); |
64
|
|
|
$gridFieldDataColumns = $submissionsgrid->getConfig()->getComponentByType('GridFieldDataColumns'); |
65
|
|
|
|
66
|
|
|
$summaryFields = $gridFieldDataColumns->getDisplayFields($submissionsgrid); |
67
|
|
|
|
68
|
|
|
$this->assertContains('SummaryShow', array_keys($summaryFields), 'Summary field not showing displayed field'); |
69
|
|
|
$this->assertNotContains('SummaryHide', array_keys($summaryFields), 'Summary field showing displayed field'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
public function testEmailRecipientPopup() |
74
|
|
|
{ |
75
|
|
|
$this->logInWithPermission('ADMIN'); |
76
|
|
|
|
77
|
|
|
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page'); |
78
|
|
|
|
79
|
|
|
$popup = new UserDefinedForm_EmailRecipient(); |
80
|
|
|
$popup->FormID = $form->ID; |
|
|
|
|
81
|
|
|
|
82
|
|
|
$fields = $popup->getCMSFields(); |
83
|
|
|
|
84
|
|
|
$this->assertTrue($fields->dataFieldByName('EmailSubject') !== null); |
|
|
|
|
85
|
|
|
$this->assertTrue($fields->dataFieldByName('EmailFrom') !== null); |
|
|
|
|
86
|
|
|
$this->assertTrue($fields->dataFieldByName('EmailAddress') !== null); |
|
|
|
|
87
|
|
|
$this->assertTrue($fields->dataFieldByName('HideFormData') !== null); |
|
|
|
|
88
|
|
|
$this->assertTrue($fields->dataFieldByName('SendPlain') !== null); |
|
|
|
|
89
|
|
|
$this->assertTrue($fields->dataFieldByName('EmailBody') !== null); |
|
|
|
|
90
|
|
|
|
91
|
|
|
// add an email field, it should now add a or from X address picker |
92
|
|
|
$email = $this->objFromFixture('EditableEmailField', 'email-field'); |
93
|
|
|
$form->Fields()->add($email); |
|
|
|
|
94
|
|
|
|
95
|
|
|
$popup->write(); |
96
|
|
|
|
97
|
|
|
$fields = $popup->getCMSFields(); |
98
|
|
|
$this->assertThat($fields->dataFieldByName('SendEmailToFieldID'), $this->isInstanceOf('DropdownField')); |
|
|
|
|
99
|
|
|
|
100
|
|
|
// if the front end has checkboxs or dropdown they can select from that can also be used to send things |
101
|
|
|
$dropdown = $this->objFromFixture('EditableDropdown', 'department-dropdown'); |
102
|
|
|
$form->Fields()->add($dropdown); |
|
|
|
|
103
|
|
|
|
104
|
|
|
$fields = $popup->getCMSFields(); |
105
|
|
|
$this->assertTrue($fields->dataFieldByName('SendEmailToFieldID') !== null); |
|
|
|
|
106
|
|
|
|
107
|
|
|
$popup->delete(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function testGetEmailBodyContent() |
111
|
|
|
{ |
112
|
|
|
$recipient = new UserDefinedForm_EmailRecipient(); |
113
|
|
|
|
114
|
|
|
$emailBody = 'not html'; |
115
|
|
|
$emailBodyHtml = '<p>html</p>'; |
116
|
|
|
|
117
|
|
|
$recipient->EmailBody = $emailBody; |
|
|
|
|
118
|
|
|
$recipient->EmailBodyHtml = $emailBodyHtml; |
|
|
|
|
119
|
|
|
$recipient->write(); |
120
|
|
|
|
121
|
|
|
$this->assertEquals($recipient->SendPlain, 0); |
|
|
|
|
122
|
|
|
$this->assertEquals($recipient->getEmailBodyContent(), $emailBodyHtml); |
|
|
|
|
123
|
|
|
|
124
|
|
|
$recipient->SendPlain = 1; |
|
|
|
|
125
|
|
|
$recipient->write(); |
126
|
|
|
|
127
|
|
|
$this->assertEquals($recipient->getEmailBodyContent(), $emailBody); |
|
|
|
|
128
|
|
|
|
129
|
|
|
$recipient->delete(); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function testGetEmailTemplateDropdownValues() |
133
|
|
|
{ |
134
|
|
|
$recipient = new UserDefinedForm_EmailRecipient(); |
135
|
|
|
|
136
|
|
|
$defaultValues = array('SubmittedFormEmail' => 'SubmittedFormEmail'); |
137
|
|
|
|
138
|
|
|
$this->assertEquals($recipient->getEmailTemplateDropdownValues(), $defaultValues); |
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function testEmailTemplateExists() |
142
|
|
|
{ |
143
|
|
|
$recipient = new UserDefinedForm_EmailRecipient(); |
144
|
|
|
|
145
|
|
|
// Set the default template |
146
|
|
|
$recipient->EmailTemplate = current(array_keys($recipient->getEmailTemplateDropdownValues())); |
|
|
|
|
147
|
|
|
$recipient->write(); |
148
|
|
|
|
149
|
|
|
// The default template exists |
150
|
|
|
$this->assertTrue($recipient->emailTemplateExists()); |
|
|
|
|
151
|
|
|
|
152
|
|
|
// A made up template doesn't exists |
153
|
|
|
$this->assertFalse($recipient->emailTemplateExists('MyTemplateThatsNotThere')); |
|
|
|
|
154
|
|
|
|
155
|
|
|
$recipient->delete(); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function testCanEditAndDeleteRecipient() |
159
|
|
|
{ |
160
|
|
|
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page'); |
161
|
|
|
|
162
|
|
|
$this->logInWithPermission('ADMIN'); |
163
|
|
|
foreach ($form->EmailRecipients() as $recipient) { |
164
|
|
|
$this->assertTrue($recipient->canEdit()); |
|
|
|
|
165
|
|
|
$this->assertTrue($recipient->canDelete()); |
|
|
|
|
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
$member = Member::currentUser(); |
169
|
|
|
$member->logOut(); |
170
|
|
|
|
171
|
|
|
$this->logInWithPermission('SITETREE_VIEW_ALL'); |
172
|
|
|
foreach ($form->EmailRecipients() as $recipient) { |
173
|
|
|
$this->assertFalse($recipient->canEdit()); |
|
|
|
|
174
|
|
|
$this->assertFalse($recipient->canDelete()); |
|
|
|
|
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function testPublishing() |
179
|
|
|
{ |
180
|
|
|
$this->logInWithPermission('ADMIN'); |
181
|
|
|
|
182
|
|
|
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page'); |
183
|
|
|
$form->write(); |
184
|
|
|
|
185
|
|
|
$form->doPublish(); |
186
|
|
|
|
187
|
|
|
$live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID"); |
188
|
|
|
|
189
|
|
|
$this->assertNotNull($live); |
|
|
|
|
190
|
|
|
$this->assertEquals(2, $live->Fields()->Count()); // one page and one field |
|
|
|
|
191
|
|
|
|
192
|
|
|
$dropdown = $this->objFromFixture('EditableDropdown', 'basic-dropdown'); |
193
|
|
|
$form->Fields()->add($dropdown); |
|
|
|
|
194
|
|
|
|
195
|
|
|
$stage = Versioned::get_one_by_stage("UserDefinedForm", "Stage", "\"UserDefinedForm\".\"ID\" = $form->ID"); |
196
|
|
|
$this->assertEquals(3, $stage->Fields()->Count()); |
|
|
|
|
197
|
|
|
|
198
|
|
|
// should not have published the dropdown |
199
|
|
|
$liveDropdown = Versioned::get_one_by_stage("EditableFormField", "Live", "\"EditableFormField_Live\".\"ID\" = $dropdown->ID"); |
200
|
|
|
$this->assertNull($liveDropdown); |
|
|
|
|
201
|
|
|
|
202
|
|
|
// when publishing it should have added it |
203
|
|
|
$form->doPublish(); |
204
|
|
|
|
205
|
|
|
$live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID"); |
206
|
|
|
$this->assertEquals(3, $live->Fields()->Count()); |
|
|
|
|
207
|
|
|
|
208
|
|
|
// edit the title |
209
|
|
|
$text = $form->Fields()->limit(1, 1)->First(); |
|
|
|
|
210
|
|
|
$text->Title = 'Edited title'; |
211
|
|
|
$text->write(); |
212
|
|
|
|
213
|
|
|
$liveText = Versioned::get_one_by_stage("EditableFormField", "Live", "\"EditableFormField_Live\".\"ID\" = $text->ID"); |
214
|
|
|
$this->assertFalse($liveText->Title == $text->Title); |
|
|
|
|
215
|
|
|
|
216
|
|
|
$form->doPublish(); |
217
|
|
|
|
218
|
|
|
$liveText = Versioned::get_one_by_stage("EditableFormField", "Live", "\"EditableFormField_Live\".\"ID\" = $text->ID"); |
219
|
|
|
$this->assertTrue($liveText->Title == $text->Title); |
|
|
|
|
220
|
|
|
|
221
|
|
|
// Add a display rule to the dropdown |
222
|
|
|
$displayRule = new EditableCustomRule(); |
223
|
|
|
$displayRule->ParentID = $dropdown->ID; |
|
|
|
|
224
|
|
|
$displayRule->ConditionFieldID = $text->ID; |
|
|
|
|
225
|
|
|
$displayRule->write(); |
226
|
|
|
$ruleID = $displayRule->ID; |
227
|
|
|
|
228
|
|
|
// Not live |
229
|
|
|
$liveRule = Versioned::get_one_by_stage("EditableCustomRule", "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID"); |
230
|
|
|
$this->assertEmpty($liveRule); |
|
|
|
|
231
|
|
|
|
232
|
|
|
// Publish form, it's now live |
233
|
|
|
$form->doPublish(); |
234
|
|
|
$liveRule = Versioned::get_one_by_stage("EditableCustomRule", "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID"); |
235
|
|
|
$this->assertNotEmpty($liveRule); |
|
|
|
|
236
|
|
|
|
237
|
|
|
// Remove rule |
238
|
|
|
$displayRule->delete(); |
239
|
|
|
|
240
|
|
|
// Live rule still exists |
241
|
|
|
$liveRule = Versioned::get_one_by_stage("EditableCustomRule", "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID"); |
242
|
|
|
$this->assertNotEmpty($liveRule); |
|
|
|
|
243
|
|
|
|
244
|
|
|
// Publish form, it should remove this rule |
245
|
|
|
$form->doPublish(); |
246
|
|
|
$liveRule = Versioned::get_one_by_stage("EditableCustomRule", "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID"); |
247
|
|
|
$this->assertEmpty($liveRule); |
|
|
|
|
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
public function testUnpublishing() |
251
|
|
|
{ |
252
|
|
|
$this->logInWithPermission('ADMIN'); |
253
|
|
|
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page'); |
254
|
|
|
$form->write(); |
255
|
|
|
$this->assertEquals(0, DB::query("SELECT COUNT(*) FROM \"EditableFormField_Live\"")->value()); |
|
|
|
|
256
|
|
|
$form->doPublish(); |
257
|
|
|
|
258
|
|
|
// assert that it exists and has a field |
259
|
|
|
$live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID"); |
260
|
|
|
|
261
|
|
|
$this->assertTrue(isset($live)); |
|
|
|
|
262
|
|
|
$this->assertEquals(2, DB::query("SELECT COUNT(*) FROM \"EditableFormField_Live\"")->value()); |
|
|
|
|
263
|
|
|
|
264
|
|
|
// unpublish |
265
|
|
|
$form->doUnpublish(); |
266
|
|
|
|
267
|
|
|
$this->assertNull(Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = $form->ID")); |
|
|
|
|
268
|
|
|
$this->assertEquals(0, DB::query("SELECT COUNT(*) FROM \"EditableFormField_Live\"")->value()); |
|
|
|
|
269
|
|
|
} |
270
|
|
|
|
271
|
|
View Code Duplication |
public function testDoRevertToLive() |
|
|
|
|
272
|
|
|
{ |
273
|
|
|
$this->logInWithPermission('ADMIN'); |
274
|
|
|
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page'); |
275
|
|
|
$field = $form->Fields()->First(); |
|
|
|
|
276
|
|
|
|
277
|
|
|
$field->Title = 'Title'; |
278
|
|
|
$field->write(); |
279
|
|
|
|
280
|
|
|
$form->doPublish(); |
281
|
|
|
|
282
|
|
|
$field->Title = 'Edited title'; |
283
|
|
|
$field->write(); |
284
|
|
|
|
285
|
|
|
// check that the published version is not updated |
286
|
|
|
$live = Versioned::get_one_by_stage("EditableFormField", "Live", "\"EditableFormField_Live\".\"ID\" = $field->ID"); |
287
|
|
|
$this->assertEquals('Title', $live->Title); |
|
|
|
|
288
|
|
|
|
289
|
|
|
// revert back to the live data |
290
|
|
|
$form->doRevertToLive(); |
291
|
|
|
$form->flushCache(); |
292
|
|
|
|
293
|
|
|
$check = Versioned::get_one_by_stage("EditableFormField", "Stage", "\"EditableFormField\".\"ID\" = $field->ID"); |
294
|
|
|
|
295
|
|
|
$this->assertEquals('Title', $check->Title); |
|
|
|
|
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
public function testDuplicatingForm() |
299
|
|
|
{ |
300
|
|
|
$this->logInWithPermission('ADMIN'); |
301
|
|
|
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page'); |
302
|
|
|
|
303
|
|
|
$duplicate = $form->duplicate(); |
304
|
|
|
|
305
|
|
|
$this->assertEquals($form->Fields()->Count(), $duplicate->Fields()->Count()); |
|
|
|
|
306
|
|
|
$this->assertEquals($form->EmailRecipients()->Count(), $form->EmailRecipients()->Count()); |
|
|
|
|
307
|
|
|
|
308
|
|
|
// can't compare object since the dates/ids change |
309
|
|
|
$this->assertEquals($form->Fields()->First()->Title, $duplicate->Fields()->First()->Title); |
|
|
|
|
310
|
|
|
|
311
|
|
|
// Test duplicate with group |
312
|
|
|
$form2 = $this->objFromFixture('UserDefinedForm', 'page-with-group'); |
313
|
|
|
$form2Validator = new UserFormValidator(); |
314
|
|
|
$form2Validator->setForm(new Form(new Controller(), 'Form', new FieldList(), new FieldList())); |
315
|
|
|
$this->assertTrue($form2Validator->php($form2->toMap())); |
|
|
|
|
316
|
|
|
|
317
|
|
|
// Check field groups exist |
318
|
|
|
$form2GroupStart = $form2->Fields()->filter('ClassName', 'EditableFieldGroup')->first(); |
|
|
|
|
319
|
|
|
$form2GroupEnd = $form2->Fields()->filter('ClassName', 'EditableFieldGroupEnd')->first(); |
|
|
|
|
320
|
|
|
$this->assertEquals($form2GroupEnd->ID, $form2GroupStart->EndID); |
|
|
|
|
321
|
|
|
|
322
|
|
|
// Duplicate this |
323
|
|
|
$form3 = $form2->duplicate(); |
324
|
|
|
$form3Validator = new UserFormValidator(); |
325
|
|
|
$form3Validator->setForm(new Form(new Controller(), 'Form', new FieldList(), new FieldList())); |
326
|
|
|
$this->assertTrue($form3Validator->php($form3->toMap())); |
|
|
|
|
327
|
|
|
|
328
|
|
|
// Check field groups exist |
329
|
|
|
$form3GroupStart = $form3->Fields()->filter('ClassName', 'EditableFieldGroup')->first(); |
330
|
|
|
$form3GroupEnd = $form3->Fields()->filter('ClassName', 'EditableFieldGroupEnd')->first(); |
331
|
|
|
$this->assertEquals($form3GroupEnd->ID, $form3GroupStart->EndID); |
|
|
|
|
332
|
|
|
$this->assertNotEquals($form2GroupEnd->ID, $form3GroupStart->EndID); |
|
|
|
|
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
public function testFormOptions() |
336
|
|
|
{ |
337
|
|
|
$this->logInWithPermission('ADMIN'); |
338
|
|
|
$form = $this->objFromFixture('UserDefinedForm', 'basic-form-page'); |
339
|
|
|
|
340
|
|
|
$fields = $form->getFormOptions(); |
341
|
|
|
$submit = $fields->fieldByName('SubmitButtonText'); |
342
|
|
|
$reset = $fields->fieldByName('ShowClearButton'); |
343
|
|
|
|
344
|
|
|
$this->assertEquals($submit->Title(), 'Text on submit button:'); |
|
|
|
|
345
|
|
|
$this->assertEquals($reset->Title(), 'Show Clear Form Button'); |
|
|
|
|
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
public function testEmailRecipientFilters() |
349
|
|
|
{ |
350
|
|
|
/** @var UserDefinedForm $form */ |
351
|
|
|
$form = $this->objFromFixture('UserDefinedForm', 'filtered-form-page'); |
352
|
|
|
|
353
|
|
|
// Check unfiltered recipients |
354
|
|
|
$result0 = $form |
355
|
|
|
->EmailRecipients() |
356
|
|
|
->sort('EmailAddress') |
357
|
|
|
->column('EmailAddress'); |
358
|
|
|
$this->assertEquals( |
|
|
|
|
359
|
|
|
array( |
360
|
|
|
'[email protected]', |
361
|
|
|
'[email protected]', |
362
|
|
|
'[email protected]' |
363
|
|
|
), |
364
|
|
|
$result0 |
365
|
|
|
); |
366
|
|
|
|
367
|
|
|
// check filters based on given data |
368
|
|
|
$result1 = $form->FilteredEmailRecipients( |
369
|
|
|
array( |
370
|
|
|
'your-name' => 'Value', |
371
|
|
|
'address' => '', |
372
|
|
|
'street' => 'Anything', |
373
|
|
|
'city' => 'Matches Not Equals', |
374
|
|
|
'colours' => array('Red') // matches 2 |
375
|
|
|
), null |
376
|
|
|
) |
377
|
|
|
->sort('EmailAddress') |
378
|
|
|
->column('EmailAddress'); |
379
|
|
|
$this->assertEquals( |
|
|
|
|
380
|
|
|
array( |
381
|
|
|
'[email protected]', |
382
|
|
|
'[email protected]' |
383
|
|
|
), |
384
|
|
|
$result1 |
385
|
|
|
); |
386
|
|
|
|
387
|
|
|
// Check all positive matches |
388
|
|
|
$result2 = $form->FilteredEmailRecipients( |
389
|
|
|
array( |
390
|
|
|
'your-name' => '', |
391
|
|
|
'address' => 'Anything', |
392
|
|
|
'street' => 'Matches Equals', |
393
|
|
|
'city' => 'Anything', |
394
|
|
|
'colours' => array('Red', 'Blue') // matches 2 |
395
|
|
|
), null |
396
|
|
|
) |
397
|
|
|
->sort('EmailAddress') |
398
|
|
|
->column('EmailAddress'); |
399
|
|
|
$this->assertEquals( |
|
|
|
|
400
|
|
|
array( |
401
|
|
|
'[email protected]', |
402
|
|
|
'[email protected]', |
403
|
|
|
'[email protected]' |
404
|
|
|
), |
405
|
|
|
$result2 |
406
|
|
|
); |
407
|
|
|
|
408
|
|
|
$result3 = $form->FilteredEmailRecipients( |
409
|
|
|
array( |
410
|
|
|
'your-name' => 'Should be blank but is not', |
411
|
|
|
'address' => 'Anything', |
412
|
|
|
'street' => 'Matches Equals', |
413
|
|
|
'city' => 'Anything', |
414
|
|
|
'colours' => array('Blue') |
415
|
|
|
), null |
416
|
|
|
)->column('EmailAddress'); |
417
|
|
|
$this->assertEquals( |
|
|
|
|
418
|
|
|
array( |
419
|
|
|
'[email protected]' |
420
|
|
|
), |
421
|
|
|
$result3 |
422
|
|
|
); |
423
|
|
|
|
424
|
|
|
|
425
|
|
|
$result4 = $form->FilteredEmailRecipients( |
426
|
|
|
array( |
427
|
|
|
'your-name' => '', |
428
|
|
|
'address' => 'Anything', |
429
|
|
|
'street' => 'Wrong value for this field', |
430
|
|
|
'city' => '', |
431
|
|
|
'colours' => array('Blue', 'Green') |
432
|
|
|
), null |
433
|
|
|
)->column('EmailAddress'); |
434
|
|
|
$this->assertEquals( |
|
|
|
|
435
|
|
|
array( |
436
|
|
|
'[email protected]' |
437
|
|
|
), |
438
|
|
|
$result4 |
439
|
|
|
); |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
public function testIndex() |
443
|
|
|
{ |
444
|
|
|
// Test that the $UserDefinedForm is stripped out |
445
|
|
|
$page = $this->objFromFixture('UserDefinedForm', 'basic-form-page'); |
446
|
|
|
$page->publish('Stage', 'Live'); |
447
|
|
|
|
448
|
|
|
$result = $this->get($page->Link()); |
449
|
|
|
$body = Convert::nl2os($result->getBody(), ''); // strip out newlines |
450
|
|
|
$this->assertFalse($result->isError()); |
|
|
|
|
451
|
|
|
$this->assertContains('<p>Here is my form</p><form', $body); |
452
|
|
|
$this->assertContains('</form><p>Thank you for filling it out</p>', $body); |
453
|
|
|
|
454
|
|
|
$this->assertNotContains('<p>$UserDefinedForm</p>', $body); |
455
|
|
|
$this->assertNotContains('<p></p>', $body); |
456
|
|
|
$this->assertNotContains('</p><p>Thank you for filling it out</p>', $body); |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
public function testEmailAddressValidation() |
460
|
|
|
{ |
461
|
|
|
$this->logInWithPermission('ADMIN'); |
462
|
|
|
|
463
|
|
|
// test invalid email addresses fail validation |
464
|
|
|
$recipient = $this->objFromFixture('UserDefinedForm_EmailRecipient', |
465
|
|
|
'invalid-recipient-list'); |
466
|
|
|
$result = $recipient->validate(); |
467
|
|
|
$this->assertFalse($result->valid()); |
|
|
|
|
468
|
|
|
$this->assertContains('filtered.example.com', $result->message()); |
469
|
|
|
$this->assertNotContains('[email protected]', $result->message()); |
470
|
|
|
|
471
|
|
|
// test valid email addresses pass validation |
472
|
|
|
$recipient = $this->objFromFixture('UserDefinedForm_EmailRecipient', |
473
|
|
|
'valid-recipient-list'); |
474
|
|
|
$result = $recipient->validate(); |
475
|
|
|
$this->assertTrue($result->valid()); |
|
|
|
|
476
|
|
|
$this->assertEmpty($result->message()); |
|
|
|
|
477
|
|
|
} |
478
|
|
|
} |
479
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.