diff --git a/admin/importers/class-convertkit-admin-importer-aweber.php b/admin/importers/class-convertkit-admin-importer-aweber.php
index fd982f283..2df10614e 100644
--- a/admin/importers/class-convertkit-admin-importer-aweber.php
+++ b/admin/importers/class-convertkit-admin-importer-aweber.php
@@ -32,6 +32,24 @@ class ConvertKit_Admin_Importer_AWeber extends ConvertKit_Admin_Importer {
*/
public $shortcode_id_attribute = 'formid';
+ /**
+ * Holds the block name for AWeber forms.
+ *
+ * @since 3.1.6
+ *
+ * @var string
+ */
+ public $block_name = 'aweber-signupform-block/aweber-shortcode';
+
+ /**
+ * Holds the ID attribute name for AWeber forms.
+ *
+ * @since 3.1.6
+ *
+ * @var string
+ */
+ public $block_id_attribute = 'selectedShortCode';
+
/**
* Returns an array of AWeber form IDs and titles.
*
diff --git a/admin/importers/class-convertkit-admin-importer-mc4wp.php b/admin/importers/class-convertkit-admin-importer-mc4wp.php
index 84ed6e071..ad9239bb7 100644
--- a/admin/importers/class-convertkit-admin-importer-mc4wp.php
+++ b/admin/importers/class-convertkit-admin-importer-mc4wp.php
@@ -32,6 +32,24 @@ class ConvertKit_Admin_Importer_MC4WP extends ConvertKit_Admin_Importer {
*/
public $shortcode_id_attribute = 'id';
+ /**
+ * Holds the block name for MC4WP forms.
+ *
+ * @since 3.1.6
+ *
+ * @var string
+ */
+ public $block_name = 'mailchimp-for-wp/form';
+
+ /**
+ * Holds the ID attribute name for MC4WP forms.
+ *
+ * @since 3.1.6
+ *
+ * @var string
+ */
+ public $block_id_attribute = 'id';
+
/**
* Returns an array of MC4WP form IDs and titles.
*
diff --git a/admin/importers/class-convertkit-admin-importer.php b/admin/importers/class-convertkit-admin-importer.php
index c3f437f20..17e86d60c 100644
--- a/admin/importers/class-convertkit-admin-importer.php
+++ b/admin/importers/class-convertkit-admin-importer.php
@@ -24,7 +24,7 @@ abstract class ConvertKit_Admin_Importer {
public $shortcode_name = '';
/**
- * Holds the ID attribute name for the third party Form plugin.
+ * Holds the shortcode ID attribute name for the third party Form plugin.
*
* @since 3.1.0
*
@@ -32,6 +32,24 @@ abstract class ConvertKit_Admin_Importer {
*/
public $shortcode_id_attribute = '';
+ /**
+ * Holds the block name for the third party Form plugin.
+ *
+ * @since 3.1.6
+ *
+ * @var string
+ */
+ public $block_name = '';
+
+ /**
+ * Holds the block ID attribute name for the third party Form plugin.
+ *
+ * @since 3.1.6
+ *
+ * @var string
+ */
+ public $block_id_attribute = '';
+
/**
* Returns an array of third party form IDs and titles.
*
@@ -42,7 +60,7 @@ abstract class ConvertKit_Admin_Importer {
abstract public function get_forms();
/**
- * Returns an array of post IDs that contain the third partyform shortcode.
+ * Returns an array of post IDs that contain the third party form block or shortcode.
*
* @since 3.1.5
*
@@ -52,17 +70,21 @@ public function get_forms_in_posts() {
global $wpdb;
- // Search post_content for the third party form shortcode and return array of post IDs.
+ // Search post_content for the third party form block or shortcode and return array of post IDs.
$results = $wpdb->get_col(
$wpdb->prepare(
"
SELECT ID
FROM {$wpdb->posts}
WHERE post_status = %s
- AND post_content LIKE %s
+ AND (
+ post_content LIKE %s
+ OR post_content LIKE %s
+ )
",
'publish',
- '%[' . $this->shortcode_name . '%'
+ '%[' . $this->shortcode_name . '%',
+ '%
+
[aweber listid=6924484 formid=' . $aweberFormID . ' formtype=webform]
+Some content with characters !@£$%^&*()_+~!@£$%^&*()_+\\\
',
'meta_input' => [
'_wp_convertkit_post_meta' => [
'form' => '0',
diff --git a/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterMC4WPCest.php b/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterMC4WPCest.php
index 569fd0049..580ac359f 100644
--- a/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterMC4WPCest.php
+++ b/tests/EndToEnd/general/plugin-screens/PluginSettingsToolsImporterMC4WPCest.php
@@ -27,13 +27,13 @@ public function _before(EndToEndTester $I)
}
/**
- * Test that Mailchimp Forms are replaced with Kit Forms when the Tools > MC4WP: Migrate Configuration is configured.
+ * Test that Mailchimp Form Shortcodes are replaced with Kit Form Shortcodes when the Tools > MC4WP: Migrate Configuration is configured.
*
* @since 3.1.0
*
* @param EndToEndTester $I Tester.
*/
- public function testMC4WPImport(EndToEndTester $I)
+ public function testMC4WPImportWithShortcodes(EndToEndTester $I)
{
// Setup Plugin.
$I->setupKitPlugin($I);
@@ -67,6 +67,52 @@ public function testMC4WPImport(EndToEndTester $I)
}
}
+ /**
+ * Test that Mailchimp Blocks are replaced with Kit Blocks when the Tools > MC4WP: Migrate Configuration is configured.
+ *
+ * @since 3.1.6
+ *
+ * @param EndToEndTester $I Tester.
+ */
+ public function testMC4WPImportWithBlocks(EndToEndTester $I)
+ {
+ // Setup Plugin.
+ $I->setupKitPlugin($I);
+ $I->setupKitPluginResources($I);
+
+ // Create Mailchimp Forms.
+ $mailchimpFormIDs = $this->_createMailchimpForms($I);
+
+ // Insert Mailchimp Blocks into Pages.
+ $pageIDs = $this->_createPagesWithMC4WPBlocks($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.');
+
+ // 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 MC4WP: Migrate Configuration section is not displayed when no Mailchimp Forms exist.
*
@@ -197,6 +243,42 @@ private function _createPagesWithMailchimpFormShortcodes(EndToEndTester $I, $mai
return $pageIDs;
}
+ /**
+ * Create Pages with MC4WP Blocks.
+ *
+ * @since 3.1.6
+ *
+ * @param EndToEndTester $I Tester.
+ * @param array $mc4wpFormIDs MC4WP Form IDs.
+ * @return array
+ */
+ private function _createPagesWithMC4WPBlocks(EndToEndTester $I, $mc4wpFormIDs)
+ {
+ $pageIDs = array();
+
+ foreach ($mc4wpFormIDs as $mc4wpFormID) {
+ $pageIDs[] = $I->havePostInDatabase(
+ [
+ 'post_type' => 'page',
+ 'post_status' => 'publish',
+ 'post_title' => 'Page with MC4WP Block #' . $mc4wpFormID,
+ 'post_content' => 'Some content with characters !@£$%^&*()_+~!@£$%^&*()_+\\\
',
+
+ // Configure Kit Plugin to not display a default Form, so we test against the Kit Form in the content.
+ '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
diff --git a/tests/Integration/ImporterTest.php b/tests/Integration/ImporterTest.php
index 1fbbe2ca7..886c2a761 100644
--- a/tests/Integration/ImporterTest.php
+++ b/tests/Integration/ImporterTest.php
@@ -18,6 +18,15 @@ class ImporterTest extends WPTestCase
*/
protected $tester;
+ /**
+ * Holds the HTML block to test, which includes special characters.
+ *
+ * @since 3.1.6
+ *
+ * @var string
+ */
+ private $html_block = 'Some content with characters !@£$%^&*()_+~!@£$%^&*()_+\
';
+
/**
* Performs actions before each test.
*
@@ -153,6 +162,72 @@ public function testAWeberReplaceShortcodesInContentIgnoringOtherShortcodes()
}
}
+ /**
+ * Test that the replace_blocks_in_post() method replaces the third party form block with the Kit form block,
+ * and special characters are not stripped when the Post is saved.
+ *
+ * @since 3.1.6
+ */
+ public function testAWeberReplaceBlocksInPost()
+ {
+ // 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);
+
+ // Create a Post with an AWeber form block and HTML block, as if the user already created this post.
+ $postID = $this->factory->post->create(
+ [
+ 'post_type' => 'page',
+ 'post_status' => 'publish',
+ 'post_title' => 'AWeber: Replace Blocks in Post',
+ 'post_content' => str_replace(
+ '\\',
+ '\\\\',
+ '
+[aweber listid=6924484 formid=289586845 formtype=webform]
+' . $this->html_block
+ ),
+ ]
+ );
+
+ // Replace the blocks in the post.
+ $this->importer->replace_blocks_in_post( $postID, 289586845, $_ENV['CONVERTKIT_API_FORM_ID'] );
+
+ // Test the block is replaced with the Kit form block, and special characters are not stripped.
+ $this->assertEquals(
+ '' . $this->html_block,
+ get_post_field( 'post_content', $postID )
+ );
+ }
+
+ /**
+ * Test that the replace_blocks_in_content() method replaces the third party form block with the Kit form block,
+ * and special characters are not stripped.
+ *
+ * @since 3.1.6
+ */
+ public function testAWeberReplaceBlocksInContent()
+ {
+ // 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 blocks to test.
+ $content = '
+[aweber listid=6924484 formid=289586845 formtype=webform]
+' . $this->html_block;
+
+ // Test the block is replaced with the Kit form block.
+ $this->assertEquals(
+ '' . $this->html_block,
+ $this->importer->replace_blocks_in_content( parse_blocks( $content ), 289586845, $_ENV['CONVERTKIT_API_FORM_ID'] )
+ );
+ }
+
/**
* Test that the get_form_ids_from_content() method returns MC4WP form shortcode Form IDs
* ignoring any other shortcodes.
@@ -256,4 +331,62 @@ public function testMC4WPReplaceShortcodesInContentIgnoringOtherShortcodes()
);
}
}
+
+ /**
+ * Test that the replace_blocks_in_post() method replaces the third party form block with the Kit form block,
+ * and special characters are not stripped when the Post is saved.
+ *
+ * @since 3.1.6
+ */
+ public function testMC4WPReplaceBlocksInPost()
+ {
+ // 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);
+
+ // Create a Post with a MC4WP form block and HTML block, as if the user already created this post.
+ $postID = $this->factory->post->create(
+ [
+ 'post_type' => 'page',
+ 'post_status' => 'publish',
+ 'post_title' => 'Mailchimp 4 WP: Replace Blocks in Post',
+ 'post_content' => str_replace( '\\', '\\\\', '' . $this->html_block ),
+ ]
+ );
+
+ // Replace the blocks in the post.
+ $this->importer->replace_blocks_in_post( $postID, 4410, $_ENV['CONVERTKIT_API_FORM_ID'] );
+
+ // Test the block is replaced with the Kit form block, and special characters are not stripped.
+ $this->assertEquals(
+ '' . $this->html_block,
+ get_post_field( 'post_content', $postID )
+ );
+ }
+
+ /**
+ * Test that the replace_blocks_in_content() method replaces the third party form block with the Kit form block,
+ * and special characters are not stripped.
+ *
+ * @since 3.1.6
+ */
+ public function testMC4WPReplaceBlocksInContent()
+ {
+ // 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 blocks to test.
+ $content = '' . $this->html_block;
+
+ // Test the block is replaced with the Kit form block.
+ $this->assertEquals(
+ '' . $this->html_block,
+ $this->importer->replace_blocks_in_content( parse_blocks( $content ), 4410, $_ENV['CONVERTKIT_API_FORM_ID'] )
+ );
+ }
}