-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPluginSettingsGeneralCest.php
More file actions
969 lines (787 loc) · 31.2 KB
/
PluginSettingsGeneralCest.php
File metadata and controls
969 lines (787 loc) · 31.2 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
<?php
namespace Tests\EndToEnd;
use Tests\Support\EndToEndTester;
/**
* Tests for the Settings > Kit > General screens.
*
* @since 1.9.6
*/
class PluginSettingsGeneralCest
{
/**
* Run common actions before running the test functions in this class.
*
* @since 1.9.6
*
* @param EndToEndTester $I Tester.
*/
public function _before(EndToEndTester $I)
{
$I->activateKitPlugin($I);
}
/**
* Test that the Settings > Kit > General screen has expected a11y output, such as label[for], and
* UTM parameters are included in links displayed on the Plugins' Setting screen.
*
* @since 1.9.7.6
*
* @param EndToEndTester $I Tester.
*/
public function testAccessibilityAndUTMParameters(EndToEndTester $I)
{
// Setup Plugin.
$I->setupKitPlugin($I);
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Confirm that settings have label[for] attributes.
$I->seeInSource('<label for="_wp_convertkit_settings_page_form">');
$I->seeInSource('<label for="_wp_convertkit_settings_post_form">');
$I->seeInSource('<label for="debug">');
$I->seeInSource('<label for="no_scripts">');
$I->seeInSource('<label for="no_css">');
$I->seeInSource('<label for="no_add_new_button">');
$I->seeInSource('<label for="usage_tracking">');
// Confirm that the UTM parameters exist for the documentation links.
$I->seeInSource('<a href="https://help.kit.com/en/articles/2502591-how-to-set-up-the-kit-plugin-on-your-wordpress-website?utm_source=wordpress&utm_term=en_US&utm_content=convertkit" class="convertkit-docs" target="_blank">Help</a>');
$I->seeInSource('<a href="https://help.kit.com/en/articles/2502591-how-to-set-up-the-kit-plugin-on-your-wordpress-website?utm_source=wordpress&utm_term=en_US&utm_content=convertkit" target="_blank">plugin documentation</a>');
}
/**
* Test that no PHP errors or notices are displayed on the Plugin's Setting screen
* and a Connect button is displayed when no credentials exist.
*
* @since 1.9.6
*
* @param EndToEndTester $I Tester.
*/
public function testNoCredentials(EndToEndTester $I)
{
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Confirm no option is displayed to save changes, as the Plugin isn't authenticated.
$I->dontSeeElementInDOM('input#submit');
// Confirm the Connect button displays.
$I->see('Connect');
$I->dontSee('Disconnect');
// Check that a link to the OAuth auth screen exists and includes the state parameter.
$I->seeInSource('<a href="https://app.kit.com/oauth/authorize?client_id=' . $_ENV['CONVERTKIT_OAUTH_CLIENT_ID'] . '&response_type=code&redirect_uri=' . urlencode( $_ENV['KIT_OAUTH_REDIRECT_URI'] ) );
$I->seeInSource(
'&state=' . $I->apiEncodeState(
$_ENV['WORDPRESS_URL'] . '/wp-admin/options-general.php?page=_wp_convertkit_settings',
$_ENV['CONVERTKIT_OAUTH_CLIENT_ID']
)
);
// Click the connect button.
$I->click('Connect');
// Confirm the Kit hosted OAuth login screen is displayed.
$I->waitForElementVisible('body.sessions');
$I->seeInSource('oauth/authorize?client_id=' . $_ENV['CONVERTKIT_OAUTH_CLIENT_ID']);
}
/**
* Test that no PHP errors or notices are displayed on the Plugin's Setting screen,
* and a warning is displayed that the supplied credentials are invalid, when
* e.g. the access token has been revoked.
*
* @since 1.9.6
*
* @param EndToEndTester $I Tester.
*/
public function testInvalidCredentials(EndToEndTester $I)
{
// Setup Plugin.
$I->setupKitPlugin(
$I,
[
'access_token' => 'fakeAccessToken',
'refresh_token' => 'fakeRefreshToken',
]
);
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Confirm the Connect button displays.
$I->see('Connect');
$I->dontSee('Disconnect');
$I->dontSeeElementInDOM('input#submit');
// Navigate to the WordPress Admin.
$I->amOnAdminPage('index.php');
// Check that a notice is displayed that the API credentials are invalid.
$I->seeErrorNotice($I, 'Kit: Authorization failed. Please connect your Kit account.');
}
/**
* Test that no PHP errors or notices are displayed on the Plugin's Setting screen,
* when valid credentials exist.
*
* @since 1.9.6
*
* @param EndToEndTester $I Tester.
*/
public function testValidCredentials(EndToEndTester $I)
{
// Setup Plugin.
$I->setupKitPlugin($I);
$I->setupKitPluginResources($I);
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Confirm the Disconnect and Save Changes buttons display.
$I->see('Disconnect');
$I->seeElementInDOM('input#submit');
// Save Changes to confirm credentials are not lost.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Confirm the Disconnect and Save Changes buttons display.
$I->see('Disconnect');
$I->seeElementInDOM('input#submit');
// Navigate to the WordPress Admin.
$I->amOnAdminPage('index.php');
// Check that no notice is displayed that the API credentials are invalid.
$I->dontSeeErrorNotice($I, 'Kit: Authorization failed. Please connect your Kit account.');
}
/**
* Test that the credentials and resources are deleted on disconnect.
*
* @since 3.2.4
*
* @param EndToEndTester $I Tester.
*/
public function testCredentialsAndResourcesAreDeletedOnDisconnect(EndToEndTester $I)
{
// Setup Plugin.
$I->setupKitPlugin($I);
$I->setupKitPluginResources($I);
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Fake the API Key, API Secret, Access and Refresh Tokens; if we revoke the tokens used for tests, future tests will fail.
$I->setupKitPlugin(
$I,
[
'access_token' => 'fakeAccessToken',
'refresh_token' => 'fakeRefreshToken',
'token_expires' => time() + 3600,
'api_key' => 'fakeAPIKey',
'api_secret' => 'fakeAPISecret',
]
);
// Disconnect the Plugin connection to Kit.
$I->click('Disconnect');
// Check credentials are removed from the settings.
$settings = $I->grabOptionFromDatabase('_wp_convertkit_settings');
$I->assertEmpty($settings['access_token']);
$I->assertEmpty($settings['refresh_token']);
$I->assertEmpty($settings['token_expires']);
$I->assertEmpty($settings['api_key']);
$I->assertEmpty($settings['api_secret']);
// Check cached resources are removed from the database on disconnection.
$I->dontSeeOptionInDatabase('convertkit_creator_network_recommendations');
$I->dontSeeOptionInDatabase('convertkit_custom_fields');
$I->dontSeeOptionInDatabase('convertkit_forms');
$I->dontSeeOptionInDatabase('convertkit_landing_pages');
$I->dontSeeOptionInDatabase('convertkit_posts');
$I->dontSeeOptionInDatabase('convertkit_products');
$I->dontSeeOptionInDatabase('convertkit_sequences');
$I->dontSeeOptionInDatabase('convertkit_tags');
// Confirm the Connect button displays.
$I->see('Connect');
$I->dontSee('Disconnect');
$I->dontSeeElementInDOM('input#submit');
}
/**
* Test that an error notice displays when the `error_description` is present in the URL,
* typically when the user denies access via OAuth or exchanging a code for an access token failed.
*
* @since 2.5.0
*
* @param EndToEndTester $I Tester.
*/
public function testErrorNoticeDisplaysOnOAuthFailure($I)
{
// Go to the Plugin's Settings Screen, as if we came back from OAuth where the user did not
// grant access, or exchanging a code for an access token failed.
$I->amOnAdminPage('options-general.php?page=_wp_convertkit_settings&error_description=Client+authentication+failed+due+to+unknown+client%2C+no+client+authentication+included%2C+or+unsupported+authentication+method.');
// Check that a notice is displayed that the API credentials are invalid.
$I->seeErrorNotice($I, 'Client authentication failed due to unknown client, no client authentication included, or unsupported authentication method.');
// Confirm the Connect button displays.
$I->see('Connect');
$I->dontSee('Disconnect');
$I->dontSeeElementInDOM('input#submit');
}
/**
* Test that no PHP errors or notices are displayed on the Plugin's Setting screen,
* when the Default Form for Pages and Posts are changed, and that the preview links
* work when the Default Form is changed.
*
* @since 1.9.6
*
* @param EndToEndTester $I Tester.
*/
public function testChangeDefaultFormSettingAndPreviewFormLinks(EndToEndTester $I)
{
// Create a Page and a Post, so that preview links display.
$I->havePostInDatabase(
[
'post_title' => 'Kit: Preview Form Links: Page',
'post_type' => 'page',
'post_status' => 'publish',
]
);
$I->havePostInDatabase(
[
'post_title' => 'Kit: Preview Form Links: Post',
'post_type' => 'post',
'post_status' => 'publish',
]
);
// Setup Plugin, without defining default Forms.
$I->setupKitPluginNoDefaultForms($I);
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Select Default Form for Pages, and change the Position.
$I->fillSelect2Field(
$I,
container: '#select2-_wp_convertkit_settings_page_form-container',
value: $_ENV['CONVERTKIT_API_FORM_NAME']
);
$I->selectOption('_wp_convertkit_settings[page_form_position]', 'Before Page content');
// Open preview.
$I->click('a#convertkit-preview-form-page');
$I->wait(2); // Required, otherwise switchToNextTab fails.
// Switch to newly opened tab.
$I->switchToNextTab();
// Confirm that the preview is a WordPress Page.
$I->seeElementInDOM('body.page');
// Confirm that one Kit Form is output in the DOM.
// This confirms that there is only one script on the page for this form, which renders the form.
$I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_ID']);
// Close newly opened tab.
$I->closeTab();
// Select Default Form for Posts.
$I->fillSelect2Field(
$I,
container: '#select2-_wp_convertkit_settings_post_form-container',
value: $_ENV['CONVERTKIT_API_FORM_NAME']
);
// Open preview.
$I->click('a#convertkit-preview-form-post');
$I->wait(2); // Required, otherwise switchToNextTab fails.
// Switch to newly opened tab.
$I->switchToNextTab();
// Confirm that the preview is a WordPress Post.
$I->seeElementInDOM('body.single-post');
// Confirm that one Kit Form is output in the DOM.
// This confirms that there is only one script on the page for this form, which renders the form.
$I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_ID']);
// Close newly opened tab.
$I->closeTab();
// Click the Save Changes button.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Check the value of the fields match the inputs provided.
$I->seeInField('_wp_convertkit_settings[page_form]', $_ENV['CONVERTKIT_API_FORM_NAME']);
$I->seeInField('_wp_convertkit_settings[page_form_position]', 'Before Page content');
$I->seeInField('_wp_convertkit_settings[post_form]', $_ENV['CONVERTKIT_API_FORM_NAME']);
$I->seeInField('_wp_convertkit_settings[post_form_position]', 'After Post content');
}
/**
* Test that no PHP errors or notices are displayed on the Plugin's Setting screen,
* when the Default Forms (Site Wide) setting is changed, and that the preview links
* work when one or more Default Forms are chosen.
*
* @since 2.6.9
*
* @param EndToEndTester $I Tester.
*/
public function testChangeDefaultSiteWideFormsSettingAndPreviewFormLinks(EndToEndTester $I)
{
// Setup Plugin, without defining default Forms.
$I->setupKitPluginNoDefaultForms($I);
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Select the Sticky Bar Form for the Site Wide option.
$I->fillSelect2MultipleField(
$I,
container: '#select2-_wp_convertkit_settings_non_inline_form-container',
value: $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_NAME']
);
// Open preview.
$I->click('a#convertkit-preview-non-inline-form');
$I->wait(2); // Required, otherwise switchToNextTab fails.
// Switch to newly opened tab.
$I->switchToNextTab();
// Confirm that the preview is the Home Page.
$I->seeElementInDOM('body.home');
// Confirm that one Kit Form is output in the DOM.
// This confirms that there is only one script on the page for this form, which renders the form.
$I->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'] . '"]', 1);
// Close newly opened tab.
$I->closeTab();
// Select a second Modal Form for the Site Wide option.
$I->fillSelect2MultipleField(
$I,
container: '#select2-_wp_convertkit_settings_non_inline_form-container',
value: $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME']
);
// Open preview.
$I->click('a#convertkit-preview-non-inline-form');
$I->wait(2); // Required, otherwise switchToNextTab fails.
// Switch to newly opened tab.
$I->switchToNextTab();
// Confirm that the preview is the Home Page.
$I->seeElementInDOM('body.home');
// Confirm that two Kit Forms are output in the DOM.
$I->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'] . '"]', 1);
$I->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID'] . '"]', 1);
// Close newly opened tab.
$I->closeTab();
// Click the Save Changes button.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Check the value of the fields match the inputs provided.
$I->seeInFormFields(
'form',
[
'_wp_convertkit_settings[non_inline_form][]' => [
$_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_NAME'],
$_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'],
],
]
);
}
/**
* Test that no PHP errors or notices are displayed on the Plugin's Setting screen,
* when the Default Form Position setting for Pages and Posts are changed.
*
* @since 2.6.2
*
* @param EndToEndTester $I Tester.
*/
public function testChangeDefaultFormPositionAfterElementSetting(EndToEndTester $I)
{
// Setup Plugin, without defining default Forms.
$I->setupKitPluginNoDefaultForms($I);
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Confirm the conditional fields do not display for Pages, as the 'After element' is not selected.
$I->dontSeeElement('_wp_convertkit_settings[page_form_position_element_index]');
$I->dontSeeElement('_wp_convertkit_settings[page_form_position_element]');
// Select Default Form for Pages, and change the Position.
$I->fillSelect2Field(
$I,
container: '#select2-_wp_convertkit_settings_page_form-container',
value: $_ENV['CONVERTKIT_API_FORM_NAME']
);
$I->selectOption('_wp_convertkit_settings[page_form_position]', 'After element');
// Confirm the conditional fields display for Pages, now that 'After element' is selected.
$I->waitForElementVisible('input[name="_wp_convertkit_settings[page_form_position_element_index]"]');
$I->waitForElementVisible('select[name="_wp_convertkit_settings[page_form_position_element]"]');
// Change a setting.
$I->fillField('_wp_convertkit_settings[page_form_position_element_index]', '3');
// Confirm the conditional fields do not display for Posts, as the 'After element' is not selected.
$I->dontSeeElement('input[name="_wp_convertkit_settings[post_form_position_element_index]"]');
$I->dontSeeElement('select[name="_wp_convertkit_settings[post_form_position_element]"]');
// Select Default Form for Posts, and change the Position.
$I->fillSelect2Field(
$I,
container: '#select2-_wp_convertkit_settings_post_form-container',
value: $_ENV['CONVERTKIT_API_FORM_NAME']
);
$I->selectOption('_wp_convertkit_settings[post_form_position]', 'After element');
// Confirm the conditional fields display for Posts, now that 'After element' is selected.
$I->waitForElementVisible('input[name="_wp_convertkit_settings[post_form_position_element_index]"]');
$I->waitForElementVisible('select[name="_wp_convertkit_settings[post_form_position_element]"]');
// Change a setting.
$I->fillField('_wp_convertkit_settings[post_form_position_element_index]', '2');
// Click the Save Changes button.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Check the value of the fields match the inputs provided.
$I->seeInField('_wp_convertkit_settings[page_form_position]', 'After element');
$I->seeInField('_wp_convertkit_settings[page_form_position_element]', 'Paragraphs');
$I->seeInField('_wp_convertkit_settings[page_form_position_element_index]', '3');
$I->seeInField('_wp_convertkit_settings[post_form_position]', 'After element');
$I->seeInField('_wp_convertkit_settings[post_form_position_element]', 'Paragraphs');
$I->seeInField('_wp_convertkit_settings[post_form_position_element_index]', '2');
// Check that the conditional fields display, as 'After element' is selected for Pages and Posts.
$I->seeElement('input[name="_wp_convertkit_settings[page_form_position_element_index]"]');
$I->seeElement('select[name="_wp_convertkit_settings[page_form_position_element]"]');
$I->seeElement('input[name="_wp_convertkit_settings[post_form_position_element_index]"]');
$I->seeElement('select[name="_wp_convertkit_settings[post_form_position_element]"]');
}
/**
* Test that the settings screen does not display preview links
* when no Pages and Posts exist in WordPress.
*
* @since 1.9.8.5
*
* @param EndToEndTester $I Tester.
*/
public function testPreviewFormLinksWhenNoPostsOrPagesExist(EndToEndTester $I)
{
// Setup Plugin.
$I->setupKitPlugin($I);
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Confirm no Page or Post preview links exist, because there are no Pages or Posts in WordPress.
$I->dontSeeElementInDOM('a#convertkit-preview-form-post');
$I->dontSeeElementInDOM('a#convertkit-preview-form-page');
}
/**
* Test that a Default Form setting for a public Custom Post Type exists in the settings screen,
* and no Default Form setting for a private Custom Post Type exists.
*
* @since 1.9.8.5
*
* @param EndToEndTester $I Tester.
*/
public function testPublicPrivateCustomPostTypeSettingsExist(EndToEndTester $I)
{
// Create Custom Post Types using the Custom Post Type UI Plugin.
$I->registerCustomPostTypes($I);
// Setup Plugin, without defining default Forms.
$I->setupKitPluginNoDefaultForms($I);
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Select Default Form for Articles.
$I->fillSelect2Field(
$I,
container: '#select2-_wp_convertkit_settings_article_form-container',
value: $_ENV['CONVERTKIT_API_FORM_NAME']
);
// Confirm no Default Form option is displayed for the Private CPT.
$I->dontSeeElementInDOM('#_wp_convertkit_settings_private_form');
// Click the Save Changes button.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Check the value of the fields match the inputs provided.
$I->seeInField('_wp_convertkit_settings[article_form]', $_ENV['CONVERTKIT_API_FORM_NAME']);
// Unregister CPTs.
$I->unregisterCustomPostTypes($I);
}
/**
* Test that no PHP errors or notices are displayed on the Plugin's Setting screen
* when the Non-inline Form settings are saved and cleared.
*
* @since 3.0.0
*
* @param EndToEndTester $I Tester.
*/
public function testNonInlineFormSettings(EndToEndTester $I)
{
// Setup Plugin.
$I->setupKitPlugin($I);
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Define fields.
$I->fillSelect2MultipleField(
$I,
container: '#select2-_wp_convertkit_settings_non_inline_form-container',
value: $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_NAME']
);
$I->fillSelect2MultipleField(
$I,
container: '#select2-_wp_convertkit_settings_non_inline_form-container',
value: $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME']
);
$I->checkOption('#non_inline_form_honor_none_setting');
$I->checkOption('#non_inline_form_limit_per_session');
// Click the Save Changes button.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->waitForElementVisible('.notice-success');
$I->checkNoWarningsAndNoticesOnScreen($I);
// Check the field settings saved.
$I->seeInFormFields(
'form',
[
'_wp_convertkit_settings[non_inline_form][]' => [
$_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_NAME'],
$_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'],
],
]
);
$I->seeCheckboxIsChecked('#non_inline_form_honor_none_setting');
$I->seeCheckboxIsChecked('#non_inline_form_limit_per_session');
}
/**
* Test that no PHP errors or notices are displayed on the Plugin's Setting screen
* when the reCAPTCHA settings are saved and cleared.
*
* @since 3.0.0
*
* @param EndToEndTester $I Tester.
*/
public function testRecaptchaSettings(EndToEndTester $I)
{
// Setup Plugin.
$I->setupKitPlugin($I);
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Fill in reCAPTCHA settings.
$I->fillField('#recaptcha_site_key', $_ENV['CONVERTKIT_API_RECAPTCHA_SITE_KEY']);
$I->fillField('#recaptcha_secret_key', $_ENV['CONVERTKIT_API_RECAPTCHA_SECRET_KEY']);
$I->fillField('#recaptcha_minimum_score', '0.01');
// Click the Save Changes button.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Check the reCAPTCHA settings were saved.
$I->seeInField('#recaptcha_site_key', $_ENV['CONVERTKIT_API_RECAPTCHA_SITE_KEY']);
$I->seeInField('#recaptcha_secret_key', $_ENV['CONVERTKIT_API_RECAPTCHA_SECRET_KEY']);
$I->seeInField('#recaptcha_minimum_score', '0.01');
// Clear the reCAPTCHA settings.
$I->clearField('#recaptcha_site_key');
$I->clearField('#recaptcha_secret_key');
$I->clearField('#recaptcha_minimum_score');
// Click the Save Changes button.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Check the reCAPTCHA settings were cleared.
$I->dontSeeInField('#recaptcha_site_key', $_ENV['CONVERTKIT_API_RECAPTCHA_SITE_KEY']);
$I->dontSeeInField('#recaptcha_secret_key', $_ENV['CONVERTKIT_API_RECAPTCHA_SECRET_KEY']);
$I->dontSeeInField('#recaptcha_minimum_score', '0.01');
}
/**
* Test that no PHP errors or notices are displayed on the Plugin's Setting screen
* when Debug settings are enabled and disabled.
*
* @since 1.9.6
*
* @param EndToEndTester $I Tester.
*/
public function testEnableAndDisableDebugSettings(EndToEndTester $I)
{
// Setup Plugin.
$I->setupKitPlugin($I);
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Tick field.
$I->checkOption('#debug');
// Click the Save Changes button.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Check the field remains ticked.
$I->seeCheckboxIsChecked('#debug');
// Untick field.
$I->uncheckOption('#debug');
// Click the Save Changes button.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Check the field remains unticked.
$I->dontSeeCheckboxIsChecked('#debug');
}
/**
* Test that no PHP errors or notices are displayed on the Plugin's Setting screen
* when the Disable JavaScript settings are enabled and disabled.
*
* @since 1.9.6
*
* @param EndToEndTester $I Tester.
*/
public function testEnableAndDisableJavaScriptSettings(EndToEndTester $I)
{
// Setup Plugin.
$I->setupKitPlugin($I);
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Tick field.
$I->checkOption('#no_scripts');
// Click the Save Changes button.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Check the field remains ticked.
$I->seeCheckboxIsChecked('#no_scripts');
// Untick field.
$I->uncheckOption('#no_scripts');
// Click the Save Changes button.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Check the field remains unticked.
$I->dontSeeCheckboxIsChecked('#no_scripts');
}
/**
* Test that no PHP errors or notices are displayed on the Plugin's Setting screen
* when the Disable CSS settings is unchecked, and that CSS is output
* on the frontend web site.
*
* @since 1.9.6.9
*
* @param EndToEndTester $I Tester.
*/
public function testEnableAndDisableCSSSetting(EndToEndTester $I)
{
// Setup Plugin.
$I->setupKitPlugin($I);
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Tick field.
$I->checkOption('#no_css');
// Click the Save Changes button.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Check the field remains ticked.
$I->seeCheckboxIsChecked('#no_css');
// Navigate to the home page.
$I->amOnPage('/');
// Confirm no CSS is output by the Plugin.
$I->dontSeeInSource('frontend.css');
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Untick field.
$I->uncheckOption('#no_css');
// Click the Save Changes button.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Check the field remains unticked.
$I->dontSeeCheckboxIsChecked('#no_css');
// Navigate to the home page.
$I->amOnPage('/');
// Confirm CSS is output by the Plugin.
$I->seeInSource('<link rel="stylesheet" id="convertkit-frontend-css" href="' . $_ENV['WORDPRESS_URL'] . '/wp-content/plugins/convertkit/resources/frontend/css/frontend.css');
}
/**
* Test that no PHP errors or notices are displayed on the Plugin's Setting screen
* when the Disable Add New Landing Page / Member Content button settings is unchecked, and that CSS is output
* on the frontend web site.
*
* @since 3.2.0
*
* @param EndToEndTester $I Tester.
*/
public function testEnableAndDisableAddNewLandingPageMemberContentButtonSetting(EndToEndTester $I)
{
// Setup Plugin.
$I->setupKitPlugin($I);
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Tick field.
$I->checkOption('#no_add_new_button');
// Click the Save Changes button.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Check the field remains ticked.
$I->seeCheckboxIsChecked('#no_add_new_button');
// Untick field.
$I->uncheckOption('#no_add_new_button');
// Click the Save Changes button.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Check the field remains unticked.
$I->dontSeeCheckboxIsChecked('#no_add_new_button');
}
/**
* Test that no PHP errors or notices are displayed on the Plugin's Setting screen
* when the Usage Tracking settings is unchecked, and that CSS is output
* on the frontend web site.
*
* @since 3.0.4
*
* @param EndToEndTester $I Tester.
*/
public function testEnableAndDisableUsageTrackingSetting(EndToEndTester $I)
{
// Setup Plugin.
$I->setupKitPlugin($I);
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Tick field.
$I->checkOption('#usage_tracking');
// Click the Save Changes button.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Check the field remains ticked.
$I->seeCheckboxIsChecked('#usage_tracking');
// Untick field.
$I->uncheckOption('#usage_tracking');
// Click the Save Changes button.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Check the field remains unticked.
$I->dontSeeCheckboxIsChecked('#usage_tracking');
}
/**
* Test that no PHP errors or notices are displayed on the Plugin's Setting screen
* when using a Kit account with no resources, and that the applicable Form settings
* fields do not display.
*
* @since 2.6.3
*
* @param EndToEndTester $I Tester.
*/
public function testSettingsScreenWhenNoResources(EndToEndTester $I)
{
// Setup Plugin using account that has no resources or data.
$I->setupKitPluginCredentialsNoData($I);
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Confirm 'No Forms exist in Kit' message displays.
$I->see('No Forms exist in Kit.');
$I->see('Click here to create your first form');
$I->seeInSource('<a href="https://app.kit.com/forms/new/?utm_source=wordpress&utm_term=en_US&utm_content=convertkit" target="_blank">');
// Confirm no Form settings are displayed for Pages or Posts.
$I->dontSeeElementInDOM('#_wp_convertkit_settings_page_form');
$I->dontSeeElementInDOM('#_wp_convertkit_settings_page_form_position');
$I->dontSeeElementInDOM('#_wp_convertkit_settings_page_form_position_element');
$I->dontSeeElementInDOM('#_wp_convertkit_settings_page_form_position_element_index');
$I->dontSeeElementInDOM('#_wp_convertkit_settings_post_form');
$I->dontSeeElementInDOM('#_wp_convertkit_settings_post_form_position');
$I->dontSeeElementInDOM('#_wp_convertkit_settings_post_form_position_element');
$I->dontSeeElementInDOM('#_wp_convertkit_settings_post_form_position_element_index');
// Confirm no Form settings are displayed for non-inline Forms.
$I->dontSeeElementInDOM('#_wp_convertkit_settings_non_inline_form');
// Check Debug, Disable JavaScript and Disable CSS settings.
$I->checkOption('#debug');
$I->checkOption('#no_scripts');
$I->checkOption('#no_css');
$I->checkOption('#usage_tracking');
// Click the Save Changes button.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Check the fields remain ticked.
$I->seeCheckboxIsChecked('#debug');
$I->seeCheckboxIsChecked('#no_scripts');
$I->seeCheckboxIsChecked('#no_css');
$I->seeCheckboxIsChecked('#usage_tracking');
// Untick fields.
$I->uncheckOption('#debug');
$I->uncheckOption('#no_scripts');
$I->uncheckOption('#no_css');
$I->uncheckOption('#usage_tracking');
// Click the Save Changes button.
$I->click('Save Changes');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
// Check the fields remain unticked.
$I->dontSeeCheckboxIsChecked('#debug');
$I->dontSeeCheckboxIsChecked('#no_scripts');
$I->dontSeeCheckboxIsChecked('#no_css');
$I->dontSeeCheckboxIsChecked('#usage_tracking');
}
/**
* Deactivate and reset Plugin(s) after each test, if the test passes.
* We don't use _after, as this would provide a screenshot of the Plugin
* deactivation and not the true test error.
*
* @since 1.9.6.7
*
* @param EndToEndTester $I Tester.
*/
public function _passed(EndToEndTester $I)
{
$I->deactivateKitPlugin($I);
$I->resetKitPlugin($I);
}
}