diff --git a/admin/importers/class-convertkit-admin-importer-activecampaign.php b/admin/importers/class-convertkit-admin-importer-activecampaign.php new file mode 100644 index 000000000..f8fe7b023 --- /dev/null +++ b/admin/importers/class-convertkit-admin-importer-activecampaign.php @@ -0,0 +1,85 @@ + __( 'The uploaded configuration file isn\'t valid.', 'convertkit' ), 'import_configuration_empty' => __( 'The uploaded configuration file contains no settings.', 'convertkit' ), 'import_configuration_success' => __( 'Configuration imported successfully.', 'convertkit' ), + 'migrate_activecampaign_configuration_success' => __( 'ActiveCampaign forms migrated successfully.', 'convertkit' ), 'migrate_aweber_configuration_success' => __( 'AWeber forms migrated successfully.', 'convertkit' ), 'migrate_mc4wp_configuration_success' => __( 'MC4WP forms migrated successfully.', 'convertkit' ), 'migrate_mailpoet_configuration_success' => __( 'MailPoet forms migrated successfully.', 'convertkit' ), @@ -79,6 +80,7 @@ private function maybe_perform_actions() { $this->maybe_download_system_info(); $this->maybe_export_configuration(); $this->maybe_import_configuration(); + $this->maybe_migrate_activecampaign_configuration(); $this->maybe_migrate_aweber_configuration(); $this->maybe_migrate_mc4wp_configuration(); $this->maybe_migrate_mailpoet_configuration(); @@ -322,6 +324,43 @@ private function maybe_import_configuration() { } + /** + * Replaces ActiveCampaign Form Shortcodes and Blocks with Kit Form Shortcodes and Blocks, if the user submitted the + * ActiveCampaign Migrate Configuration section. + * + * @since 3.1.7 + */ + private function maybe_migrate_activecampaign_configuration() { + + // Bail if nonce verification fails. + if ( ! isset( $_REQUEST['_convertkit_settings_tools_nonce'] ) ) { + return; + } + + if ( ! wp_verify_nonce( sanitize_key( $_REQUEST['_convertkit_settings_tools_nonce'] ), 'convertkit-settings-tools' ) ) { + return; + } + + // Bail if no ActiveCampaign Form IDs were submitted. + if ( ! isset( $_REQUEST['_wp_convertkit_integration_activecampaign_settings'] ) ) { + return; + } + + // Initialise the importer. + $activecampaign = new ConvertKit_Admin_Importer_ActiveCampaign(); + + // Iterate through the ActiveCampaign Form IDs, replacing the shortcodes with the Kit Form Shortcodes + // and blocks with the Kit Form Blocks. + foreach ( array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['_wp_convertkit_integration_activecampaign_settings'] ) ) as $activecampaign_form_id => $kit_form_id ) { + $activecampaign->replace_blocks_in_posts( (int) $activecampaign_form_id, (int) $kit_form_id ); + $activecampaign->replace_shortcodes_in_posts( (int) $activecampaign_form_id, (int) $kit_form_id ); + } + + // Redirect to Tools screen. + $this->redirect_with_success_notice( 'migrate_activecampaign_configuration_success' ); + + } + /** * Replaces AWeber Form Shortcodes with Kit Form Shortcodes, if the user submitted the * AWeber Migrate Configuration section. @@ -488,10 +527,11 @@ public function render() { $forms = new ConvertKit_Resource_Forms(); // Get Importers. - $aweber = new ConvertKit_Admin_Importer_AWeber(); - $mc4wp = new ConvertKit_Admin_Importer_MC4WP(); - $mailpoet = new ConvertKit_Admin_Importer_Mailpoet(); - $newsletter = new ConvertKit_Admin_Importer_Newsletter(); + $activecampaign = new ConvertKit_Admin_Importer_ActiveCampaign(); + $aweber = new ConvertKit_Admin_Importer_AWeber(); + $mc4wp = new ConvertKit_Admin_Importer_MC4WP(); + $mailpoet = new ConvertKit_Admin_Importer_Mailpoet(); + $newsletter = new ConvertKit_Admin_Importer_Newsletter(); // Output view. require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/settings/tools.php'; diff --git a/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterActiveCampaignCest.php b/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterActiveCampaignCest.php new file mode 100644 index 000000000..88cb63345 --- /dev/null +++ b/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterActiveCampaignCest.php @@ -0,0 +1,296 @@ + Kit > Tools > Import sections for ActiveCampaign. + * + * @since 3.1.7 + */ +class PluginSettingsToolsImporterActiveCampaignCest +{ + /** + * Run common actions before running the test functions in this class. + * + * @since 3.1.7 + * + * @param EndToEndTester $I Tester. + */ + public function _before(EndToEndTester $I) + { + // Activate Plugins. + $I->activateKitPlugin($I); + } + + /** + * Test that ActiveCampaign Form Shortcodes are replaced with Kit Form Shortcodes when the Tools > ActiveCampaign: Migrate Configuration is configured. + * + * @since 3.1.7 + * + * @param EndToEndTester $I Tester. + */ + public function testActiveCampaignImportWithShortcodes(EndToEndTester $I) + { + // Setup Plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Create ActiveCampaign Forms. + $activecampaignFormIDs = $this->_createActiveCampaignForms($I); + + // Insert ActiveCampaign Form Shortcodes into Pages. + $pageIDs = $this->_createPagesWithActiveCampaignFormShortcodes($I, $activecampaignFormIDs); + + // Navigate to the Tools screen. + $I->loadKitSettingsToolsScreen($I); + + // Select the Kit Forms to replace the ActiveCampaign Forms. + foreach ($activecampaignFormIDs as $activecampaignFormID) { + $I->selectOption('_wp_convertkit_integration_activecampaign_settings[' . $activecampaignFormID . ']', $_ENV['CONVERTKIT_API_FORM_ID']); + } + + // Click the Migrate button. + $I->click('Migrate'); + + // Confirm success message displays. + $I->waitForElementVisible('.notice-success'); + $I->see('ActiveCampaign 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 ActiveCampaign Blocks are replaced with Kit Blocks when the Tools > ActiveCampaign: Migrate Configuration is configured. + * + * @since 3.1.7 + * + * @param EndToEndTester $I Tester. + */ + public function testActiveCampaignImportWithBlocks(EndToEndTester $I) + { + // Setup Plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Create ActiveCampaign Forms. + $activecampaignFormIDs = $this->_createActiveCampaignForms($I); + + // Insert ActiveCampaign Blocks into Pages. + $pageIDs = $this->_createPagesWithActiveCampaignBlocks($I, $activecampaignFormIDs); + + // Navigate to the Tools screen. + $I->loadKitSettingsToolsScreen($I); + + // Select the Kit Forms to replace the ActiveCampaign Forms. + foreach ($activecampaignFormIDs as $activecampaignFormID) { + $I->selectOption('_wp_convertkit_integration_activecampaign_settings[' . $activecampaignFormID . ']', $_ENV['CONVERTKIT_API_FORM_ID']); + } + + // Click the Migrate button. + $I->click('Migrate'); + + // Confirm success message displays. + $I->waitForElementVisible('.notice-success'); + $I->see('ActiveCampaign forms migrated successfully.'); + + // Test each Page. + foreach ($pageIDs as $pageID) { + $I->amOnPage('?p=' . $pageID); + + // Check Kit Form block is displayed. + $I->seeElementInDOM('form[data-sv-form]'); + + // Confirm special characters have not been stripped. + $I->seeInSource('!@£$%^&*()_+~!@£$%^&*()_+\\'); + } + } + + /** + * Test that the ActiveCampaign: Migrate Configuration section is not displayed when no ActiveCampaign Forms exist. + * + * @since 3.1.7 + * + * @param EndToEndTester $I Tester. + */ + public function testActiveCampaignImportWhenNoActiveCampaignForms(EndToEndTester $I) + { + // Setup Plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Navigate to the Tools screen. + $I->loadKitSettingsToolsScreen($I); + + // Confirm no ActiveCampaign: Migrate Configuration section is displayed. + $I->dontSeeElementInDOM('#import-activecampaign'); + } + + /** + * Test that the ActiveCampaign: Migrate Configuration section is not displayed when ActiveCampaign Forms exist, + * but no Pages, Posts or Custom Posts contain ActiveCampaign Form Shortcodes. + * + * @since 3.1.7 + * + * @param EndToEndTester $I Tester. + */ + public function testActiveCampaignImportWhenNoActiveCampaignShortcodesInContent(EndToEndTester $I) + { + // Setup Plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Create ActiveCampaign Forms. + $this->_createActiveCampaignForms($I); + + // Navigate to the Tools screen. + $I->loadKitSettingsToolsScreen($I); + + // Confirm no ActiveCampaign: Migrate Configuration section is displayed, as there are no + // ActiveCampaign Form Shortcodes in the content. + $I->dontSeeElementInDOM('#import-activecampaign'); + } + + /** + * Test that the ActiveCampaign: Migrate Configuration section is not displayed when no Kit Forms exist. + * + * @since 3.1.7 + * + * @param EndToEndTester $I Tester. + */ + public function testActiveCampaignImportWhenNoKitForms(EndToEndTester $I) + { + // Setup Plugin. + $I->setupKitPluginCredentialsNoData($I); + $I->setupKitPluginResourcesNoData($I); + + // Navigate to the Tools screen. + $I->loadKitSettingsToolsScreen($I); + + // Confirm no ActiveCampaign: Migrate Configuration section is displayed, as there are no + // ActiveCampaign Form Shortcodes in the content. + $I->dontSeeElementInDOM('#import-activecampaign'); + } + + /** + * Create ActiveCampaign Forms. + * + * @since 3.1.7 + * + * @param EndToEndTester $I Tester. + * @return array + */ + private function _createActiveCampaignForms(EndToEndTester $I) + { + // Enable Defer and Delay JavaScript. + $I->haveOptionInDatabase( + 'settings_activecampaign', + [ + 'forms' => [ + 1 => [ + 'id' => '1', + 'name' => 'ActiveCampaign Form #1', + ], + 2 => [ + 'id' => '2', + 'name' => 'ActiveCampaign Form #2', + ], + ], + ] + ); + + // Return Form IDs. + return [ 1, 2 ]; + } + + /** + * Create Pages with ActiveCampaign Form Shortcodes. + * + * @since 3.1.7 + * + * @param EndToEndTester $I Tester. + * @param array $activecampaignFormIDs ActiveCampaign Form IDs. + * @return array + */ + private function _createPagesWithActiveCampaignFormShortcodes(EndToEndTester $I, $activecampaignFormIDs) + { + $pageIDs = array(); + + foreach ($activecampaignFormIDs as $activecampaignFormID) { + $pageIDs[] = $I->havePostInDatabase( + [ + 'post_type' => 'page', + 'post_status' => 'publish', + 'post_title' => 'Page with ActiveCampaign Form #' . $activecampaignFormID, + 'post_content' => '[activecampaign form="' . $activecampaignFormID . '"]', + 'meta_input' => [ + '_wp_convertkit_post_meta' => [ + 'form' => '0', + 'landing_page' => '', + 'tag' => '', + ], + ], + ] + ); + } + + return $pageIDs; + } + + /** + * Create Pages with ActiveCampaign Blocks. + * + * @since 3.1.7 + * + * @param EndToEndTester $I Tester. + * @param array $activecampaignFormIDs ActiveCampaign Form IDs. + * @return array + */ + private function _createPagesWithActiveCampaignBlocks(EndToEndTester $I, $activecampaignFormIDs) + { + $pageIDs = array(); + + foreach ($activecampaignFormIDs as $activecampaignFormID) { + $pageIDs[] = $I->havePostInDatabase( + [ + 'post_type' => 'page', + 'post_status' => 'publish', + 'post_title' => 'Page with ActiveCampaign Block #' . $activecampaignFormID, + 'post_content' => '
+
+
| + | + |
|---|---|
| + | + + | +
+ +
+