From 75fb1ac297ca317d2ec6c42bd32bc03607e196db Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 30 Apr 2026 11:35:15 +0800 Subject: [PATCH 1/9] Form Builder: Set correct subscriber state when a Kit Form is used --- includes/blocks/class-convertkit-block-form-builder.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/includes/blocks/class-convertkit-block-form-builder.php b/includes/blocks/class-convertkit-block-form-builder.php index df67aa3c8..985417dcd 100644 --- a/includes/blocks/class-convertkit-block-form-builder.php +++ b/includes/blocks/class-convertkit-block-form-builder.php @@ -138,11 +138,16 @@ public function maybe_subscribe() { 'block_form_builder' ); + // Determine the subscriber state. + // If a Form is specified, mark the subscriber as inactive, so the form's double optin is honored. + // If a Tag or Sequence is specified, mark the subscriber as active, as there's no double optin for tags or sequences. + $subscriber_state = $form_id !== false ? 'inactive' : 'active'; + // Create subscriber. $result = $api->create_subscriber( sanitize_email( $form_data['email'] ), array_key_exists( 'first_name', $form_data ) ? $form_data['first_name'] : '', - 'active', + $subscriber_state, $custom_fields ); From 081b0a695680919fff37c6a93c3e54352f9965c8 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 30 Apr 2026 12:54:08 +0800 Subject: [PATCH 2/9] Updated test --- .env.dist.testing | 2 ++ .../blocks-shortcodes/PageBlockFormBuilderCest.php | 8 ++++++-- tests/Support/Helper/KitPlugin.php | 11 +++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.env.dist.testing b/.env.dist.testing index d00480684..90b1e42b0 100644 --- a/.env.dist.testing +++ b/.env.dist.testing @@ -37,6 +37,8 @@ CONVERTKIT_API_SUBSCRIBER_ID="1579118532" CONVERTKIT_API_SUBSCRIBER_ID_NO_ACCESS="1632998602" CONVERTKIT_API_FORM_NAME="Page Form [inline]" CONVERTKIT_API_FORM_ID="2765139" +CONVERTKIT_API_FORM_DOUBLE_OPTIN_NAME="Double Optin Form [inline]" +CONVERTKIT_API_FORM_DOUBLE_OPTIN_ID="2765143" CONVERTKIT_API_FORM_FORMAT_MODAL_NAME="Modal Form [modal]" CONVERTKIT_API_FORM_FORMAT_MODAL_NAME_ONLY="Modal Form" CONVERTKIT_API_FORM_FORMAT_MODAL_ID="2780977" diff --git a/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormBuilderCest.php b/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormBuilderCest.php index 2f02ca7da..30f6b0f4a 100644 --- a/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormBuilderCest.php +++ b/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormBuilderCest.php @@ -309,7 +309,7 @@ public function testFormBuilderBlockWithFormEnabled(EndToEndTester $I) blockName: 'Kit Form Builder', blockProgrammaticName: 'convertkit-form-builder', blockConfiguration: [ - 'form_id' => [ 'select', $_ENV['CONVERTKIT_API_FORM_NAME'] ], + 'form_id' => [ 'select', $_ENV['CONVERTKIT_API_FORM_DOUBLE_OPTIN_NAME'] ], ] ); @@ -373,11 +373,15 @@ public function testFormBuilderBlockWithFormEnabled(EndToEndTester $I) firstName: 'First' ); + // Confirm that the subscriber is inactive, as a form was used. + // This honors a Form's double optin setting. + $I->assertEquals('inactive', $subscriber['state']); + // Confirm that the subscriber has the form. $I->apiCheckSubscriberHasForm( $I, subscriberID: $subscriber['id'], - formID: $_ENV['CONVERTKIT_API_FORM_ID'], + formID: $_ENV['CONVERTKIT_API_FORM_DOUBLE_OPTIN_ID'], referrer: $_ENV['WORDPRESS_URL'] . $I->grabFromCurrentUrl() ); } diff --git a/tests/Support/Helper/KitPlugin.php b/tests/Support/Helper/KitPlugin.php index 9df9404eb..665965896 100644 --- a/tests/Support/Helper/KitPlugin.php +++ b/tests/Support/Helper/KitPlugin.php @@ -222,6 +222,17 @@ public function setupKitPluginResources($I) $I->haveOptionInDatabase( 'convertkit_forms', [ + 2765143 => [ + 'id' => 2765143, + 'name' => 'Double Optin Form', + 'created_at' => '2021-11-11T15:31:28Z', + 'type' => 'embed', + 'format' => 'inline', + 'embed_js' => 'https://cheerful-architect-3237.kit.com/a04b384fc6/index.js', + 'embed_url' => 'https://cheerful-architect-3237.kit.com/a04b384fc6', + 'archived' => false, + 'uid' => 'a04b384fc6', + ], 3003590 => [ 'id' => 3003590, 'name' => 'Third Party Integrations Form', From cfd212e75c31940ed5f3d6993b3532c8e28d861d Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 30 Apr 2026 12:57:48 +0800 Subject: [PATCH 3/9] Tests: Integrations: Assert `inactive` subscriber state when a Kit Form is used --- .../integrations/other/ContactForm7FormCest.php | 8 ++++++-- .../integrations/other/ForminatorCest.php | 16 ++++++++++++---- .../integrations/wlm/WishListMemberCest.php | 8 ++++++-- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/tests/EndToEnd/integrations/other/ContactForm7FormCest.php b/tests/EndToEnd/integrations/other/ContactForm7FormCest.php index e9a1cc2b4..481a99963 100644 --- a/tests/EndToEnd/integrations/other/ContactForm7FormCest.php +++ b/tests/EndToEnd/integrations/other/ContactForm7FormCest.php @@ -53,7 +53,7 @@ public function testSettingsContactForm7ToKitFormMapping(EndToEndTester $I) // Setup Contact form 7 Form and configuration for this test. $pageID = $this->_contactForm7SetupForm( $I, - $_ENV['CONVERTKIT_API_THIRD_PARTY_INTEGRATIONS_FORM_NAME'] + $_ENV['CONVERTKIT_API_DOUBLE_OPTIN_FORM_NAME'] ); // Define email address for this test. @@ -72,11 +72,15 @@ public function testSettingsContactForm7ToKitFormMapping(EndToEndTester $I) // Confirm that the email address was added to Kit. $subscriber = $I->apiCheckSubscriberExists($I, $emailAddress); + // Confirm that the subscriber is inactive, as a form was used. + // This honors a Form's double optin setting. + $I->assertEquals('inactive', $subscriber['state']); + // Check that the subscriber has the expected form and referrer value set. $I->apiCheckSubscriberHasForm( $I, subscriberID: $subscriber['id'], - formID: $_ENV['CONVERTKIT_API_THIRD_PARTY_INTEGRATIONS_FORM_ID'], + formID: $_ENV['CONVERTKIT_API_DOUBLE_OPTIN_FORM_ID'], referrer: $_ENV['WORDPRESS_URL'] . $I->grabFromCurrentUrl() ); } diff --git a/tests/EndToEnd/integrations/other/ForminatorCest.php b/tests/EndToEnd/integrations/other/ForminatorCest.php index a37fdb5d1..6401c2336 100644 --- a/tests/EndToEnd/integrations/other/ForminatorCest.php +++ b/tests/EndToEnd/integrations/other/ForminatorCest.php @@ -53,7 +53,7 @@ public function testSettingsForminatorFormToKitFormMapping(EndToEndTester $I) // Setup Forminator Form and configuration for this test. $pageID = $this->_forminatorSetupForm( $I, - $_ENV['CONVERTKIT_API_THIRD_PARTY_INTEGRATIONS_FORM_NAME'] + $_ENV['CONVERTKIT_API_DOUBLE_OPTIN_FORM_NAME'] ); // Define email address for this test. @@ -72,11 +72,15 @@ public function testSettingsForminatorFormToKitFormMapping(EndToEndTester $I) // Confirm that the email address was added to Kit. $subscriber = $I->apiCheckSubscriberExists($I, $emailAddress); + // Confirm that the subscriber is inactive, as a form was used. + // This honors a Form's double optin setting. + $I->assertEquals('inactive', $subscriber['state']); + // Check that the subscriber has the expected form and referrer value set. $I->apiCheckSubscriberHasForm( $I, subscriberID: $subscriber['id'], - formID: $_ENV['CONVERTKIT_API_THIRD_PARTY_INTEGRATIONS_FORM_ID'], + formID: $_ENV['CONVERTKIT_API_DOUBLE_OPTIN_FORM_ID'], referrer: $_ENV['WORDPRESS_URL'] . $I->grabFromCurrentUrl() ); } @@ -257,7 +261,7 @@ public function testSettingsForminatorQuizToKitFormMapping(EndToEndTester $I) // Setup Forminator Quiz and configuration for this test. $pageID = $this->_forminatorSetupQuiz( $I, - $_ENV['CONVERTKIT_API_THIRD_PARTY_INTEGRATIONS_FORM_NAME'] + $_ENV['CONVERTKIT_API_DOUBLE_OPTIN_FORM_NAME'] ); // Define email address for this test. @@ -274,7 +278,11 @@ public function testSettingsForminatorQuizToKitFormMapping(EndToEndTester $I) $I->wait(2); // Confirm that the email address was added to Kit. - $I->apiCheckSubscriberExists($I, $emailAddress); + $subscriber = $I->apiCheckSubscriberExists($I, $emailAddress); + + // Confirm that the subscriber is inactive, as a form was used. + // This honors a Form's double optin setting. + $I->assertEquals('inactive', $subscriber['state']); } /** diff --git a/tests/EndToEnd/integrations/wlm/WishListMemberCest.php b/tests/EndToEnd/integrations/wlm/WishListMemberCest.php index 6230c81f7..311c10daf 100644 --- a/tests/EndToEnd/integrations/wlm/WishListMemberCest.php +++ b/tests/EndToEnd/integrations/wlm/WishListMemberCest.php @@ -47,13 +47,17 @@ public function testWLMToKitFormMappingOnLevelAdded(EndToEndTester $I) $userID = $this->_createUser($I, $emailAddress); // Configure mapping. - $this->_configureMapping($I, $wlmLevelID, 'add', $_ENV['CONVERTKIT_API_THIRD_PARTY_INTEGRATIONS_FORM_NAME']); + $this->_configureMapping($I, $wlmLevelID, 'add', $_ENV['CONVERTKIT_API_DOUBLE_OPTIN_FORM_NAME']); // Assign level to user. $this->_assignLevelToUser($I, $wlmLevelID, $userID); // Confirm that the email address was added to Kit. - $I->apiCheckSubscriberExists($I, $emailAddress); + $susbcriber = $I->apiCheckSubscriberExists($I, $emailAddress); + + // Confirm that the subscriber is inactive, as a form was used. + // This honors a Form's double optin setting. + $I->assertEquals('inactive', $subscriber['state']); } /** From ebda2f4d119ae5077e9ab24c3bf6b068c67bc723 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 30 Apr 2026 13:56:26 +0800 Subject: [PATCH 4/9] Tests: Fix .env names --- tests/EndToEnd/integrations/other/ContactForm7FormCest.php | 4 ++-- tests/EndToEnd/integrations/other/ForminatorCest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/EndToEnd/integrations/other/ContactForm7FormCest.php b/tests/EndToEnd/integrations/other/ContactForm7FormCest.php index 481a99963..e88d79a08 100644 --- a/tests/EndToEnd/integrations/other/ContactForm7FormCest.php +++ b/tests/EndToEnd/integrations/other/ContactForm7FormCest.php @@ -53,7 +53,7 @@ public function testSettingsContactForm7ToKitFormMapping(EndToEndTester $I) // Setup Contact form 7 Form and configuration for this test. $pageID = $this->_contactForm7SetupForm( $I, - $_ENV['CONVERTKIT_API_DOUBLE_OPTIN_FORM_NAME'] + $_ENV['CONVERTKIT_API_FORM_DOUBLE_OPTIN_NAME'] ); // Define email address for this test. @@ -80,7 +80,7 @@ public function testSettingsContactForm7ToKitFormMapping(EndToEndTester $I) $I->apiCheckSubscriberHasForm( $I, subscriberID: $subscriber['id'], - formID: $_ENV['CONVERTKIT_API_DOUBLE_OPTIN_FORM_ID'], + formID: $_ENV['CONVERTKIT_API_FORM_DOUBLE_OPTIN_ID'], referrer: $_ENV['WORDPRESS_URL'] . $I->grabFromCurrentUrl() ); } diff --git a/tests/EndToEnd/integrations/other/ForminatorCest.php b/tests/EndToEnd/integrations/other/ForminatorCest.php index 6401c2336..46ad5ba40 100644 --- a/tests/EndToEnd/integrations/other/ForminatorCest.php +++ b/tests/EndToEnd/integrations/other/ForminatorCest.php @@ -53,7 +53,7 @@ public function testSettingsForminatorFormToKitFormMapping(EndToEndTester $I) // Setup Forminator Form and configuration for this test. $pageID = $this->_forminatorSetupForm( $I, - $_ENV['CONVERTKIT_API_DOUBLE_OPTIN_FORM_NAME'] + $_ENV['CONVERTKIT_API_FORM_DOUBLE_OPTIN_NAME'] ); // Define email address for this test. @@ -261,7 +261,7 @@ public function testSettingsForminatorQuizToKitFormMapping(EndToEndTester $I) // Setup Forminator Quiz and configuration for this test. $pageID = $this->_forminatorSetupQuiz( $I, - $_ENV['CONVERTKIT_API_DOUBLE_OPTIN_FORM_NAME'] + $_ENV['CONVERTKIT_API_FORM_DOUBLE_OPTIN_NAME'] ); // Define email address for this test. From cb76508b8fb36f1012fd5ee644f361d70d39dcdc Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 30 Apr 2026 14:47:23 +0800 Subject: [PATCH 5/9] Form Builder: Support Legacy Forms --- .../class-convertkit-block-form-builder.php | 19 +++- tests/EndToEnd.suite.yml | 1 - .../PageBlockFormBuilderCest.php | 97 +++++++++++++++++++ 3 files changed, 111 insertions(+), 6 deletions(-) diff --git a/includes/blocks/class-convertkit-block-form-builder.php b/includes/blocks/class-convertkit-block-form-builder.php index 985417dcd..fe1a97b20 100644 --- a/includes/blocks/class-convertkit-block-form-builder.php +++ b/includes/blocks/class-convertkit-block-form-builder.php @@ -194,11 +194,20 @@ public function maybe_subscribe() { // If a form was specified, add the subscriber to the form. if ( $form_id ) { - $result = $api->add_subscriber_to_form( - $form_id, - $result['subscriber']['id'], - get_permalink( absint( $form_data['post_id'] ) ) - ); + // For Legacy Forms, a different endpoint is used. + $forms = new ConvertKit_Resource_Forms(); + if ( $forms->is_legacy( $form_id ) ) { + $result = $api->add_subscriber_to_legacy_form( + $form_id, + $result['subscriber']['id'] + ); + } else { + $result = $api->add_subscriber_to_form( + $form_id, + $result['subscriber']['id'], + get_permalink( absint( $form_data['post_id'] ) ) + ); + } if ( $form_data['store_entries'] ) { $entries->upsert( diff --git a/tests/EndToEnd.suite.yml b/tests/EndToEnd.suite.yml index 8e565cf34..8747fdc13 100644 --- a/tests/EndToEnd.suite.yml +++ b/tests/EndToEnd.suite.yml @@ -56,7 +56,6 @@ modules: capabilities: "goog:chromeOptions": args: - - "--headless" - "--disable-gpu" - "--disable-dev-shm-usage" - "--disable-software-rasterizer" diff --git a/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormBuilderCest.php b/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormBuilderCest.php index 30f6b0f4a..c57019fd7 100644 --- a/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormBuilderCest.php +++ b/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormBuilderCest.php @@ -386,6 +386,103 @@ public function testFormBuilderBlockWithFormEnabled(EndToEndTester $I) ); } + /** + * Test the Form Builder block works when added and a Legacy Form is specified + * to subscribe the subscriber to. + * + * @since 3.3.2 + * + * @param EndToEndTester $I Tester. + */ + public function testFormBuilderBlockWithLegacyFormEnabled(EndToEndTester $I) + { + // Setup Plugin and Resources. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + title: 'Kit: Page: Form Builder: Block: Form Enabled' + ); + + // Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg. + $I->configurePluginSidebarSettings( + $I, + form: 'None' + ); + + // Add block to Page. + $I->addGutenbergBlock( + $I, + blockName: 'Kit Form Builder', + blockProgrammaticName: 'convertkit-form-builder', + blockConfiguration: [ + 'form_id' => [ 'select', $_ENV['CONVERTKIT_API_LEGACY_FORM_NAME'] ], + ] + ); + + // Confirm the block template was used as the default. + $this->seeFormBuilderBlock($I); + $this->seeFormBuilderButtonBlock($I); + $this->seeFormBuilderField( + $I, + fieldType: 'text', + fieldName: 'first_name', + fieldID: 'first_name', + label: 'First name', + container: 'div[data-type="convertkit/form-builder"]' + ); + $this->seeFormBuilderField( + $I, + fieldType: 'email', + fieldName: 'email', + fieldID: 'email', + label: 'Email address', + container: 'div[data-type="convertkit/form-builder"]' + ); + + // Publish and view the Page on the frontend site. + $I->publishAndViewGutenbergPage($I); + + // Confirm that the Form is output in the DOM. + $this->seeFormBuilderField( + $I, + fieldType: 'text', + fieldName: 'first_name', + fieldID: 'first_name', + label: 'First name', + container: 'div.wp-block-convertkit-form-builder', + isFrontend: true + ); + $this->seeFormBuilderField( + $I, + fieldType: 'email', + fieldName: 'email', + fieldID: 'email', + label: 'Email address', + container: 'div.wp-block-convertkit-form-builder', + isFrontend: true + ); + + // Generate email address for this test. + $emailAddress = $I->generateEmailAddress(); + + // Submit form. + $I->fillField('input[name="convertkit[first_name]"]', 'First'); + $I->fillField('input[name="convertkit[email]"]', $emailAddress); + $I->click('div.wp-block-convertkit-form-builder button[type="submit"]'); + + // Confirm that the email address was added to Kit. + $I->waitForElementVisible('.convertkit-form-builder-subscribed-message'); + $I->wait(3); + $I->apiCheckSubscriberExists( + $I, + emailAddress: $emailAddress, + firstName: 'First' + ); + } + /** * Test the Form Builder block works when added and a Tag is specified * to subscribe the subscriber to. From d241252cd8cf073fbe364ae103bfd909e88d160e Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 30 Apr 2026 14:57:57 +0800 Subject: [PATCH 6/9] Fix failing tests --- tests/EndToEnd/integrations/other/ForminatorCest.php | 9 ++++++++- .../EndToEnd/integrations/wlm/WishListMemberCest.php | 11 +++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/EndToEnd/integrations/other/ForminatorCest.php b/tests/EndToEnd/integrations/other/ForminatorCest.php index 46ad5ba40..2f928f021 100644 --- a/tests/EndToEnd/integrations/other/ForminatorCest.php +++ b/tests/EndToEnd/integrations/other/ForminatorCest.php @@ -80,7 +80,7 @@ public function testSettingsForminatorFormToKitFormMapping(EndToEndTester $I) $I->apiCheckSubscriberHasForm( $I, subscriberID: $subscriber['id'], - formID: $_ENV['CONVERTKIT_API_DOUBLE_OPTIN_FORM_ID'], + formID: $_ENV['CONVERTKIT_API_FORM_DOUBLE_OPTIN_ID'], referrer: $_ENV['WORDPRESS_URL'] . $I->grabFromCurrentUrl() ); } @@ -283,6 +283,13 @@ public function testSettingsForminatorQuizToKitFormMapping(EndToEndTester $I) // Confirm that the subscriber is inactive, as a form was used. // This honors a Form's double optin setting. $I->assertEquals('inactive', $subscriber['state']); + + // Check that the subscriber has the expected form value set. + $I->apiCheckSubscriberHasForm( + $I, + subscriberID: $subscriber['id'], + formID: $_ENV['CONVERTKIT_API_FORM_DOUBLE_OPTIN_ID'] + ); } /** diff --git a/tests/EndToEnd/integrations/wlm/WishListMemberCest.php b/tests/EndToEnd/integrations/wlm/WishListMemberCest.php index 311c10daf..e36262f29 100644 --- a/tests/EndToEnd/integrations/wlm/WishListMemberCest.php +++ b/tests/EndToEnd/integrations/wlm/WishListMemberCest.php @@ -47,17 +47,24 @@ public function testWLMToKitFormMappingOnLevelAdded(EndToEndTester $I) $userID = $this->_createUser($I, $emailAddress); // Configure mapping. - $this->_configureMapping($I, $wlmLevelID, 'add', $_ENV['CONVERTKIT_API_DOUBLE_OPTIN_FORM_NAME']); + $this->_configureMapping($I, $wlmLevelID, 'add', $_ENV['CONVERTKIT_API_FORM_DOUBLE_OPTIN_NAME']); // Assign level to user. $this->_assignLevelToUser($I, $wlmLevelID, $userID); // Confirm that the email address was added to Kit. - $susbcriber = $I->apiCheckSubscriberExists($I, $emailAddress); + $subscriber = $I->apiCheckSubscriberExists($I, $emailAddress); // Confirm that the subscriber is inactive, as a form was used. // This honors a Form's double optin setting. $I->assertEquals('inactive', $subscriber['state']); + + // Check that the subscriber has the expected form value set. + $I->apiCheckSubscriberHasForm( + $I, + subscriberID: $subscriber['id'], + formID: $_ENV['CONVERTKIT_API_FORM_DOUBLE_OPTIN_ID'] + ); } /** From 7cbf0ab04b225d7b2451840c6118195eeb1cd262 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 30 Apr 2026 14:59:36 +0800 Subject: [PATCH 7/9] Run chromedriver in 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 8747fdc13..8e565cf34 100644 --- a/tests/EndToEnd.suite.yml +++ b/tests/EndToEnd.suite.yml @@ -56,6 +56,7 @@ modules: capabilities: "goog:chromeOptions": args: + - "--headless" - "--disable-gpu" - "--disable-dev-shm-usage" - "--disable-software-rasterizer" From a213fa9be7606416b8999fcbed41540b925d4cc7 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Fri, 1 May 2026 11:33:37 +0800 Subject: [PATCH 8/9] Tests: Check subscriber state for single and double optin forms --- .env.dist.testing | 2 + .../PageBlockFormBuilderCest.php | 115 +++++++++++++++++- tests/Support/Helper/KitPlugin.php | 11 ++ 3 files changed, 125 insertions(+), 3 deletions(-) diff --git a/.env.dist.testing b/.env.dist.testing index 90b1e42b0..31a59c636 100644 --- a/.env.dist.testing +++ b/.env.dist.testing @@ -37,6 +37,8 @@ CONVERTKIT_API_SUBSCRIBER_ID="1579118532" CONVERTKIT_API_SUBSCRIBER_ID_NO_ACCESS="1632998602" CONVERTKIT_API_FORM_NAME="Page Form [inline]" CONVERTKIT_API_FORM_ID="2765139" +CONVERTKIT_API_FORM_SINGLE_OPTIN_NAME="Auto Confirm Form [inline]" +CONVERTKIT_API_FORM_SINGLE_OPTIN_ID="3059218" CONVERTKIT_API_FORM_DOUBLE_OPTIN_NAME="Double Optin Form [inline]" CONVERTKIT_API_FORM_DOUBLE_OPTIN_ID="2765143" CONVERTKIT_API_FORM_FORMAT_MODAL_NAME="Modal Form [modal]" diff --git a/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormBuilderCest.php b/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormBuilderCest.php index 30f6b0f4a..d9c44bde7 100644 --- a/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormBuilderCest.php +++ b/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormBuilderCest.php @@ -278,14 +278,123 @@ public function testFormBuilderBlockWithTextCustomization(EndToEndTester $I) } /** - * Test the Form Builder block works when added and a Form is specified - * to subscribe the subscriber to. + * Test the Form Builder block works when added and that the subscriber's state + * is active when a single optin Form is specified. + * + * @since 3.0.4 + * + * @param EndToEndTester $I Tester. + */ + public function testFormBuilderBlockWithSingleOptinFormEnabled(EndToEndTester $I) + { + // Setup Plugin and Resources. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + title: 'Kit: Page: Form Builder: Block: Form Enabled' + ); + + // Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg. + $I->configurePluginSidebarSettings( + $I, + form: 'None' + ); + + // Add block to Page. + $I->addGutenbergBlock( + $I, + blockName: 'Kit Form Builder', + blockProgrammaticName: 'convertkit-form-builder', + blockConfiguration: [ + 'form_id' => [ 'select', $_ENV['CONVERTKIT_API_FORM_SINGLE_OPTIN_NAME'] ], + ] + ); + + // Confirm the block template was used as the default. + $this->seeFormBuilderBlock($I); + $this->seeFormBuilderButtonBlock($I); + $this->seeFormBuilderField( + $I, + fieldType: 'text', + fieldName: 'first_name', + fieldID: 'first_name', + label: 'First name', + container: 'div[data-type="convertkit/form-builder"]' + ); + $this->seeFormBuilderField( + $I, + fieldType: 'email', + fieldName: 'email', + fieldID: 'email', + label: 'Email address', + container: 'div[data-type="convertkit/form-builder"]' + ); + + // Publish and view the Page on the frontend site. + $I->publishAndViewGutenbergPage($I); + + // Confirm that the Form is output in the DOM. + $this->seeFormBuilderField( + $I, + fieldType: 'text', + fieldName: 'first_name', + fieldID: 'first_name', + label: 'First name', + container: 'div.wp-block-convertkit-form-builder', + isFrontend: true + ); + $this->seeFormBuilderField( + $I, + fieldType: 'email', + fieldName: 'email', + fieldID: 'email', + label: 'Email address', + container: 'div.wp-block-convertkit-form-builder', + isFrontend: true + ); + + // Generate email address for this test. + $emailAddress = $I->generateEmailAddress(); + + // Submit form. + $I->fillField('input[name="convertkit[first_name]"]', 'First'); + $I->fillField('input[name="convertkit[email]"]', $emailAddress); + $I->click('div.wp-block-convertkit-form-builder button[type="submit"]'); + + // Confirm that the email address was added to Kit. + $I->waitForElementVisible('.convertkit-form-builder-subscribed-message'); + $I->wait(3); + $subscriber = $I->apiCheckSubscriberExists( + $I, + emailAddress: $emailAddress, + firstName: 'First' + ); + + // Confirm that the subscriber is active, as a form was used. + // This honors a Form's single optin setting. + $I->assertEquals('active', $subscriber['state']); + + // Confirm that the subscriber has the form. + $I->apiCheckSubscriberHasForm( + $I, + subscriberID: $subscriber['id'], + formID: $_ENV['CONVERTKIT_API_FORM_SINGLE_OPTIN_ID'], + referrer: $_ENV['WORDPRESS_URL'] . $I->grabFromCurrentUrl() + ); + } + + /** + * Test the Form Builder block works when added and that the subscriber's state + * is inactive when a double optin Form is specified. * * @since 3.0.4 * * @param EndToEndTester $I Tester. */ - public function testFormBuilderBlockWithFormEnabled(EndToEndTester $I) + public function testFormBuilderBlockWithDoubleOptinFormEnabled(EndToEndTester $I) { // Setup Plugin and Resources. $I->setupKitPlugin($I); diff --git a/tests/Support/Helper/KitPlugin.php b/tests/Support/Helper/KitPlugin.php index 665965896..6c5e136fb 100644 --- a/tests/Support/Helper/KitPlugin.php +++ b/tests/Support/Helper/KitPlugin.php @@ -222,6 +222,17 @@ public function setupKitPluginResources($I) $I->haveOptionInDatabase( 'convertkit_forms', [ + 3059218 => [ + 'id' => 3059218, + 'name' => 'Auto Confirm Form', + 'created_at' => '2022-03-07T15:57:51Z', + 'type' => 'embed', + 'format' => 'inline', + 'embed_js' => 'https://cheerful-architect-3237.kit.com/bfac9ed794/index.js', + 'embed_url' => 'https://cheerful-architect-3237.kit.com/bfac9ed794', + 'archived' => false, + 'uid' => 'bfac9ed794', + ], 2765143 => [ 'id' => 2765143, 'name' => 'Double Optin Form', From 62921accf5571d6fe3fa29a83e4fe0ab5bace94a Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Fri, 1 May 2026 11:49:13 +0800 Subject: [PATCH 9/9] Update test coverage for third party form integrations --- .../other/ContactForm7FormCest.php | 52 ++++++++- .../integrations/other/ForminatorCest.php | 103 +++++++++++++++++- .../integrations/wlm/WishListMemberCest.php | 48 +++++++- 3 files changed, 190 insertions(+), 13 deletions(-) diff --git a/tests/EndToEnd/integrations/other/ContactForm7FormCest.php b/tests/EndToEnd/integrations/other/ContactForm7FormCest.php index e88d79a08..be6192a66 100644 --- a/tests/EndToEnd/integrations/other/ContactForm7FormCest.php +++ b/tests/EndToEnd/integrations/other/ContactForm7FormCest.php @@ -42,13 +42,59 @@ public function testSettingsContactForm7WhenNoCredentials(EndToEndTester $I) } /** - * Test that saving a Contact Form 7 to Kit Form Mapping works. + * Test the Contact Form 7 Form integration works and that the subscriber's state is active + * when a single optin Form is specified. * - * @since 1.9.6 + * @since 3.3.2 + * + * @param EndToEndTester $I Tester. + */ + public function testSettingsContactForm7ToKitSingleOptinFormMapping(EndToEndTester $I) + { + // Setup Contact form 7 Form and configuration for this test. + $pageID = $this->_contactForm7SetupForm( + $I, + $_ENV['CONVERTKIT_API_FORM_SINGLE_OPTIN_NAME'] + ); + + // Define email address for this test. + $emailAddress = $I->generateEmailAddress(); + + // Complete and submit Contact Form 7 Form. + $this->_contactForm7CompleteAndSubmitForm( + $I, + pageID: $pageID, + emailAddress: $emailAddress + ); + + // Wait for the API to update. + $I->wait(2); + + // Confirm that the email address was added to Kit. + $subscriber = $I->apiCheckSubscriberExists($I, $emailAddress); + + // Confirm that the subscriber is active, as a form was used. + // This honors a Form's single optin setting. + $I->assertEquals('active', $subscriber['state']); + + // Check that the subscriber has the expected form and referrer value set. + $I->apiCheckSubscriberHasForm( + $I, + subscriberID: $subscriber['id'], + formID: $_ENV['CONVERTKIT_API_FORM_SINGLE_OPTIN_ID'], + referrer: $_ENV['WORDPRESS_URL'] . $I->grabFromCurrentUrl() + ); + } + + /** + * Test the Contact Form 7 Form integration works and that the subscriber's state is inactive + * when a double optin Form is specified. + * + * @since 3.3.2 * * @param EndToEndTester $I Tester. */ - public function testSettingsContactForm7ToKitFormMapping(EndToEndTester $I) + public function testSettingsContactForm7ToKitDoubleOptinFormMapping(EndToEndTester $I) { // Setup Contact form 7 Form and configuration for this test. $pageID = $this->_contactForm7SetupForm( diff --git a/tests/EndToEnd/integrations/other/ForminatorCest.php b/tests/EndToEnd/integrations/other/ForminatorCest.php index 2f928f021..007b9147c 100644 --- a/tests/EndToEnd/integrations/other/ForminatorCest.php +++ b/tests/EndToEnd/integrations/other/ForminatorCest.php @@ -42,13 +42,59 @@ public function testSettingsForminatorWhenNoCredentials(EndToEndTester $I) } /** - * Test that saving a Forminator Form to Kit Form Mapping works. + * Test the Forminator Form integration works and that the subscriber's state is active + * when a single optin Form is specified. * - * @since 2.3.0 + * @since 3.3.2 + * + * @param EndToEndTester $I Tester. + */ + public function testSettingsForminatorFormToKitSingleOptinFormMapping(EndToEndTester $I) + { + // Setup Forminator Form and configuration for this test. + $pageID = $this->_forminatorSetupForm( + $I, + $_ENV['CONVERTKIT_API_FORM_SINGLE_OPTIN_NAME'] + ); + + // Define email address for this test. + $emailAddress = $I->generateEmailAddress(); + + // Complete and submit Forminator Form. + $this->_forminatorCompleteAndSubmitForm( + $I, + pageID: $pageID, + emailAddress: $emailAddress + ); + + // Wait for the API to update. + $I->wait(2); + + // Confirm that the email address was added to Kit. + $subscriber = $I->apiCheckSubscriberExists($I, $emailAddress); + + // Confirm that the subscriber is active, as a form was used. + // This honors a Form's single optin setting. + $I->assertEquals('active', $subscriber['state']); + + // Check that the subscriber has the expected form and referrer value set. + $I->apiCheckSubscriberHasForm( + $I, + subscriberID: $subscriber['id'], + formID: $_ENV['CONVERTKIT_API_FORM_SINGLE_OPTIN_ID'], + referrer: $_ENV['WORDPRESS_URL'] . $I->grabFromCurrentUrl() + ); + } + + /** + * Test the Forminator Form integration works and that the subscriber's state is inactive + * when a double optin Form is specified. + * + * @since 3.3.2 * * @param EndToEndTester $I Tester. */ - public function testSettingsForminatorFormToKitFormMapping(EndToEndTester $I) + public function testSettingsForminatorFormToKitDoubleOptinFormMapping(EndToEndTester $I) { // Setup Forminator Form and configuration for this test. $pageID = $this->_forminatorSetupForm( @@ -250,13 +296,58 @@ public function testSettingsForminatorFormSubscribeOption(EndToEndTester $I) } /** - * Test that saving a Forminator Quiz to Kit Form Mapping works. + * Test the Forminator Quiz integration works and that the subscriber's state is active + * when a single optin Form is specified. * - * @since 2.4.3 + * @since 3.3.2 + * + * @param EndToEndTester $I Tester. + */ + public function testSettingsForminatorQuizToKitSingleOptinFormMapping(EndToEndTester $I) + { + // Setup Forminator Quiz and configuration for this test. + $pageID = $this->_forminatorSetupQuiz( + $I, + $_ENV['CONVERTKIT_API_FORM_SINGLE_OPTIN_NAME'] + ); + + // Define email address for this test. + $emailAddress = $I->generateEmailAddress(); + + // Complete and submit Forminator Quiz. + $this->_forminatorCompleteAndSubmitQuiz( + $I, + pageID: $pageID, + emailAddress: $emailAddress + ); + + // Wait for the API to update. + $I->wait(2); + + // Confirm that the email address was added to Kit. + $subscriber = $I->apiCheckSubscriberExists($I, $emailAddress); + + // Confirm that the subscriber is active, as a form was used. + // This honors a Form's double optin setting. + $I->assertEquals('active', $subscriber['state']); + + // Check that the subscriber has the expected form value set. + $I->apiCheckSubscriberHasForm( + $I, + subscriberID: $subscriber['id'], + formID: $_ENV['CONVERTKIT_API_FORM_SINGLE_OPTIN_ID'] + ); + } + + /** + * Test the Forminator Quiz integration works and that the subscriber's state is inactive + * when a double optin Form is specified. + * + * @since 3.3.2 * * @param EndToEndTester $I Tester. */ - public function testSettingsForminatorQuizToKitFormMapping(EndToEndTester $I) + public function testSettingsForminatorQuizToKitDoubleOptinFormMapping(EndToEndTester $I) { // Setup Forminator Quiz and configuration for this test. $pageID = $this->_forminatorSetupQuiz( diff --git a/tests/EndToEnd/integrations/wlm/WishListMemberCest.php b/tests/EndToEnd/integrations/wlm/WishListMemberCest.php index e36262f29..bac2f73ac 100644 --- a/tests/EndToEnd/integrations/wlm/WishListMemberCest.php +++ b/tests/EndToEnd/integrations/wlm/WishListMemberCest.php @@ -28,14 +28,54 @@ public function _before(EndToEndTester $I) } /** - * Test that WishList Member Level to Kit Form Mapping works, - * and the email address is added to Kit when assigned the WishList Member Level + * Test the WishList Member Level to Kit Double Optin works, and that the subscriber's state is active + * when a single optin Form is specified. * - * @since 1.9.6 + * @since 3.3.2 + * + * @param EndToEndTester $I Tester. + */ + public function testWLMToKitSingleOptinFormMappingOnLevelAdded(EndToEndTester $I) + { + // Get WishList Member Level ID defined. + $wlmLevelID = $this->_getWishListMemberLevelID($I); + + // Define email address for this test. + $emailAddress = $I->generateEmailAddress(); + + // Create a test WordPress User. + $userID = $this->_createUser($I, $emailAddress); + + // Configure mapping. + $this->_configureMapping($I, $wlmLevelID, 'add', $_ENV['CONVERTKIT_API_FORM_SINGLE_OPTIN_NAME']); + + // Assign level to user. + $this->_assignLevelToUser($I, $wlmLevelID, $userID); + + // Confirm that the email address was added to Kit. + $subscriber = $I->apiCheckSubscriberExists($I, $emailAddress); + + // Confirm that the subscriber is active, as a form was used. + // This honors a Form's single optin setting. + $I->assertEquals('active', $subscriber['state']); + + // Check that the subscriber has the expected form value set. + $I->apiCheckSubscriberHasForm( + $I, + subscriberID: $subscriber['id'], + formID: $_ENV['CONVERTKIT_API_FORM_SINGLE_OPTIN_ID'] + ); + } + + /** + * Test the WishList Member Level to Kit Double Optin works, and that the subscriber's state is inactive + * when a double optin Form is specified. + * + * @since 3.3.2 * * @param EndToEndTester $I Tester. */ - public function testWLMToKitFormMappingOnLevelAdded(EndToEndTester $I) + public function testWLMToKitDoubleOptinFormMappingOnLevelAdded(EndToEndTester $I) { // Get WishList Member Level ID defined. $wlmLevelID = $this->_getWishListMemberLevelID($I);