From b197209b65e782f9cb86b095133015d9ccc68546 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 13 Jan 2026 17:14:34 +0800 Subject: [PATCH 1/6] Integration Tests --- tests/Integration/ImporterTest.php | 80 ++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/tests/Integration/ImporterTest.php b/tests/Integration/ImporterTest.php index 25a3f6dc8..a851b1e37 100644 --- a/tests/Integration/ImporterTest.php +++ b/tests/Integration/ImporterTest.php @@ -47,6 +47,86 @@ public function tearDown(): void parent::tearDown(); } + /** + * Test that the replace_shortcodes_in_content() method replaces the third party form shortcode with the Kit form shortcode. + * + * @since 3.1.5 + */ + public function testAWeberReplaceShortcodesInContent() + { + // Initialize the class we want to test. + $this->importer = new \ConvertKit_Admin_Importer_AWeber(); + + // Confirm initialization didn't result in an error. + $this->assertNotInstanceOf(\WP_Error::class, $this->importer); + + // Define the shortcodes to test. + $shortcodes = [ + '[aweber formid=10]', + '[aweber formid="10"]', + '[aweber formid=10 listid=11]', + '[aweber formid="10" listid="11"]', + '[aweber formid=10 listid=11 formtype=webform]', + '[aweber formid="10" listid="11" formtype="webform"]', + '[aweber listid=11 formid=10]', + '[aweber listid="11" formid="10"]', + '[aweber listid=11 formid=10 formtype=webform]', + '[aweber listid="11" formid="10" formtype="webform"]', + '[aweber formtype=webform listid=11 formid=10]', + '[aweber formtype="webform" listid="11" formid="10"]', + ]; + + // Test each shortcode is replaced with the Kit form shortcode. + foreach ( $shortcodes as $shortcode ) { + $this->assertEquals( + '[convertkit_form id="' . $_ENV['CONVERTKIT_API_FORM_ID'] . '"]', + $this->importer->replace_shortcodes_in_content( $shortcode, 10, $_ENV['CONVERTKIT_API_FORM_ID'] ) + ); + + // Prepend and append some content. + $content = 'Some content before the shortcode: ' . $shortcode . ' Some content after the shortcode.'; + $this->assertEquals( + 'Some content before the shortcode: [convertkit_form id="' . $_ENV['CONVERTKIT_API_FORM_ID'] . '"] Some content after the shortcode.', + $this->importer->replace_shortcodes_in_content( $content, 10, $_ENV['CONVERTKIT_API_FORM_ID'] ) + ); + + // Prepend and append some content and duplicate the shortcode. + $content = 'Some content before the shortcode: ' . $shortcode . ' Some content after the shortcode: ' . $shortcode; + $this->assertEquals( + 'Some content before the shortcode: [convertkit_form id="' . $_ENV['CONVERTKIT_API_FORM_ID'] . '"] Some content after the shortcode: [convertkit_form id="' . $_ENV['CONVERTKIT_API_FORM_ID'] . '"]', + $this->importer->replace_shortcodes_in_content( $content, 10, $_ENV['CONVERTKIT_API_FORM_ID'] ) + ); + } + } + + /** + * Test that the replace_shortcodes_in_content() method ignores non-AWeber shortcodes. + * + * @since 3.1.5 + */ + public function testAWeberReplaceShortcodesInContentIgnoringOtherShortcodes() + { + // Initialize the class we want to test. + $this->importer = new \ConvertKit_Admin_Importer_AWeber(); + + // Confirm initialization didn't result in an error. + $this->assertNotInstanceOf(\WP_Error::class, $this->importer); + + // Define the shortcodes to test. + $shortcodes = [ + '[convertkit_form id="' . $_ENV['CONVERTKIT_API_FORM_ID'] . '"]', + '[a_random_shortcode]', + ]; + + // Test each shortcode is ignored. + foreach ( $shortcodes as $shortcode ) { + $this->assertEquals( + $shortcode, + $this->importer->replace_shortcodes_in_content( $shortcode, 10, $_ENV['CONVERTKIT_API_FORM_ID'] ) + ); + } + } + /** * Test that the replace_shortcodes_in_content() method replaces the third party form shortcode with the Kit form shortcode. * From b429e8a3d9cd032f24c360f701847476eac081a4 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 13 Jan 2026 17:22:51 +0800 Subject: [PATCH 2/6] Tests: Import: AWeber --- .github/workflows/tests.yml | 2 +- .../PluginSettingsToolsImporterAweberCest.php | 197 ++++++++++++++++++ 2 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterAweberCest.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c59a882fb..ea7d1b70e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -31,7 +31,7 @@ jobs: DB_PASS: root DB_HOST: localhost WORDPRESS_DB_SQL_DUMP_FILE: tests/Support/Data/dump.sql # Used to populate the test site database for WordPress 6.2.8 - 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 rocket-lazy-load 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 aweber-web-form-widget beaver-builder-lite-version block-visibility contact-form-7 classic-editor custom-post-type-ui debloat elementor forminator jetpack-boost mailchimp-for-wp rocket-lazy-load 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 http://cktestplugins.wpengine.com/wp-content/uploads/2026/01/impeka.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/PluginSettingsToolsImporterAweberCest.php b/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterAweberCest.php new file mode 100644 index 000000000..f8f220d82 --- /dev/null +++ b/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterAweberCest.php @@ -0,0 +1,197 @@ + Kit > Tools > Import sections for AWeber. + * + * @since 3.1.5 + */ +class PluginSettingsToolsImporterAweberCest +{ + /** + * Run common actions before running the test functions in this class. + * + * @since 3.1.5 + * + * @param EndToEndTester $I Tester. + */ + public function _before(EndToEndTester $I) + { + // Activate Plugins. + $I->activateKitPlugin($I); + $I->activateThirdPartyPlugin($I, 'aweber-web-form-widget'); + } + + /** + * Test that AWeber Forms are replaced with Kit Forms when the Tools > AWeber: Migrate Configuration is configured. + * + * @since 3.1.5 + * + * @param EndToEndTester $I Tester. + */ + public function testAWeberImport(EndToEndTester $I) + { + // Setup Plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Create Aweber Forms. + $aweberFormIDs = $this->_createAWeberForms($I); + + // Insert AWeber Form Shortcodes into Pages. + $pageIDs = $this->_createPagesWithAWeberFormShortcodes($I, $aweberFormIDs); + + // Navigate to the Tools screen. + $I->loadKitSettingsToolsScreen($I); + + // Select the Kit Forms to replace the AWeber Forms. + foreach ($aweberFormIDs as $aweberFormID) { + $I->selectOption('_wp_convertkit_integration_aweber_settings[' . $aweberFormID . ']', $_ENV['CONVERTKIT_API_FORM_ID']); + } + + // Click the Migrate button. + $I->click('Migrate'); + + // Confirm success message displays. + $I->waitForElementVisible('.notice-success'); + $I->see('AWeber 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 AWeber: Migrate Configuration section is not displayed when no AWeber Forms exist. + * + * @since 3.1.5 + * + * @param EndToEndTester $I Tester. + */ + public function testAWeberImportWhenNoAWeberForms(EndToEndTester $I) + { + // Setup Plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Navigate to the Tools screen. + $I->loadKitSettingsToolsScreen($I); + + // Confirm no AWeber: Migrate Configuration section is displayed. + $I->dontSeeElementInDOM('#import-aweber'); + } + + /** + * Test that the AWeber: Migrate Configuration section is not displayed when AWeber Forms exist, + * but no Pages, Posts or Custom Posts contain AWeber Form Shortcodes. + * + * @since 3.1.5 + * + * @param EndToEndTester $I Tester. + */ + public function testAWeberImportWhenNoAWeberShortcodesInContent(EndToEndTester $I) + { + // Setup Plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Create AWeber Forms. + $aweberFormIDs = $this->_createAWeberForms($I); + + // Navigate to the Tools screen. + $I->loadKitSettingsToolsScreen($I); + + // Confirm no AWeber: Migrate Configuration section is displayed, as there are no + // AWeber Form Shortcodes in the content. + $I->dontSeeElementInDOM('#import-aweber'); + } + + /** + * Test that the AWeber: Migrate Configuration section is not displayed when no Kit Forms exist. + * + * @since 3.1.5 + * + * @param EndToEndTester $I Tester. + */ + public function testAWeberImportWhenNoKitForms(EndToEndTester $I) + { + // Setup Plugin. + $I->setupKitPluginCredentialsNoData($I); + $I->setupKitPluginResourcesNoData($I); + + // Navigate to the Tools screen. + $I->loadKitSettingsToolsScreen($I); + + // Confirm no AWeber: Migrate Configuration section is displayed, as there are no + // AWeber Form Shortcodes in the content. + $I->dontSeeElementInDOM('#import-aweber'); + } + + /** + * Create AWeber Forms. + * + * @since 3.1.5 + * + * @param EndToEndTester $I Tester. + * @return array + */ + private function _createAWeberForms(EndToEndTester $I) + { + // @TODO. + } + + /** + * Create Pages with AWeber Form Shortcodes. + * + * @since 3.1.5 + * + * @param EndToEndTester $I Tester. + * @param array $aweberFormIDs AWeber Form IDs. + * @return array + */ + private function _createPagesWithAWeberFormShortcodes(EndToEndTester $I, $aweberFormIDs) + { + $pageIDs = array(); + + foreach ($aweberFormIDs as $aweberFormID) { + $pageIDs[] = $I->havePostInDatabase( + [ + 'post_type' => 'page', + 'post_status' => 'publish', + 'post_title' => 'Page with AWeber Form #' . $aweberFormID, + 'post_content' => '[aweber formid="' . $aweberFormID . '"]', + '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.5 + * + * @param EndToEndTester $I Tester. + */ + public function _passed(EndToEndTester $I) + { + $I->deactivateThirdPartyPlugin($I, 'aweber-web-form-widget'); + $I->deactivateKitPlugin($I); + $I->resetKitPlugin($I); + } +} From 2063985111147d0e10a8ea51332c3c68ae33f3e0 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 13 Jan 2026 18:14:42 +0800 Subject: [PATCH 3/6] Added Tests --- .github/workflows/tests.yml | 2 +- tests/EndToEnd.suite.yml | 1 - .../PluginSettingsToolsImporterAweberCest.php | 5 +- tests/Integration/ImporterTest.php | 50 +++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ea7d1b70e..c59a882fb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -31,7 +31,7 @@ jobs: DB_PASS: root DB_HOST: localhost WORDPRESS_DB_SQL_DUMP_FILE: tests/Support/Data/dump.sql # Used to populate the test site database for WordPress 6.2.8 - INSTALL_PLUGINS: "admin-menu-editor autoptimize aweber-web-form-widget beaver-builder-lite-version block-visibility contact-form-7 classic-editor custom-post-type-ui debloat elementor forminator jetpack-boost mailchimp-for-wp rocket-lazy-load 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 rocket-lazy-load 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 http://cktestplugins.wpengine.com/wp-content/uploads/2026/01/impeka.zip" CONVERTKIT_API_KEY: ${{ secrets.CONVERTKIT_API_KEY }} # ConvertKit API Key, stored in the repository's Settings > Secrets diff --git a/tests/EndToEnd.suite.yml b/tests/EndToEnd.suite.yml index 7cf15b9ed..d8ef7596f 100644 --- a/tests/EndToEnd.suite.yml +++ b/tests/EndToEnd.suite.yml @@ -55,7 +55,6 @@ modules: capabilities: "goog:chromeOptions": args: - - "--headless" - "--disable-gpu" - "--disable-dev-shm-usage" - "--disable-software-rasterizer" diff --git a/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterAweberCest.php b/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterAweberCest.php index f8f220d82..575e3bf93 100644 --- a/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterAweberCest.php +++ b/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterAweberCest.php @@ -142,7 +142,10 @@ public function testAWeberImportWhenNoKitForms(EndToEndTester $I) */ private function _createAWeberForms(EndToEndTester $I) { - // @TODO. + // AWeber doesn't cache Forms or store them in the database, so we mock the data that would be returned from their API. + return [ + '10', '11' + ]; } /** diff --git a/tests/Integration/ImporterTest.php b/tests/Integration/ImporterTest.php index a851b1e37..bb8abc890 100644 --- a/tests/Integration/ImporterTest.php +++ b/tests/Integration/ImporterTest.php @@ -47,6 +47,31 @@ public function tearDown(): void parent::tearDown(); } + /** + * Test that the get_form_ids_from_content() method returns third party form shortcode Form IDs. + * + * @since 3.1.5 + */ + public function testGetAWeberFormIDsFromContent() + { + // Initialize the class we want to test. + $this->importer = new \ConvertKit_Admin_Importer_AWeber(); + + // Confirm initialization didn't result in an error. + $this->assertNotInstanceOf(\WP_Error::class, $this->importer); + + // Define the content to test. + $content = '[aweber formid="10"] some content [aweber formid="11"] some other content'; + + // Extract form IDs from content. + $form_ids = $this->importer->get_form_ids_from_content( $content ); + + // Assert the correct number of form IDs are returned. + $this->assertEquals( 2, count( $form_ids ) ); + $this->assertEquals( 10, $form_ids[0] ); + $this->assertEquals( 11, $form_ids[1] ); + } + /** * Test that the replace_shortcodes_in_content() method replaces the third party form shortcode with the Kit form shortcode. * @@ -127,6 +152,31 @@ public function testAWeberReplaceShortcodesInContentIgnoringOtherShortcodes() } } + /** + * Test that the get_form_ids_from_content() method returns third party form shortcode Form IDs. + * + * @since 3.1.5 + */ + public function testGetMC4WPFormIDsFromContent() + { + // Initialize the class we want to test. + $this->importer = new \ConvertKit_Admin_Importer_MC4WP(); + + // Confirm initialization didn't result in an error. + $this->assertNotInstanceOf(\WP_Error::class, $this->importer); + + // Define the content to test. + $content = '[mc4wp_form id="10"] some content [mc4wp_form id="11"] some other content'; + + // Extract form IDs from content. + $form_ids = $this->importer->get_form_ids_from_content( $content ); + + // Assert the correct number of form IDs are returned. + $this->assertEquals( 2, count( $form_ids ) ); + $this->assertEquals( 10, $form_ids[0] ); + $this->assertEquals( 11, $form_ids[1] ); + } + /** * Test that the replace_shortcodes_in_content() method replaces the third party form shortcode with the Kit form shortcode. * From 06a3bbfab1adf9066fef35a48cd40b6e71a887de Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 13 Jan 2026 18:15:53 +0800 Subject: [PATCH 4/6] Reinstate headless mode --- tests/EndToEnd.suite.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/EndToEnd.suite.yml b/tests/EndToEnd.suite.yml index d8ef7596f..7cf15b9ed 100644 --- a/tests/EndToEnd.suite.yml +++ b/tests/EndToEnd.suite.yml @@ -55,6 +55,7 @@ modules: capabilities: "goog:chromeOptions": args: + - "--headless" - "--disable-gpu" - "--disable-dev-shm-usage" - "--disable-software-rasterizer" From 81eedd7dc069222c66d0472b95bbf3b4a77f4a7e Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 13 Jan 2026 20:13:10 +0800 Subject: [PATCH 5/6] Tests: Removed third party plugin activation/deactivation --- .../plugin-screens/PluginSettingsToolsImporterAweberCest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterAweberCest.php b/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterAweberCest.php index 575e3bf93..e385e9cb4 100644 --- a/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterAweberCest.php +++ b/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterAweberCest.php @@ -22,7 +22,6 @@ public function _before(EndToEndTester $I) { // Activate Plugins. $I->activateKitPlugin($I); - $I->activateThirdPartyPlugin($I, 'aweber-web-form-widget'); } /** @@ -193,7 +192,6 @@ private function _createPagesWithAWeberFormShortcodes(EndToEndTester $I, $aweber */ public function _passed(EndToEndTester $I) { - $I->deactivateThirdPartyPlugin($I, 'aweber-web-form-widget'); $I->deactivateKitPlugin($I); $I->resetKitPlugin($I); } From d344c6687492619bdee7c114caeec95a9631ce4f Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Tue, 13 Jan 2026 20:15:41 +0800 Subject: [PATCH 6/6] Coding standards --- .../PluginSettingsToolsImporterAweberCest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterAweberCest.php b/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterAweberCest.php index e385e9cb4..27bdfca60 100644 --- a/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterAweberCest.php +++ b/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterAweberCest.php @@ -136,14 +136,14 @@ public function testAWeberImportWhenNoKitForms(EndToEndTester $I) * * @since 3.1.5 * - * @param EndToEndTester $I Tester. * @return array */ - private function _createAWeberForms(EndToEndTester $I) + private function _createAWeberForms() { // AWeber doesn't cache Forms or store them in the database, so we mock the data that would be returned from their API. return [ - '10', '11' + '10', + '11', ]; }