|
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
|
|
|
$form = $this->objFromFixture('UserDefinedForm', 'filtered-form-page'); |
|
351
|
|
|
|
|
352
|
|
|
// Check unfiltered recipients |
|
353
|
|
|
$result0 = $form |
|
354
|
|
|
->EmailRecipients() |
|
355
|
|
|
->sort('EmailAddress') |
|
356
|
|
|
->column('EmailAddress'); |
|
357
|
|
|
$this->assertEquals( |
|
|
|
|
|
|
358
|
|
|
array( |
|
359
|
|
|
'[email protected]', |
|
360
|
|
|
'[email protected]', |
|
361
|
|
|
'[email protected]' |
|
362
|
|
|
), |
|
363
|
|
|
$result0 |
|
364
|
|
|
); |
|
365
|
|
|
|
|
366
|
|
|
// check filters based on given data |
|
367
|
|
|
$result1 = $form->FilteredEmailRecipients( |
|
368
|
|
|
array( |
|
369
|
|
|
'your-name' => 'Value', |
|
370
|
|
|
'address' => '', |
|
371
|
|
|
'street' => 'Anything', |
|
372
|
|
|
'city' => 'Matches Not Equals', |
|
373
|
|
|
'colours' => array('Red') // matches 2 |
|
374
|
|
|
), null |
|
375
|
|
|
) |
|
376
|
|
|
->sort('EmailAddress') |
|
377
|
|
|
->column('EmailAddress'); |
|
378
|
|
|
$this->assertEquals( |
|
|
|
|
|
|
379
|
|
|
array( |
|
380
|
|
|
'[email protected]', |
|
381
|
|
|
'[email protected]' |
|
382
|
|
|
), |
|
383
|
|
|
$result1 |
|
384
|
|
|
); |
|
385
|
|
|
|
|
386
|
|
|
// Check all positive matches |
|
387
|
|
|
$result2 = $form->FilteredEmailRecipients( |
|
388
|
|
|
array( |
|
389
|
|
|
'your-name' => '', |
|
390
|
|
|
'address' => 'Anything', |
|
391
|
|
|
'street' => 'Matches Equals', |
|
392
|
|
|
'city' => 'Anything', |
|
393
|
|
|
'colours' => array('Red', 'Blue') // matches 2 |
|
394
|
|
|
), null |
|
395
|
|
|
) |
|
396
|
|
|
->sort('EmailAddress') |
|
397
|
|
|
->column('EmailAddress'); |
|
398
|
|
|
$this->assertEquals( |
|
|
|
|
|
|
399
|
|
|
array( |
|
400
|
|
|
'[email protected]', |
|
401
|
|
|
'[email protected]', |
|
402
|
|
|
'[email protected]' |
|
403
|
|
|
), |
|
404
|
|
|
$result2 |
|
405
|
|
|
); |
|
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
|
|
|
|
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.