Skip to content

Commit acc71c3

Browse files
authored
Merge pull request #950 from Kit/migrate-mc4wp-tests
Importer: Mailchimp (MC4WP): Tests
2 parents d327b6d + f522378 commit acc71c3

File tree

2 files changed

+216
-1
lines changed

2 files changed

+216
-1
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
DB_USER: root
3131
DB_PASS: root
3232
DB_HOST: localhost
33-
INSTALL_PLUGINS: "admin-menu-editor autoptimize beaver-builder-lite-version block-visibility contact-form-7 classic-editor custom-post-type-ui debloat elementor forminator jetpack-boost woocommerce wordpress-seo wpforms-lite litespeed-cache wp-crontrol wp-super-cache w3-total-cache wp-fastest-cache wp-optimize sg-cachepress" # Don't include this repository's Plugin here.
33+
INSTALL_PLUGINS: "admin-menu-editor autoptimize beaver-builder-lite-version block-visibility contact-form-7 classic-editor custom-post-type-ui debloat elementor forminator jetpack-boost mailchimp-for-wp woocommerce wordpress-seo wpforms-lite litespeed-cache wp-crontrol wp-super-cache w3-total-cache wp-fastest-cache wp-optimize sg-cachepress" # Don't include this repository's Plugin here.
3434
INSTALL_PLUGINS_URLS: "https://downloads.wordpress.org/plugin/convertkit-for-woocommerce.1.6.4.zip http://cktestplugins.wpengine.com/wp-content/uploads/2024/01/convertkit-action-filter-tests.zip http://cktestplugins.wpengine.com/wp-content/uploads/2024/11/disable-doing-it-wrong-notices.zip http://cktestplugins.wpengine.com/wp-content/uploads/2025/03/uncode-js_composer.7.8.zip http://cktestplugins.wpengine.com/wp-content/uploads/2025/03/uncode-core.zip" # URLs to specific third party Plugins
3535
INSTALL_THEMES_URLS: "http://cktestplugins.wpengine.com/wp-content/uploads/2025/03/uncode.zip http://cktestplugins.wpengine.com/wp-content/uploads/2025/04/Divi.zip"
3636
CONVERTKIT_API_KEY: ${{ secrets.CONVERTKIT_API_KEY }} # ConvertKit API Key, stored in the repository's Settings > Secrets
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
<?php
2+
3+
namespace Tests\EndToEnd;
4+
5+
use Tests\Support\EndToEndTester;
6+
7+
/**
8+
* Tests for the Settings > Kit > Tools > Import sections for third party Form plugins,
9+
* such as MC4WP.
10+
*
11+
* @since 3.1.0
12+
*/
13+
class PluginSettingsToolsImporterMC4WPCest
14+
{
15+
/**
16+
* Run common actions before running the test functions in this class.
17+
*
18+
* @since 3.1.0
19+
*
20+
* @param EndToEndTester $I Tester.
21+
*/
22+
public function _before(EndToEndTester $I)
23+
{
24+
// Activate Plugins.
25+
$I->activateKitPlugin($I);
26+
$I->activateThirdPartyPlugin($I, 'mailchimp-for-wp');
27+
}
28+
29+
/**
30+
* Test that Mailchimp Forms are replaced with Kit Forms when the Tools > MC4WP: Migrate Configuration is configured.
31+
*
32+
* @since 3.1.0
33+
*
34+
* @param EndToEndTester $I Tester.
35+
*/
36+
public function testMC4WPImport(EndToEndTester $I)
37+
{
38+
// Setup Plugin.
39+
$I->setupKitPlugin($I);
40+
$I->setupKitPluginResources($I);
41+
42+
// Create Mailchimp Forms.
43+
$mailchimpFormIDs = $this->_createMailchimpForms($I);
44+
45+
// Insert Mailchimp Form Shortcodes into Pages.
46+
$pageIDs = $this->_createPagesWithMailchimpFormShortcodes($I, $mailchimpFormIDs);
47+
48+
// Navigate to the Tools screen.
49+
$I->loadKitSettingsToolsScreen($I);
50+
51+
// Select the Kit Forms to replace the Mailchimp Forms.
52+
foreach ($mailchimpFormIDs as $mailchimpFormID) {
53+
$I->selectOption('_wp_convertkit_integration_mc4wp_settings[' . $mailchimpFormID . ']', $_ENV['CONVERTKIT_API_FORM_ID']);
54+
}
55+
56+
// Click the Migrate button.
57+
$I->click('Migrate');
58+
59+
// Confirm success message displays.
60+
$I->waitForElementVisible('.notice-success');
61+
$I->see('MC4WP forms migrated successfully.');
62+
63+
// View the Pages, to confirm Kit Forms now display.
64+
foreach ($pageIDs as $pageID) {
65+
$I->amOnPage('?p=' . $pageID);
66+
$I->seeElementInDOM('form[data-sv-form]');
67+
}
68+
}
69+
70+
/**
71+
* Test that the MC4WP: Migrate Configuration section is not displayed when no Mailchimp Forms exist.
72+
*
73+
* @since 3.1.0
74+
*
75+
* @param EndToEndTester $I Tester.
76+
*/
77+
public function testMC4WPImportWhenNoMailchimpForms(EndToEndTester $I)
78+
{
79+
// Setup Plugin.
80+
$I->setupKitPlugin($I);
81+
$I->setupKitPluginResources($I);
82+
83+
// Navigate to the Tools screen.
84+
$I->loadKitSettingsToolsScreen($I);
85+
86+
// Confirm no MC4WP: Migrate Configuration section is displayed.
87+
$I->dontSeeElementInDOM('#import-mc4wp');
88+
}
89+
90+
/**
91+
* Test that the MC4WP: Migrate Configuration section is not displayed when Mailchimp Forms exist,
92+
* but no Pages, Posts or Custom Posts contain Mailchimp Form Shortcodes.
93+
*
94+
* @since 3.1.0
95+
*
96+
* @param EndToEndTester $I Tester.
97+
*/
98+
public function testMC4WPImportWhenNoMailchimpShortcodesInContent(EndToEndTester $I)
99+
{
100+
// Setup Plugin.
101+
$I->setupKitPlugin($I);
102+
$I->setupKitPluginResources($I);
103+
104+
// Create Mailchimp Forms.
105+
$mailchimpFormIDs = $this->_createMailchimpForms($I);
106+
107+
// Navigate to the Tools screen.
108+
$I->loadKitSettingsToolsScreen($I);
109+
110+
// Confirm no MC4WP: Migrate Configuration section is displayed, as there are no
111+
// Mailchimp Form Shortcodes in the content.
112+
$I->dontSeeElementInDOM('#import-mc4wp');
113+
}
114+
115+
/**
116+
* Test that the MC4WP: Migrate Configuration section is not displayed when no Kit Forms exist.
117+
*
118+
* @since 3.1.0
119+
*
120+
* @param EndToEndTester $I Tester.
121+
*/
122+
public function testMC4WPImportWhenNoKitForms(EndToEndTester $I)
123+
{
124+
// Setup Plugin.
125+
$I->setupKitPluginCredentialsNoData($I);
126+
$I->setupKitPluginResourcesNoData($I);
127+
128+
// Navigate to the Tools screen.
129+
$I->loadKitSettingsToolsScreen($I);
130+
131+
// Confirm no MC4WP: Migrate Configuration section is displayed, as there are no
132+
// Mailchimp Form Shortcodes in the content.
133+
$I->dontSeeElementInDOM('#import-mc4wp');
134+
}
135+
136+
/**
137+
* Create Mailchimp Forms.
138+
*
139+
* @since 3.1.0
140+
*
141+
* @param EndToEndTester $I Tester.
142+
* @return array
143+
*/
144+
private function _createMailchimpForms(EndToEndTester $I)
145+
{
146+
return array(
147+
$I->havePostInDatabase(
148+
[
149+
'post_type' => 'mc4wp-form',
150+
'post_status' => 'publish',
151+
'post_title' => 'Mailchimp Form #1',
152+
'post_content' => '<p><label>Email address:<input type="email" name="EMAIL" placeholder="Your email address" required /></label></p><p><input type="submit" value="Sign up" /></p>',
153+
]
154+
),
155+
$I->havePostInDatabase(
156+
[
157+
'post_type' => 'mc4wp-form',
158+
'post_status' => 'publish',
159+
'post_title' => 'Mailchimp Form #2',
160+
'post_content' => '<p><label>Email address:<input type="email" name="EMAIL" placeholder="Your email address" required /></label></p><p><input type="submit" value="Sign up" /></p>',
161+
]
162+
),
163+
);
164+
}
165+
166+
/**
167+
* Create Pages with Mailchimp Form Shortcodes.
168+
*
169+
* @since 3.1.0
170+
*
171+
* @param EndToEndTester $I Tester.
172+
* @param array $mailchimpFormIDs Mailchimp Form IDs.
173+
* @return array
174+
*/
175+
private function _createPagesWithMailchimpFormShortcodes(EndToEndTester $I, $mailchimpFormIDs)
176+
{
177+
$pageIDs = array();
178+
179+
foreach ($mailchimpFormIDs as $mailchimpFormID) {
180+
$pageIDs[] = $I->havePostInDatabase(
181+
[
182+
'post_type' => 'page',
183+
'post_status' => 'publish',
184+
'post_title' => 'Page with Mailchimp Form #' . $mailchimpFormID,
185+
'post_content' => '[mc4wp_form id="' . $mailchimpFormID . '"]',
186+
'meta_input' => [
187+
'_wp_convertkit_post_meta' => [
188+
'form' => '0',
189+
'landing_page' => '',
190+
'tag' => '',
191+
],
192+
],
193+
]
194+
);
195+
}
196+
197+
return $pageIDs;
198+
}
199+
200+
/**
201+
* Deactivate and reset Plugin(s) after each test, if the test passes.
202+
* We don't use _after, as this would provide a screenshot of the Plugin
203+
* deactivation and not the true test error.
204+
*
205+
* @since 3.1.0
206+
*
207+
* @param EndToEndTester $I Tester.
208+
*/
209+
public function _passed(EndToEndTester $I)
210+
{
211+
$I->deactivateThirdPartyPlugin($I, 'mailchimp-for-wp');
212+
$I->deactivateKitPlugin($I);
213+
$I->resetKitPlugin($I);
214+
}
215+
}

0 commit comments

Comments
 (0)