-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPageBlockFormBuilderCest.php
More file actions
1325 lines (1165 loc) · 38.7 KB
/
PageBlockFormBuilderCest.php
File metadata and controls
1325 lines (1165 loc) · 38.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
namespace Tests\EndToEnd;
use Tests\Support\EndToEndTester;
/**
* Tests for the Kit Form Builder Gutenberg Block.
*
* @since 3.0.0
*/
class PageBlockFormBuilderCest
{
/**
* Run common actions before running the test functions in this class.
*
* @since 3.0.0
*
* @param EndToEndTester $I Tester.
*/
public function _before(EndToEndTester $I)
{
$I->activateKitPlugin($I);
}
/**
* Test the Form Builder block's conditional fields work.
*
* @since 3.0.6
*
* @param EndToEndTester $I Tester.
*/
public function testFormBuilderBlockConditionalFields(EndToEndTester $I)
{
// Setup Plugin and enable debug log.
$I->setupKitPlugin($I);
$I->setupKitPluginResources($I);
// Add a Page using the Gutenberg editor.
$I->addGutenbergPage(
$I,
title: 'Kit: Page: Form Builder: Conditional Fields'
);
// Add block to Page.
$I->addGutenbergBlock(
$I,
blockName: 'Kit Form Builder',
blockProgrammaticName: 'convertkit-form-builder'
);
// Confirm conditional fields are not displayed.
$I->dontSeeElementInDOM('#convertkit_form_builder_text_if_subscribed');
// Disable 'Display form' and confirm the conditional field displays.
$I->click("//label[normalize-space(text())='Display form']/preceding-sibling::span/input");
$I->waitForElementVisible('#convertkit_form_builder_text_if_subscribed');
// Enable 'Display form' to confirm the conditional field is hidden.
$I->click("//label[normalize-space(text())='Display form']/preceding-sibling::span/input");
$I->waitForElementNotVisible('#convertkit_form_builder_text_if_subscribed');
// Publish Page, so no browser warnings are displayed about unsaved changes.
$I->publishGutenbergPage($I);
}
/**
* Test the Form Builder block works when added with no changes to its configuration.
*
* @since 3.0.0
*
* @param EndToEndTester $I Tester.
*/
public function testFormBuilderBlockWithDefaultConfiguration(EndToEndTester $I)
{
// Setup Plugin and Resources.
$I->setupKitPlugin($I);
$I->setupKitPluginResources($I);
// Add a Page using the Gutenberg editor.
$I->addGutenbergPage(
$I,
title: 'Kit: Page: Form Builder: Block: Default'
);
// Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg.
$I->configurePluginSidebarSettings(
$I,
form: 'None'
);
// Add block to Page.
$I->addGutenbergBlock(
$I,
blockName: 'Kit Form Builder',
blockProgrammaticName: 'convertkit-form-builder'
);
// Confirm the block template was used as the default.
$this->seeFormBuilderBlock($I);
$this->seeFormBuilderButtonBlock($I);
$this->seeFormBuilderField(
$I,
fieldType: 'text',
fieldName: 'first_name',
fieldID: 'first_name',
label: 'First name',
container: 'div[data-type="convertkit/form-builder"]'
);
$this->seeFormBuilderField(
$I,
fieldType: 'email',
fieldName: 'email',
fieldID: 'email',
label: 'Email address',
container: 'div[data-type="convertkit/form-builder"]'
);
// Publish and view the Page on the frontend site.
$I->publishAndViewGutenbergPage($I);
// Confirm that the Form is output in the DOM.
$this->seeFormBuilderField(
$I,
fieldType: 'text',
fieldName: 'first_name',
fieldID: 'first_name',
label: 'First name',
container: 'div.wp-block-convertkit-form-builder',
isFrontend: true
);
$this->seeFormBuilderField(
$I,
fieldType: 'email',
fieldName: 'email',
fieldID: 'email',
label: 'Email address',
container: 'div.wp-block-convertkit-form-builder',
isFrontend: true
);
// Generate email address for this test.
$emailAddress = $I->generateEmailAddress();
// Submit form.
$I->fillField('input[name="convertkit[first_name]"]', 'First');
$I->fillField('input[name="convertkit[email]"]', $emailAddress);
$I->click('div.wp-block-convertkit-form-builder button[type="submit"]');
// Confirm that the message and form is displayed.
$I->waitForElementVisible('.convertkit-form-builder-subscribed-message');
$I->see('Thanks for subscribing!');
$I->seeElementInDOM('input[name="convertkit[first_name]"]');
$I->seeElementInDOM('input[name="convertkit[email]"]');
$I->seeElementInDOM('button[type="submit"]');
// Confirm that the email address was added to Kit.
$I->wait(3);
$I->apiCheckSubscriberExists(
$I,
emailAddress: $emailAddress,
firstName: 'First'
);
}
/**
* Test the Form Builder block works when added with changes made to the:
* - Display form option,
* - Thanks for subscribing text.
*
* @since 3.0.0
*
* @param EndToEndTester $I Tester.
*/
public function testFormBuilderBlockWithTextCustomization(EndToEndTester $I)
{
// Setup Plugin and Resources.
$I->setupKitPlugin($I);
$I->setupKitPluginResources($I);
// Add a Page using the Gutenberg editor.
$I->addGutenbergPage(
$I,
title: 'Kit: Page: Form Builder: Block: Text Customization'
);
// Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg.
$I->configurePluginSidebarSettings(
$I,
form: 'None'
);
// Add block to Page.
$I->addGutenbergBlock(
$I,
blockName: 'Kit Form Builder',
blockProgrammaticName: 'convertkit-form-builder',
blockConfiguration: [
'Display form' => [ 'toggle', false ],
'text_if_subscribed' => [ 'text', 'Welcome to the newsletter!' ],
]
);
// Change the labels of the form fields. These are added as inner blocks when the Form Builder block is added.
$I->selectGutenbergBlockInEditor($I, 'convertkit/form-builder-field-name');
$I->waitForElementVisible('.interface-interface-skeleton__sidebar[aria-label="Editor settings"]');
$I->fillField('#convertkit_form_builder_field_name_label', 'Nafnið þitt');
$I->selectGutenbergBlockInEditor($I, 'convertkit/form-builder-field-email');
$I->waitForElementVisible('.interface-interface-skeleton__sidebar[aria-label="Editor settings"]');
$I->fillField('#convertkit_form_builder_field_email_label', 'Netfangið þitt');
// Wait for the changes to show in the editor.
$I->wait(2);
// Confirm the block template was used as the default.
$this->seeFormBuilderBlock($I);
$this->seeFormBuilderButtonBlock($I);
$this->seeFormBuilderField(
$I,
fieldType: 'text',
fieldName: 'first_name',
fieldID: 'first_name',
label: 'Nafnið þitt',
container: 'div[data-type="convertkit/form-builder"]'
);
$this->seeFormBuilderField(
$I,
fieldType: 'email',
fieldName: 'email',
fieldID: 'email',
label: 'Netfangið þitt',
container: 'div[data-type="convertkit/form-builder"]'
);
// Publish and view the Page on the frontend site.
$I->publishAndViewGutenbergPage($I);
// Confirm that the Form is output in the DOM.
$this->seeFormBuilderField(
$I,
fieldType: 'text',
fieldName: 'first_name',
fieldID: 'first_name',
label: 'Nafnið þitt',
container: 'div.wp-block-convertkit-form-builder',
isFrontend: true
);
$this->seeFormBuilderField(
$I,
fieldType: 'email',
fieldName: 'email',
fieldID: 'email',
label: 'Netfangið þitt',
container: 'div.wp-block-convertkit-form-builder',
isFrontend: true
);
// Generate email address for this test.
$emailAddress = $I->generateEmailAddress();
// Submit form.
$I->fillField('input[name="convertkit[first_name]"]', 'First');
$I->fillField('input[name="convertkit[email]"]', $emailAddress);
$I->click('div.wp-block-convertkit-form-builder button[type="submit"]');
// Check that the form no longer displays and the message displays.
$I->waitForText('Welcome to the newsletter!', 10, '.convertkit-form-builder.wp-block-convertkit-form-builder');
$I->dontSeeElementInDOM('input[name="convertkit[first_name]"]');
$I->dontSeeElementInDOM('input[name="convertkit[email]"]');
// Confirm that the email address was added to Kit.
$I->apiCheckSubscriberExists(
$I,
emailAddress: $emailAddress,
firstName: 'First'
);
}
/**
* Test the Form Builder block works when added and a Form is specified
* to subscribe the subscriber to.
*
* @since 3.0.4
*
* @param EndToEndTester $I Tester.
*/
public function testFormBuilderBlockWithFormEnabled(EndToEndTester $I)
{
// Setup Plugin and Resources.
$I->setupKitPlugin($I);
$I->setupKitPluginResources($I);
// Add a Page using the Gutenberg editor.
$I->addGutenbergPage(
$I,
title: 'Kit: Page: Form Builder: Block: Form Enabled'
);
// Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg.
$I->configurePluginSidebarSettings(
$I,
form: 'None'
);
// Add block to Page.
$I->addGutenbergBlock(
$I,
blockName: 'Kit Form Builder',
blockProgrammaticName: 'convertkit-form-builder',
blockConfiguration: [
'form_id' => [ 'select', $_ENV['CONVERTKIT_API_FORM_NAME'] ],
]
);
// Confirm the block template was used as the default.
$this->seeFormBuilderBlock($I);
$this->seeFormBuilderButtonBlock($I);
$this->seeFormBuilderField(
$I,
fieldType: 'text',
fieldName: 'first_name',
fieldID: 'first_name',
label: 'First name',
container: 'div[data-type="convertkit/form-builder"]'
);
$this->seeFormBuilderField(
$I,
fieldType: 'email',
fieldName: 'email',
fieldID: 'email',
label: 'Email address',
container: 'div[data-type="convertkit/form-builder"]'
);
// Publish and view the Page on the frontend site.
$I->publishAndViewGutenbergPage($I);
// Confirm that the Form is output in the DOM.
$this->seeFormBuilderField(
$I,
fieldType: 'text',
fieldName: 'first_name',
fieldID: 'first_name',
label: 'First name',
container: 'div.wp-block-convertkit-form-builder',
isFrontend: true
);
$this->seeFormBuilderField(
$I,
fieldType: 'email',
fieldName: 'email',
fieldID: 'email',
label: 'Email address',
container: 'div.wp-block-convertkit-form-builder',
isFrontend: true
);
// Generate email address for this test.
$emailAddress = $I->generateEmailAddress();
// Submit form.
$I->fillField('input[name="convertkit[first_name]"]', 'First');
$I->fillField('input[name="convertkit[email]"]', $emailAddress);
$I->click('div.wp-block-convertkit-form-builder button[type="submit"]');
// Confirm that the email address was added to Kit.
$I->waitForElementVisible('.convertkit-form-builder-subscribed-message');
$I->wait(3);
$subscriber = $I->apiCheckSubscriberExists(
$I,
emailAddress: $emailAddress,
firstName: 'First'
);
// Confirm that the subscriber has the form.
$I->apiCheckSubscriberHasForm(
$I,
subscriberID: $subscriber['id'],
formID: $_ENV['CONVERTKIT_API_FORM_ID'],
referrer: $_ENV['WORDPRESS_URL'] . $I->grabFromCurrentUrl()
);
}
/**
* Test the Form Builder block works when added and a Tag is specified
* to subscribe the subscriber to.
*
* @since 3.0.0
*
* @param EndToEndTester $I Tester.
*/
public function testFormBuilderBlockWithTaggingEnabled(EndToEndTester $I)
{
// Setup Plugin and Resources.
$I->setupKitPlugin($I);
$I->setupKitPluginResources($I);
// Add a Page using the Gutenberg editor.
$I->addGutenbergPage(
$I,
title: 'Kit: Page: Form Builder: Block: Tagging Enabled'
);
// Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg.
$I->configurePluginSidebarSettings(
$I,
form: 'None'
);
// Add block to Page.
$I->addGutenbergBlock(
$I,
blockName: 'Kit Form Builder',
blockProgrammaticName: 'convertkit-form-builder',
blockConfiguration: [
'tag_id' => [ 'select', $_ENV['CONVERTKIT_API_TAG_NAME'] ],
]
);
// Confirm the block template was used as the default.
$this->seeFormBuilderBlock($I);
$this->seeFormBuilderButtonBlock($I);
$this->seeFormBuilderField(
$I,
fieldType: 'text',
fieldName: 'first_name',
fieldID: 'first_name',
label: 'First name',
container: 'div[data-type="convertkit/form-builder"]'
);
$this->seeFormBuilderField(
$I,
fieldType: 'email',
fieldName: 'email',
fieldID: 'email',
label: 'Email address',
container: 'div[data-type="convertkit/form-builder"]'
);
// Publish and view the Page on the frontend site.
$I->publishAndViewGutenbergPage($I);
// Confirm that the Form is output in the DOM.
$this->seeFormBuilderField(
$I,
fieldType: 'text',
fieldName: 'first_name',
fieldID: 'first_name',
label: 'First name',
container: 'div.wp-block-convertkit-form-builder',
isFrontend: true
);
$this->seeFormBuilderField(
$I,
fieldType: 'email',
fieldName: 'email',
fieldID: 'email',
label: 'Email address',
container: 'div.wp-block-convertkit-form-builder',
isFrontend: true
);
// Generate email address for this test.
$emailAddress = $I->generateEmailAddress();
// Submit form.
$I->fillField('input[name="convertkit[first_name]"]', 'First');
$I->fillField('input[name="convertkit[email]"]', $emailAddress);
$I->click('div.wp-block-convertkit-form-builder button[type="submit"]');
// Confirm that the email address was added to Kit.
$I->waitForElementVisible('.convertkit-form-builder-subscribed-message');
$I->wait(3);
$subscriber = $I->apiCheckSubscriberExists(
$I,
emailAddress: $emailAddress,
firstName: 'First'
);
// Confirm that the subscriber has the tag.
$I->apiCheckSubscriberHasTag(
$I,
subscriberID: $subscriber['id'],
tagID: $_ENV['CONVERTKIT_API_TAG_ID']
);
}
/**
* Test the Form Builder block works when added and a Sequence is specified
* to subscribe the subscriber to.
*
* @since 3.0.0
*
* @param EndToEndTester $I Tester.
*/
public function testFormBuilderBlockWithSequenceEnabled(EndToEndTester $I)
{
// Setup Plugin and Resources.
$I->setupKitPlugin($I);
$I->setupKitPluginResources($I);
// Add a Page using the Gutenberg editor.
$I->addGutenbergPage(
$I,
title: 'Kit: Page: Form Builder: Block: Sequence Enabled'
);
// Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg.
$I->configurePluginSidebarSettings(
$I,
form: 'None'
);
// Add block to Page.
$I->addGutenbergBlock(
$I,
blockName: 'Kit Form Builder',
blockProgrammaticName: 'convertkit-form-builder',
blockConfiguration: [
'sequence_id' => [ 'select', $_ENV['CONVERTKIT_API_SEQUENCE_NAME'] ],
]
);
// Confirm the block template was used as the default.
$this->seeFormBuilderBlock($I);
$this->seeFormBuilderButtonBlock($I);
$this->seeFormBuilderField(
$I,
fieldType: 'text',
fieldName: 'first_name',
fieldID: 'first_name',
label: 'First name',
container: 'div[data-type="convertkit/form-builder"]'
);
$this->seeFormBuilderField(
$I,
fieldType: 'email',
fieldName: 'email',
fieldID: 'email',
label: 'Email address',
container: 'div[data-type="convertkit/form-builder"]'
);
// Publish and view the Page on the frontend site.
$I->publishAndViewGutenbergPage($I);
// Confirm that the Form is output in the DOM.
$this->seeFormBuilderField(
$I,
fieldType: 'text',
fieldName: 'first_name',
fieldID: 'first_name',
label: 'First name',
container: 'div.wp-block-convertkit-form-builder',
isFrontend: true
);
$this->seeFormBuilderField(
$I,
fieldType: 'email',
fieldName: 'email',
fieldID: 'email',
label: 'Email address',
container: 'div.wp-block-convertkit-form-builder',
isFrontend: true
);
// Generate email address for this test.
$emailAddress = $I->generateEmailAddress();
// Submit form.
$I->fillField('input[name="convertkit[first_name]"]', 'First');
$I->fillField('input[name="convertkit[email]"]', $emailAddress);
$I->click('div.wp-block-convertkit-form-builder button[type="submit"]');
// Confirm that the email address was added to Kit.
$I->waitForElementVisible('.convertkit-form-builder-subscribed-message');
$I->wait(3);
$subscriber = $I->apiCheckSubscriberExists(
$I,
emailAddress: $emailAddress,
firstName: 'First'
);
// Confirm that the subscriber has the sequence.
$I->apiCheckSubscriberHasSequence(
$I,
subscriberID: $subscriber['id'],
sequenceID: $_ENV['CONVERTKIT_API_SEQUENCE_ID']
);
}
/**
* Test the Form Builder block works when custom fields are added.
*
* @since 3.0.0
*
* @param EndToEndTester $I Tester.
*/
public function testFormBuilderBlockWithCustomField(EndToEndTester $I)
{
// Setup Plugin and Resources.
$I->setupKitPlugin($I);
$I->setupKitPluginResources($I);
// Add a Page using the Gutenberg editor.
$I->addGutenbergPage(
$I,
title: 'Kit: Page: Form Builder: Block: Custom Field'
);
// Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg.
$I->configurePluginSidebarSettings(
$I,
form: 'None'
);
// Add block to Page.
$I->addGutenbergBlock(
$I,
blockName: 'Kit Form Builder',
blockProgrammaticName: 'convertkit-form-builder'
);
// Define custom fields to add to the form.
$customFields = [
'last_name' => [
'label' => 'Last Name',
'type' => 'text',
'value' => 'Last',
],
'phone_number' => [
'label' => 'Phone Number',
'type' => 'number',
'value' => '1234567890',
],
'notes' => [
'label' => 'Notes',
'type' => 'textarea',
'value' => 'Notes',
],
'url' => [
'label' => 'URL',
'type' => 'url',
'value' => 'https://kit.com',
],
];
foreach ( $customFields as $field ) {
// Focus on an inner block, so the Form Builder field blocks are available in the inserter.
$I->selectGutenbergBlockInEditor($I, 'convertkit/form-builder-field-name');
// Add custom field block, mapping its data to the Last Name field in Kit.
$I->addGutenbergBlock(
$I,
blockName: 'Kit Form Builder: Custom Field',
blockProgrammaticName: 'convertkit-form-builder-field-custom',
blockConfiguration: [
'label' => [ 'input', $field['label'] ],
'type' => [ 'select', $field['type'] ],
'custom_field' => [ 'select', $field['label'] ],
]
);
}
// Publish and view the Page on the frontend site.
$I->publishAndViewGutenbergPage($I);
// Confirm that the Form is output in the DOM.
$this->seeFormBuilderField(
$I,
fieldType: 'text',
fieldName: 'first_name',
fieldID: 'first_name',
label: 'First name',
container: 'div.wp-block-convertkit-form-builder',
isFrontend: true
);
$this->seeFormBuilderField(
$I,
fieldType: 'email',
fieldName: 'email',
fieldID: 'email',
label: 'Email address',
container: 'div.wp-block-convertkit-form-builder',
isFrontend: true
);
foreach ( $customFields as $key => $field ) {
$this->seeFormBuilderField(
$I,
fieldType: $field['type'],
fieldName: 'custom_fields][' . $key,
fieldID: 'custom_fields_' . $key,
label: $field['label'],
container: 'div.wp-block-convertkit-form-builder',
isFrontend: true
);
}
// Generate email address for this test.
$emailAddress = $I->generateEmailAddress();
// Submit form.
$I->fillField('input[name="convertkit[first_name]"]', 'First');
$I->fillField('input[name="convertkit[email]"]', $emailAddress);
foreach ( $customFields as $key => $field ) {
$I->fillField('[name="convertkit[custom_fields][' . $key . ']"]', $field['value']);
}
$I->click('div.wp-block-convertkit-form-builder button[type="submit"]');
// Confirm that the email address was added to Kit.
$I->waitForElementVisible('.convertkit-form-builder-subscribed-message');
$I->wait(3);
$subscriber = $I->apiCheckSubscriberExists(
$I,
emailAddress: $emailAddress,
firstName: 'First'
);
// Confirm that the custom fields were added to the subscriber.
foreach ( $customFields as $key => $field ) {
$I->assertEquals($field['value'], $subscriber['fields'][ $key ]);
}
}
/**
* Test the Form Builder block works when the redirect URL is set.
*
* @since 3.0.0
*
* @param EndToEndTester $I Tester.
*/
public function testFormBuilderBlockWithRedirectOption(EndToEndTester $I)
{
// Setup Plugin and Resources.
$I->setupKitPlugin($I);
$I->setupKitPluginResources($I);
// Add a Page using the Gutenberg editor.
$I->addGutenbergPage(
$I,
title: 'Kit: Page: Form Builder: Block: Redirect URL'
);
// Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg.
$I->configurePluginSidebarSettings(
$I,
form: 'None'
);
// Add block to Page, setting the Form setting to the value specified in the .env file.
$I->addGutenbergBlock(
$I,
blockName: 'Kit Form Builder',
blockProgrammaticName: 'convertkit-form-builder',
blockConfiguration: [
'redirect' => [ 'text', $_ENV['WORDPRESS_URL'] ],
]
);
// Confirm the block template was used as the default.
$this->seeFormBuilderBlock($I);
$this->seeFormBuilderButtonBlock($I);
$this->seeFormBuilderField(
$I,
fieldType: 'text',
fieldName: 'first_name',
fieldID: 'first_name',
label: 'First name',
container: 'div[data-type="convertkit/form-builder"]'
);
$this->seeFormBuilderField(
$I,
fieldType: 'email',
fieldName: 'email',
fieldID: 'email',
label: 'Email address',
container: 'div[data-type="convertkit/form-builder"]'
);
// Publish and view the Page on the frontend site.
$I->publishAndViewGutenbergPage($I);
// Confirm that the Form is output in the DOM.
$this->seeFormBuilderField(
$I,
fieldType: 'text',
fieldName: 'first_name',
fieldID: 'first_name',
label: 'First name',
container: 'div.wp-block-convertkit-form-builder',
isFrontend: true
);
$this->seeFormBuilderField(
$I,
fieldType: 'email',
fieldName: 'email',
fieldID: 'email',
label: 'Email address',
container: 'div.wp-block-convertkit-form-builder',
isFrontend: true
);
// Generate email address for this test.
$emailAddress = $I->generateEmailAddress();
// Submit form.
$I->fillField('input[name="convertkit[first_name]"]', 'First');
$I->fillField('input[name="convertkit[email]"]', $emailAddress);
$I->click('div.wp-block-convertkit-form-builder button[type="submit"]');
// Check we are on the redirect URL i.e. the home page.
$I->waitForElementVisible('body.home');
// Confirm that the email address was added to Kit.
$I->apiCheckSubscriberExists(
$I,
emailAddress: $emailAddress,
firstName: 'First'
);
}
/**
* Test the Form Builder block supports various styling options
* provided by the block editor.
*
* @since 3.0.0
*
* @param EndToEndTester $I Tester.
*/
public function testFormBuilderSupportsStyles(EndToEndTester $I)
{
// Setup Plugin and enable debug log.
$I->setupKitPlugin($I);
$I->setupKitPluginResources($I);
// Create a Page as if it were create in Gutenberg with the Form Builder block
// and various styling options.
$pageID = $I->havePostInDatabase(
[
'post_type' => 'page',
'post_title' => 'Kit: Page: Form Builder: Block: Styles',
'post_content' => '<!-- wp:convertkit/form-builder {"align":"left","style":{"spacing":{"padding":{"top":"var:preset|spacing|30","bottom":"var:preset|spacing|30","left":"var:preset|spacing|30","right":"var:preset|spacing|30"},"margin":{"top":"var:preset|spacing|30","bottom":"var:preset|spacing|30","left":"var:preset|spacing|30","right":"var:preset|spacing|30"}}},"backgroundColor":"accent-5","fontSize":"small"} -->
<div class="wp-block-convertkit-form-builder alignleft has-accent-5-background-color has-background has-small-font-size" style="padding: var(--wp--preset--spacing--30); margin: var(--wp--preset--spacing--30);"><!-- wp:convertkit/form-builder-field-name {"label":"First name"} /-->
<!-- wp:convertkit/form-builder-field-email {"label":"Email address"} /-->
<!-- wp:button {"lock":{"move":true,"remove":true},"className":"convertkit-form-builder-submit-button"} -->
<div class="wp-block-button convertkit-form-builder-submit-button"><a class="wp-block-button__link wp-element-button">Subscribe</a></div>
<!-- /wp:button --></div>
<!-- /wp:convertkit/form-builder -->',
'meta_input' => [
// Configure Kit Plugin to not display a default Form.
'_wp_convertkit_post_meta' => [
'form' => '0',
'landing_page' => '',
'tag' => '',
],
],
]
);
// Load the Page on the frontend site.
$I->amOnPage('?p=' . $pageID);
// Wait for frontend web site to load.
$I->waitForElementVisible('body.page-template-default');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Confirm that the chosen styles are applied.
$I->seeInSource('<div class="wp-block-convertkit-form-builder alignleft has-accent-5-background-color has-background has-small-font-size" style="padding: var(--wp--preset--spacing--30); margin: var(--wp--preset--spacing--30);">');
}
/**
* Test the Form Builder Fields (Name, Email etc.) can only be inserted to the Kit Form Builder
* block, and not another block in the editor.
*
* @since 3.0.0
*
* @param EndToEndTester $I Tester.
*/
public function testFormBuilderFieldsCanOnlyBeInsertedToFormBuilderBlock(EndToEndTester $I)
{
// Setup Plugin and Resources.
$I->setupKitPlugin($I);
$I->setupKitPluginResources($I);
// Add a Page using the Gutenberg editor.
$I->addGutenbergPage(
$I,
title: 'Kit: Page: Form Builder: Block: Form Fields'
);
// Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg.
$I->configurePluginSidebarSettings(
$I,
form: 'None'
);
// Confirm the Form Field blocks cannot be added, as we are not within the Form Builder block.
$I->dontSeeGutenbergBlockAvailable($I, 'Kit Form Field Name', 'convertkit-form-builder-field-name');
$I->dontSeeGutenbergBlockAvailable($I, 'Kit Form Field Email', 'convertkit-form-builder-field-email');
$I->dontSeeGutenbergBlockAvailable($I, 'Kit Form Field Custom', 'convertkit-form-builder-field-custom');
// Add the Form Builder block.
$I->addGutenbergBlock(
$I,
blockName: 'Kit Form Builder',
blockProgrammaticName: 'convertkit-form-builder'
);
// Click an inner block within the Form Builder block.
$I->selectGutenbergBlockInEditor($I, 'convertkit/form-builder');
$I->waitForElementVisible('.interface-interface-skeleton__sidebar[aria-label="Editor settings"]');
// Confirm the Form Field blocks can be added to the Form Builder block.
$I->seeGutenbergBlockAvailable($I, 'Kit Form Field Name', 'convertkit-form-builder-field-name');
$I->seeGutenbergBlockAvailable($I, 'Kit Form Field Email', 'convertkit-form-builder-field-email');
$I->seeGutenbergBlockAvailable($I, 'Kit Form Field Custom', 'convertkit-form-builder-field-custom');
// Publish and view the Page on the frontend site.
$I->publishAndViewGutenbergPage($I);
}
/**
* Test the Form Builder block supports the core blocks.
* - Paragraph
* - Heading
* - List
* - Image
* - Button
* - Spacer
*
* @since 3.0.0
*
* @param EndToEndTester $I Tester.
*/
public function testFormBuilderSupportsCoreBlocks(EndToEndTester $I)
{
// Setup Plugin and Resources.
$I->setupKitPlugin($I);
$I->setupKitPluginResources($I);
// Add a Page using the Gutenberg editor.
$I->addGutenbergPage(
$I,
title: 'Kit: Page: Form Builder: Block: Core Blocks'
);
// Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg.
$I->configurePluginSidebarSettings(
$I,
form: 'None'
);
// Add the Form Builder block.
$I->addGutenbergBlock(
$I,
blockName: 'Kit Form Builder',
blockProgrammaticName: 'convertkit-form-builder'
);
// Click an inner block within the Form Builder block.
$I->selectGutenbergBlockInEditor($I, 'convertkit/form-builder');
$I->waitForElementVisible('.interface-interface-skeleton__sidebar[aria-label="Editor settings"]');
// Confirm some core blocks can be added to the Form Builder block.
$I->seeGutenbergBlockAvailable($I, 'Paragraph', 'paragraph/paragraph');
$I->seeGutenbergBlockAvailable($I, 'Heading', 'heading/heading');
$I->seeGutenbergBlockAvailable($I, 'List', 'list');
$I->seeGutenbergBlockAvailable($I, 'Image', 'image');
$I->seeGutenbergBlockAvailable($I, 'Spacer', 'spacer');
// Publish and view the Page on the frontend site.
$I->publishAndViewGutenbergPage($I);
}
/**
* Test the Form Builder block works when reCAPTCHA is enabled.
*
* @since 3.0.0
*
* @param EndToEndTester $I Tester.
*/
public function testFormBuilderWithRecaptchaEnabled(EndToEndTester $I)
{
// Setup Plugin and Resources.
$I->setupKitPlugin(
$I,
[
'recaptcha_site_key' => $_ENV['CONVERTKIT_API_RECAPTCHA_SITE_KEY'],
'recaptcha_secret_key' => $_ENV['CONVERTKIT_API_RECAPTCHA_SECRET_KEY'],
'recaptcha_minimum_score' => '0.01', // Set a low score to ensure reCAPTCHA passes the subscriber.
]
);
$I->setupKitPluginResources($I);
// Add a Page using the Gutenberg editor.