-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathUpgradePathsCest.php
More file actions
306 lines (269 loc) · 9.29 KB
/
UpgradePathsCest.php
File metadata and controls
306 lines (269 loc) · 9.29 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
<?php
namespace Tests\EndToEnd;
use Tests\Support\EndToEndTester;
/**
* Tests edge cases when upgrading between specific Kit Plugin versions.
*
* @since 1.9.6.4
*/
class UpgradePathsCest
{
/**
* Check for undefined index errors for a Post when upgrading from 1.4.6 or earlier to 1.4.7 or later.
*
* @since 1.9.6.4
*
* @param EndToEndTester $I Tester.
*/
public function testUndefinedIndexForPost(EndToEndTester $I)
{
// Activate and Setup Kit plugin.
$I->activateKitPlugin($I);
$I->setupKitPlugin($I);
$I->setupKitPluginResources($I);
// Create a Post with Post Meta that does not include landing_page and tag keys,
// mirroring how 1.4.6 and earlier of the Plugin worked.
$postID = $I->havePageInDatabase(
[
'post_type' => 'post',
'post_status' => 'publish',
'post_title' => 'Kit: Post: 1.4.6',
'post_name' => 'kit-post-1-4-6',
'meta_input' => [
// 1.4.6 and earlier wouldn't set a landing_page or tag meta keys if no values were specified
// in the Meta Box.
'_wp_convertkit_post_meta' => [
'form' => '0',
],
],
]
);
// Load the Post on the frontend site.
$I->amOnPage('kit-post-1-4-6');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
}
/**
* Check for undefined index errors for a Page when upgrading from 1.4.6 or earlier to 1.4.7 or later.
*
* @since 1.9.6.4
*
* @param EndToEndTester $I Tester.
*/
public function testUndefinedIndexForPage(EndToEndTester $I)
{
// Activate and Setup Kit plugin.
$I->activateKitPlugin($I);
$I->setupKitPlugin($I);
$I->setupKitPluginResources($I);
// Create a Page with Post Meta that does not include landing_page and tag keys,
// mirroring how 1.4.6 and earlier of the Plugin worked.
$postID = $I->havePageInDatabase(
[
'post_type' => 'post',
'post_status' => 'publish',
'post_title' => 'Kit: Page: 1.4.6',
'post_name' => 'kit-page-1-4-6',
'meta_input' => [
// 1.4.6 and earlier wouldn't set a landing_page or tag meta keys if no values were specified
// in the Meta Box.
'_wp_convertkit_post_meta' => [
'form' => '0',
],
],
]
);
// Load the Post on the frontend site.
$I->amOnPage('kit-page-1-4-6');
// Check that no PHP warnings or notices were output.
$I->checkNoWarningsAndNoticesOnScreen($I);
}
/**
* Tests that an Access Token and Refresh Token are obtained using an API Key and Secret
* when upgrading to 2.5.0 or later.
*
* @since 2.5.0
*
* @param EndToEndTester $I Tester.
*/
public function testGetAccessTokenByAPIKeyAndSecret(EndToEndTester $I)
{
// Setup Kit Plugin's settings with an API Key and Secret.
$I->haveOptionInDatabase(
'_wp_convertkit_settings',
[
'api_key' => $_ENV['CONVERTKIT_API_KEY'],
'api_secret' => $_ENV['CONVERTKIT_API_SECRET'],
'debug' => 'on',
'no_scripts' => '',
'no_css' => '',
'post_form' => $_ENV['CONVERTKIT_API_FORM_ID'],
'page_form' => $_ENV['CONVERTKIT_API_FORM_ID'],
'product_form' => $_ENV['CONVERTKIT_API_FORM_ID'],
'non_inline_form' => '',
]
);
// Define an installation version older than 2.5.0.
$I->haveOptionInDatabase('convertkit_version', '2.4.0');
// Activate the Plugin, as if we just upgraded to 2.5.0 or higher.
$I->activateKitPlugin($I, false);
// Confirm the options table now contains an Access Token and Refresh Token.
$settings = $I->grabOptionFromDatabase('_wp_convertkit_settings');
$I->assertArrayHasKey('access_token', $settings);
$I->assertArrayHasKey('refresh_token', $settings);
$I->assertArrayHasKey('token_expires', $settings);
// Confirm the API Key is retained, as it's needed for Legacy Forms.
$I->assertArrayHasKey('api_key', $settings);
$I->assertEquals($settings['api_key'], $_ENV['CONVERTKIT_API_KEY']);
// Go to the Plugin's Settings Screen.
$I->loadKitSettingsGeneralScreen($I);
// Confirm the Plugin authorized by checking for a Disconnect button.
$I->see('Kit WordPress');
$I->see('Disconnect');
}
/**
* Tests that reCAPTCHA settings are migrated from Restrict Content settings to General settings
* when upgrading to 3.0.0 or later.
*
* @since 3.0.0
*
* @param EndToEndTester $I Tester.
*/
public function testMigrateRecaptchaSettings(EndToEndTester $I)
{
// Setup Restrict Content settings with reCAPTCHA settings for < 3.0.0.
$I->setupKitPlugin($I);
$I->haveOptionInDatabase(
'_wp_convertkit_settings_restrict_content',
[
'recaptcha_site_key' => $_ENV['CONVERTKIT_API_RECAPTCHA_SITE_KEY'],
'recaptcha_secret_key' => $_ENV['CONVERTKIT_API_RECAPTCHA_SECRET_KEY'],
'recaptcha_minimum_score' => '0.8',
]
);
// Define an installation version older than 3.0.0.
$I->haveOptionInDatabase('convertkit_version', '2.8.7');
// Activate the Plugin, as if we just upgraded to 3.0.0 or higher.
$I->activateKitPlugin($I, false);
// Confirm the options table now contains reCAPTCHA settings.
$settings = $I->grabOptionFromDatabase('_wp_convertkit_settings');
$I->assertArrayHasKey('recaptcha_site_key', $settings);
$I->assertArrayHasKey('recaptcha_secret_key', $settings);
$I->assertArrayHasKey('recaptcha_minimum_score', $settings);
$I->assertEquals($settings['recaptcha_site_key'], $_ENV['CONVERTKIT_API_RECAPTCHA_SITE_KEY']);
$I->assertEquals($settings['recaptcha_secret_key'], $_ENV['CONVERTKIT_API_RECAPTCHA_SECRET_KEY']);
$I->assertEquals($settings['recaptcha_minimum_score'], '0.8');
// Confirm the Restrict Content settings no longer contains reCAPTCHA settings.
$settings = $I->grabOptionFromDatabase('_wp_convertkit_settings_restrict_content');
$I->assertArrayNotHasKey('recaptcha_site_key', $settings);
$I->assertArrayNotHasKey('recaptcha_secret_key', $settings);
$I->assertArrayNotHasKey('recaptcha_minimum_score', $settings);
}
/**
* Tests that the form entries table is created when upgrading to 3.0.0 or later.
*
* @since 3.0.0
*
* @param EndToEndTester $I Tester.
*/
public function testCreateFormEntriesTable(EndToEndTester $I)
{
// Setup Kit Plugin.
$I->setupKitPlugin($I);
// Define an installation version older than 3.0.0.
$I->haveOptionInDatabase('convertkit_version', '2.8.7');
// Activate the Plugin, as if we just upgraded to 3.0.0 or higher.
$I->activateKitPlugin($I, false);
// Confirm the form entries table is created.
$I->seeTableInDatabase('wp_kit_form_entries');
}
/**
* Tests that the form_id column is added to the form entries table when upgrading to 3.0.4 or later.
*
* @since 3.0.4
*
* @param EndToEndTester $I Tester.
*/
public function testUpdateFormEntriesTableAddsFormIDColumn(EndToEndTester $I)
{
// Create the form entries table as if it were created in 3.0.3 or older,
// without the form_id column.
$I->importSql(
[
"CREATE TABLE IF NOT EXISTS wp_kit_form_entries (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`post_id` int(11) NOT NULL,
`first_name` varchar(191) NOT NULL DEFAULT '',
`email` varchar(191) NOT NULL DEFAULT '',
`custom_fields` text,
`tag_id` int(11) NOT NULL,
`sequence_id` int(11) NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
`api_result` varchar(191) NOT NULL DEFAULT 'success',
`api_error` text,
PRIMARY KEY (`id`),
KEY `post_id` (`post_id`),
KEY `first_name` (`first_name`),
KEY `email` (`email`),
KEY `tag_id` (`tag_id`),
KEY `sequence_id` (`sequence_id`),
KEY `api_result` (`api_result`)
) AUTO_INCREMENT=1",
]
);
// Confirm the form entries table is created.
$I->seeTableInDatabase('wp_kit_form_entries');
// Setup Kit Plugin.
$I->setupKitPlugin($I);
// Define an installation version older than 3.0.3.
$I->haveOptionInDatabase('convertkit_version', '3.0.0');
// Activate the Plugin.
$I->activateKitPlugin($I, false);
// Confirm the form entries table now has the form_id column.
$I->seeColumnInDatabase('wp_kit_form_entries', 'form_id');
}
/**
* Tests that the v3 API Secret is removed from settings when upgrading to 3.2.4 or later.
*
* @since 3.2.4
*
* @param EndToEndTester $I Tester.
*/
public function testV3APISecretRemovedFromSettings(EndToEndTester $I)
{
// Setup Plugin with v3 API Key and Secret.
$I->setupKitPlugin(
$I,
[
'api_key' => $_ENV['CONVERTKIT_API_KEY'],
'api_secret' => $_ENV['CONVERTKIT_API_SECRET'],
'post_form' => '',
'page_form' => '',
'product_form' => '',
]
);
// Define an installation version older than 3.2.4.
$I->haveOptionInDatabase('convertkit_version', '3.2.0');
// Activate the Plugin.
$I->activateKitPlugin($I, false);
// Confirm the settings no longer have a value for the v3 API Secret.
$settings = $I->grabOptionFromDatabase('_wp_convertkit_settings');
$I->assertEquals($settings['api_key'], $_ENV['CONVERTKIT_API_KEY']);
$I->assertEquals($settings['api_secret'], '');
}
/**
* 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);
}
}