From cb76508b8fb36f1012fd5ee644f361d70d39dcdc Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 30 Apr 2026 14:47:23 +0800 Subject: [PATCH 1/2] 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 7cbf0ab04b225d7b2451840c6118195eeb1cd262 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 30 Apr 2026 14:59:36 +0800 Subject: [PATCH 2/2] 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"