From 83332e1eb5d9a12c0501486de4a09bf2e3d36466 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 4 Nov 2025 20:01:28 +0800 Subject: [PATCH 1/3] PHPStan compat. --- .../class-convertkit-admin-importer-mc4wp.php | 2 +- .../class-convertkit-admin-importer.php | 46 ++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/admin/importers/class-convertkit-admin-importer-mc4wp.php b/admin/importers/class-convertkit-admin-importer-mc4wp.php index 288e573a6..ff18b17af 100644 --- a/admin/importers/class-convertkit-admin-importer-mc4wp.php +++ b/admin/importers/class-convertkit-admin-importer-mc4wp.php @@ -79,7 +79,7 @@ public function get_forms() { ); if ( ! $posts->post_count ) { - return false; + return array(); } $forms = array(); diff --git a/admin/importers/class-convertkit-admin-importer.php b/admin/importers/class-convertkit-admin-importer.php index 98e889cec..2909fdf1e 100644 --- a/admin/importers/class-convertkit-admin-importer.php +++ b/admin/importers/class-convertkit-admin-importer.php @@ -14,6 +14,50 @@ */ class ConvertKit_Admin_Importer { + /** + * Holds the shortcode name for the third party Form plugin. + * + * @since 3.1.0 + * + * @var string + */ + public $shortcode_name = ''; + + /** + * Holds the ID attribute name for the third party Form plugin. + * + * @since 3.1.0 + * + * @var string + */ + public $shortcode_id_attribute = ''; + + /** + * Returns an array of third party form IDs and titles. + * + * @since 3.1.0 + * + * @return array + */ + public function get_forms() { + + return array(); + + } + + /** + * Returns an array of post IDs that contain the third party form shortcode. + * + * @since 3.1.0 + * + * @return array + */ + public function get_forms_in_posts() { + + return array(); + + } + /** * Returns whether any third party forms exist. * @@ -98,7 +142,7 @@ public function replace_shortcodes_in_content( $content, $third_party_form_id, $ . '[^\]]*?' // Match any characters that are not a closing square bracket, non-greedy. . '\b' . preg_quote( $this->shortcode_id_attribute, '/' ) // Match the id attribute word boundary and escape as needed. . '\s*=\s*' // Match optional whitespace around an equals sign. - . '(?:"' . preg_quote( $third_party_form_id, '/' ) . '"|' . preg_quote( $third_party_form_id, '/' ) . ')' // Match the form ID, quoted or unquoted. + . '(?:"' . preg_quote( (string) $third_party_form_id, '/' ) . '"|' . preg_quote( (string) $third_party_form_id, '/' ) . ')' // Match the form ID, quoted or unquoted. . '[^\]]*?\]/i'; // Match any other characters (non-greedy) up to the closing square bracket, case-insensitive. return preg_replace( From 31342b9295508abe8d7680f5acbfcd8f98747e8e Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Wed, 5 Nov 2025 11:09:34 +0800 Subject: [PATCH 2/3] Started work on tests --- .github/workflows/tests.yml | 2 +- .../PluginSettingsToolsImporterMC4WPCest.php | 198 ++++++++++++++++++ 2 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterMC4WPCest.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 772909364..4e71c3fa8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -30,7 +30,7 @@ jobs: DB_USER: root DB_PASS: root DB_HOST: localhost - 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. + 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. 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 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" CONVERTKIT_API_KEY: ${{ secrets.CONVERTKIT_API_KEY }} # ConvertKit API Key, stored in the repository's Settings > Secrets diff --git a/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterMC4WPCest.php b/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterMC4WPCest.php new file mode 100644 index 000000000..dadb4fd5c --- /dev/null +++ b/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterMC4WPCest.php @@ -0,0 +1,198 @@ + Kit > Tools > Import sections for third party Form plugins, + * such as MC4WP. + * + * @since 3.1.0 + */ +class PluginSettingsToolsImporterMC4WPCest +{ + /** + * Run common actions before running the test functions in this class. + * + * @since 3.1.0 + * + * @param EndToEndTester $I Tester. + */ + public function _before(EndToEndTester $I) + { + // Activate and Setup Kit plugin. + $I->activateKitPlugin($I); + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Activate Mailchimp for WordPress Plugin. + $I->activateThirdPartyPlugin($I, 'mailchimp-for-wp'); + } + + /** + * Test that Mailchimp Forms are replaced with Kit Forms when the Tools > MC4WP: Migrate Configuration is configured. + * + * @since 3.1.0 + * + * @param EndToEndTester $I Tester. + */ + public function testMC4WPImport(EndToEndTester $I) + { + // Create Mailchimp Forms. + $mailchimpFormIDs = $this->_createMailchimpForms($I); + + // Insert Mailchimp Form Shortcodes into Pages. + $pageIDs = $this->_createPagesWithMailchimpFormShortcodes($I, $mailchimpFormIDs); + + // Navigate to the Tools screen. + $I->loadKitSettingsToolsScreen($I); + + // Select the Kit Forms to replace the Mailchimp Forms. + foreach ($mailchimpFormIDs as $mailchimpFormID) { + $I->selectOption('_wp_convertkit_integration_mc4wp_settings[' . $mailchimpFormID . ']', $_ENV['CONVERTKIT_API_FORM_ID']); + } + + // Click the Migrate button. + $I->click('Migrate'); + + // Confirm success message displays. + $I->waitForElementVisible('.notice-success'); + $I->see('MC4WP forms migrated successfully.'); + + // View the Pages, to confirm Kit Forms now display. + foreach ($pageIDs as $pageID) { + $I->amOnPage('?p=' . $pageID); + $I->seeElementInDOM('form[data-sv-form]'); + } + } + + /** + * Test that the MC4WP: Migrate Configuration section is not displayed when no Mailchimp Forms exist. + * + * @since 3.1.0 + * + * @param EndToEndTester $I Tester. + */ + public function testMC4WPImportWhenNoMailchimpForms(EndToEndTester $I) + { + // Navigate to the Tools screen. + $I->loadKitSettingsToolsScreen($I); + + // Confirm no MC4WP: Migrate Configuration section is displayed. + $I->dontSeeElementInDOM('#import-mc4wp'); + } + + /** + * Test that the MC4WP: Migrate Configuration section is not displayed when Mailchimp Forms exist, + * but no Pages, Posts or Custom Posts contain Mailchimp Form Shortcodes. + * + * @since 3.1.0 + * + * @param EndToEndTester $I Tester. + */ + public function testMC4WPImportWhenNoMailchimpShortcodesInContent(EndToEndTester $I) + { + // Create Mailchimp Forms. + $mailchimpFormIDs = $this->_createMailchimpForms($I); + + // Navigate to the Tools screen. + $I->loadKitSettingsToolsScreen($I); + + // Confirm no MC4WP: Migrate Configuration section is displayed, as there are no + // Mailchimp Form Shortcodes in the content. + $I->dontSeeElementInDOM('#import-mc4wp'); + } + + /** + * Test that the MC4WP: Migrate Configuration section is not displayed when no Kit Forms exist. + * + * @since 3.1.0 + * + * @param EndToEndTester $I Tester. + */ + public function testMC4WPImportWhenNoKitForms(EndToEndTester $I) + { + // @TODO. + } + + /** + * Create Mailchimp Forms. + * + * @since 3.1.0 + * + * @param EndToEndTester $I Tester. + * @return array + */ + private function _createMailchimpForms(EndToEndTester $I) + { + return array( + $I->havePostInDatabase( + [ + 'post_type' => 'mc4wp-form', + 'post_status' => 'publish', + 'post_title' => 'Mailchimp Form #1', + 'post_content' => '

', + ] + ), + $I->havePostInDatabase( + [ + 'post_type' => 'mc4wp-form', + 'post_status' => 'publish', + 'post_title' => 'Mailchimp Form #2', + 'post_content' => '

', + ] + ), + ); + } + + /** + * Create Pages with Mailchimp Form Shortcodes. + * + * @since 3.1.0 + * + * @param EndToEndTester $I Tester. + * @param array $mailchimpFormIDs Mailchimp Form IDs. + * @return array + */ + private function _createPagesWithMailchimpFormShortcodes(EndToEndTester $I, $mailchimpFormIDs) + { + $pageIDs = array(); + + foreach ($mailchimpFormIDs as $mailchimpFormID) { + $pageIDs[] = $I->havePostInDatabase( + [ + 'post_type' => 'page', + 'post_status' => 'publish', + 'post_title' => 'Page with Mailchimp Form #' . $mailchimpFormID, + 'post_content' => '[mc4wp_form id="' . $mailchimpFormID . '"]', + 'meta_input' => [ + '_wp_convertkit_post_meta' => [ + 'form' => '0', + 'landing_page' => '', + 'tag' => '', + ], + ], + ] + ); + } + + return $pageIDs; + } + + /** + * 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 3.1.0 + * + * @param EndToEndTester $I Tester. + */ + public function _passed(EndToEndTester $I) + { + $I->deactivateThirdPartyPlugin($I, 'mailchimp-for-wp'); + $I->deactivateKitPlugin($I); + $I->resetKitPlugin($I); + } +} From f522378c8fa57975cb967d2e95155396f5c327fb Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Wed, 5 Nov 2025 16:45:53 +0800 Subject: [PATCH 3/3] Added tests --- .../PluginSettingsToolsImporterMC4WPCest.php | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterMC4WPCest.php b/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterMC4WPCest.php index dadb4fd5c..569fd0049 100644 --- a/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterMC4WPCest.php +++ b/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterMC4WPCest.php @@ -21,12 +21,8 @@ class PluginSettingsToolsImporterMC4WPCest */ public function _before(EndToEndTester $I) { - // Activate and Setup Kit plugin. + // Activate Plugins. $I->activateKitPlugin($I); - $I->setupKitPlugin($I); - $I->setupKitPluginResources($I); - - // Activate Mailchimp for WordPress Plugin. $I->activateThirdPartyPlugin($I, 'mailchimp-for-wp'); } @@ -39,6 +35,10 @@ public function _before(EndToEndTester $I) */ public function testMC4WPImport(EndToEndTester $I) { + // Setup Plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + // Create Mailchimp Forms. $mailchimpFormIDs = $this->_createMailchimpForms($I); @@ -76,6 +76,10 @@ public function testMC4WPImport(EndToEndTester $I) */ public function testMC4WPImportWhenNoMailchimpForms(EndToEndTester $I) { + // Setup Plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + // Navigate to the Tools screen. $I->loadKitSettingsToolsScreen($I); @@ -93,6 +97,10 @@ public function testMC4WPImportWhenNoMailchimpForms(EndToEndTester $I) */ public function testMC4WPImportWhenNoMailchimpShortcodesInContent(EndToEndTester $I) { + // Setup Plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + // Create Mailchimp Forms. $mailchimpFormIDs = $this->_createMailchimpForms($I); @@ -113,7 +121,16 @@ public function testMC4WPImportWhenNoMailchimpShortcodesInContent(EndToEndTester */ public function testMC4WPImportWhenNoKitForms(EndToEndTester $I) { - // @TODO. + // Setup Plugin. + $I->setupKitPluginCredentialsNoData($I); + $I->setupKitPluginResourcesNoData($I); + + // Navigate to the Tools screen. + $I->loadKitSettingsToolsScreen($I); + + // Confirm no MC4WP: Migrate Configuration section is displayed, as there are no + // Mailchimp Form Shortcodes in the content. + $I->dontSeeElementInDOM('#import-mc4wp'); } /**