From 6f9bedbc2537f5c28353ea92a89aa8b3aea8365f Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 28 Oct 2024 11:26:23 +0800 Subject: [PATCH 1/5] Use `has_access_and_refresh_token`, not `has_api_key_and_secret` --- includes/class-convertkit-output.php | 4 ++-- includes/class-convertkit-settings.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/class-convertkit-output.php b/includes/class-convertkit-output.php index d937ac45..69cb16bb 100644 --- a/includes/class-convertkit-output.php +++ b/includes/class-convertkit-output.php @@ -112,8 +112,8 @@ public function maybe_tag_subscriber() { $this->settings = new ConvertKit_Settings(); } - // Bail if the API if an API Key and Secret is not defined. - if ( ! $this->settings->has_api_key_and_secret() ) { + // Bail if the API hasn't been configured. + if ( ! $this->settings->has_access_and_refresh_token() ) { return; } diff --git a/includes/class-convertkit-settings.php b/includes/class-convertkit-settings.php index 542b2ba5..73f5ed1a 100644 --- a/includes/class-convertkit-settings.php +++ b/includes/class-convertkit-settings.php @@ -162,7 +162,8 @@ public function is_api_secret_a_constant() { */ public function has_api_key_and_secret() { - return $this->has_api_key() && $this->has_api_secret(); + // Use check for access and refresh token. + return $this->has_access_and_refresh_token(); } From e9a4434a27ed8cd252c5eaa2c07ada261fc42269 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 28 Oct 2024 11:28:24 +0800 Subject: [PATCH 2/5] =?UTF-8?q?Tests:=20Don=E2=80=99t=20populate=20API=20K?= =?UTF-8?q?ey=20and=20Secret=20by=20default?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/_support/Helper/Acceptance/ConvertKitPlugin.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/_support/Helper/Acceptance/ConvertKitPlugin.php b/tests/_support/Helper/Acceptance/ConvertKitPlugin.php index c6d07a4e..dd14b75f 100644 --- a/tests/_support/Helper/Acceptance/ConvertKitPlugin.php +++ b/tests/_support/Helper/Acceptance/ConvertKitPlugin.php @@ -60,9 +60,6 @@ public function setupConvertKitPlugin($I, $options = false) { // Define default options. $defaults = [ - // API Key and Secret retained for testing Legacy Forms and Landing Pages. - 'api_key' => $_ENV['CONVERTKIT_API_KEY'], - 'api_secret' => $_ENV['CONVERTKIT_API_SECRET'], 'access_token' => $_ENV['CONVERTKIT_OAUTH_ACCESS_TOKEN'], 'refresh_token' => $_ENV['CONVERTKIT_OAUTH_REFRESH_TOKEN'], 'debug' => 'on', @@ -99,8 +96,6 @@ public function setupConvertKitPluginCredentialsNoData($I) $I->setupConvertKitPlugin( $I, [ - 'api_key' => $_ENV['CONVERTKIT_API_KEY_NO_DATA'], - 'api_secret' => $_ENV['CONVERTKIT_API_SECRET_NO_DATA'], 'access_token' => $_ENV['CONVERTKIT_OAUTH_ACCESS_TOKEN_NO_DATA'], 'refresh_token' => $_ENV['CONVERTKIT_OAUTH_REFRESH_TOKEN_NO_DATA'], 'post_form' => '', From b79209a22cfd44b005f29ad31a1fee5de38792e3 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 28 Oct 2024 11:37:20 +0800 Subject: [PATCH 3/5] Mark `has_api_key_and_secret` as deprecated --- includes/class-convertkit-settings.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/class-convertkit-settings.php b/includes/class-convertkit-settings.php index 73f5ed1a..70042d56 100644 --- a/includes/class-convertkit-settings.php +++ b/includes/class-convertkit-settings.php @@ -162,6 +162,8 @@ public function is_api_secret_a_constant() { */ public function has_api_key_and_secret() { + _deprecated_function( __FUNCTION__, '2.6.3', 'has_access_and_refresh_token()' ); + // Use check for access and refresh token. return $this->has_access_and_refresh_token(); From 6ddd5005ac479c013da47ede9be674a7fe4afb76 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 28 Oct 2024 13:23:17 +0800 Subject: [PATCH 4/5] Fixed tests for Legacy Forms to use API Key --- .../blocks-shortcodes/PageBlockFormCest.php | 13 ++++++-- .../PageShortcodeFormCest.php | 26 ++++++++++++--- .../forms/general/EditFormLinkCest.php | 9 +++++ .../forms/general/WidgetFormCest.php | 33 +++++++++++++++++++ .../forms/post-types/CPTFormCest.php | 6 +++- .../forms/post-types/PageFormCest.php | 15 ++++++--- .../forms/post-types/PostFormCest.php | 15 ++++++--- .../integrations/other/DiviFormCest.php | 13 ++++++-- .../integrations/other/ElementorFormCest.php | 12 +++++++ 9 files changed, 125 insertions(+), 17 deletions(-) diff --git a/tests/acceptance/forms/blocks-shortcodes/PageBlockFormCest.php b/tests/acceptance/forms/blocks-shortcodes/PageBlockFormCest.php index 592d8b84..9777a271 100644 --- a/tests/acceptance/forms/blocks-shortcodes/PageBlockFormCest.php +++ b/tests/acceptance/forms/blocks-shortcodes/PageBlockFormCest.php @@ -70,8 +70,17 @@ public function testFormBlockWithValidFormParameter(AcceptanceTester $I) */ public function testFormBlockWithValidLegacyFormParameter(AcceptanceTester $I) { - // Setup Plugin and Resources. - $I->setupConvertKitPlugin($I); + // Setup Plugin with API Key and Secret, which is required for Legacy Forms to work. + $I->setupConvertKitPlugin( + $I, + [ + 'api_key' => $_ENV['CONVERTKIT_API_KEY'], + 'api_secret' => $_ENV['CONVERTKIT_API_SECRET'], + 'post_form' => '', + 'page_form' => '', + 'product_form' => '', + ] + ); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. diff --git a/tests/acceptance/forms/blocks-shortcodes/PageShortcodeFormCest.php b/tests/acceptance/forms/blocks-shortcodes/PageShortcodeFormCest.php index 22a6ecb5..12c6ab39 100644 --- a/tests/acceptance/forms/blocks-shortcodes/PageShortcodeFormCest.php +++ b/tests/acceptance/forms/blocks-shortcodes/PageShortcodeFormCest.php @@ -261,8 +261,17 @@ public function testFormShortcodeWhenFormDoesNotExistInPluginFormResources(Accep */ public function testFormShortcodeWithValidLegacyFormParameter(AcceptanceTester $I) { - // Setup Plugin. - $I->setupConvertKitPluginNoDefaultForms($I); // Don't specify default forms. + // Setup Plugin with API Key and Secret, which is required for Legacy Forms to work. + $I->setupConvertKitPlugin( + $I, + [ + 'api_key' => $_ENV['CONVERTKIT_API_KEY'], + 'api_secret' => $_ENV['CONVERTKIT_API_SECRET'], + 'post_form' => '', + 'page_form' => '', + 'product_form' => '', + ] + ); $I->setupConvertKitPluginResources($I); // Create Page with Shortcode. @@ -325,8 +334,17 @@ public function testFormShortcodeWithValidLegacyIDParameter(AcceptanceTester $I) */ public function testFormShortcodeWithValidLegacyFormShortcodeFromConvertKitApp(AcceptanceTester $I) { - // Setup Plugin. - $I->setupConvertKitPluginNoDefaultForms($I); // Don't specify default forms. + // Setup Plugin with API Key and Secret, which is required for Legacy Forms to work. + $I->setupConvertKitPlugin( + $I, + [ + 'api_key' => $_ENV['CONVERTKIT_API_KEY'], + 'api_secret' => $_ENV['CONVERTKIT_API_SECRET'], + 'post_form' => '', + 'page_form' => '', + 'product_form' => '', + ] + ); $I->setupConvertKitPluginResources($I); // Create Page with Shortcode. diff --git a/tests/acceptance/forms/general/EditFormLinkCest.php b/tests/acceptance/forms/general/EditFormLinkCest.php index 2a6b3ae0..258ce12f 100644 --- a/tests/acceptance/forms/general/EditFormLinkCest.php +++ b/tests/acceptance/forms/general/EditFormLinkCest.php @@ -159,6 +159,15 @@ public function testEditFormLinkOnPageWithInvalidForm(AcceptanceTester $I) */ public function testEditFormLinkOnPageWithLegacyForm(AcceptanceTester $I) { + // Setup Plugin with API Key and Secret, which is required for Legacy Forms to work. + $I->setupConvertKitPlugin( + $I, + [ + 'api_key' => $_ENV['CONVERTKIT_API_KEY'], + 'api_secret' => $_ENV['CONVERTKIT_API_SECRET'], + ] + ); + // Add a Page using the Gutenberg editor. $I->addGutenbergPage($I, 'page', 'Kit: Page: Form: Legacy: Edit Link'); diff --git a/tests/acceptance/forms/general/WidgetFormCest.php b/tests/acceptance/forms/general/WidgetFormCest.php index cf2cd753..4533a62e 100644 --- a/tests/acceptance/forms/general/WidgetFormCest.php +++ b/tests/acceptance/forms/general/WidgetFormCest.php @@ -42,6 +42,17 @@ public function _before(AcceptanceTester $I) */ public function testLegacyFormWidgetWithValidFormParameter(AcceptanceTester $I) { + // Setup Plugin with API Key and Secret, which is required for Legacy Forms to work. + $I->setupConvertKitPlugin( + $I, + [ + 'api_key' => $_ENV['CONVERTKIT_API_KEY'], + 'api_secret' => $_ENV['CONVERTKIT_API_SECRET'], + 'page_form' => '', + 'post_form' => '', + ] + ); + // Add legacy widget, setting the Form setting to the value specified in the .env file. $I->addLegacyWidget( $I, @@ -69,6 +80,17 @@ public function testLegacyFormWidgetWithValidFormParameter(AcceptanceTester $I) */ public function testLegacyFormWidgetWithValidLegacyFormParameter(AcceptanceTester $I) { + // Setup Plugin with API Key and Secret, which is required for Legacy Forms to work. + $I->setupConvertKitPlugin( + $I, + [ + 'api_key' => $_ENV['CONVERTKIT_API_KEY'], + 'api_secret' => $_ENV['CONVERTKIT_API_SECRET'], + 'page_form' => '', + 'post_form' => '', + ] + ); + // Add legacy widget, setting the Form setting to the value specified in the .env file. $I->addLegacyWidget( $I, @@ -118,6 +140,17 @@ public function testBlockFormWidgetWithValidFormParameter(AcceptanceTester $I) */ public function testBlockFormBlockWithValidLegacyFormParameter(AcceptanceTester $I) { + // Setup Plugin with API Key and Secret, which is required for Legacy Forms to work. + $I->setupConvertKitPlugin( + $I, + [ + 'api_key' => $_ENV['CONVERTKIT_API_KEY'], + 'api_secret' => $_ENV['CONVERTKIT_API_SECRET'], + 'page_form' => '', + 'post_form' => '', + ] + ); + // Add block widget, setting the Form setting to the value specified in the .env file. $I->addBlockWidget( $I, diff --git a/tests/acceptance/forms/post-types/CPTFormCest.php b/tests/acceptance/forms/post-types/CPTFormCest.php index e246ab6e..ffcfb6fb 100644 --- a/tests/acceptance/forms/post-types/CPTFormCest.php +++ b/tests/acceptance/forms/post-types/CPTFormCest.php @@ -439,6 +439,8 @@ public function testAddNewCPTUsingDefaultLegacyForm(AcceptanceTester $I) $I->setupConvertKitPlugin( $I, [ + 'api_key' => $_ENV['CONVERTKIT_API_KEY'], + 'api_secret' => $_ENV['CONVERTKIT_API_SECRET'], 'article_form' => $_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], ] ); @@ -554,7 +556,9 @@ public function testAddNewCPTUsingDefinedLegacyForm(AcceptanceTester $I) $I->setupConvertKitPlugin( $I, [ - 'article_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'api_key' => $_ENV['CONVERTKIT_API_KEY'], + 'api_secret' => $_ENV['CONVERTKIT_API_SECRET'], + 'article_form' => '', ] ); $I->setupConvertKitPluginResources($I); diff --git a/tests/acceptance/forms/post-types/PageFormCest.php b/tests/acceptance/forms/post-types/PageFormCest.php index 6a3d8881..fbac66e1 100644 --- a/tests/acceptance/forms/post-types/PageFormCest.php +++ b/tests/acceptance/forms/post-types/PageFormCest.php @@ -327,9 +327,9 @@ public function testAddNewPageUsingDefaultLegacyForm(AcceptanceTester $I) $I->setupConvertKitPlugin( $I, [ - 'page_form' => $_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], - 'post_form' => '', - 'product_form' => '', + 'api_key' => $_ENV['CONVERTKIT_API_KEY'], + 'api_secret' => $_ENV['CONVERTKIT_API_SECRET'], + 'page_form' => $_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], ] ); $I->setupConvertKitPluginResources($I); @@ -714,7 +714,14 @@ public function testAddNewPageUsingModalFormWithWPRocketPlugin(AcceptanceTester public function testAddNewPageUsingDefinedLegacyForm(AcceptanceTester $I) { // Setup ConvertKit plugin. - $I->setupConvertKitPlugin($I); + $I->setupConvertKitPlugin( + $I, + [ + 'api_key' => $_ENV['CONVERTKIT_API_KEY'], + 'api_secret' => $_ENV['CONVERTKIT_API_SECRET'], + 'page_form' => '', + ] + ); $I->setupConvertKitPluginResources($I); // Add a Page using the Gutenberg editor. diff --git a/tests/acceptance/forms/post-types/PostFormCest.php b/tests/acceptance/forms/post-types/PostFormCest.php index ec1c76a4..e335f6e7 100644 --- a/tests/acceptance/forms/post-types/PostFormCest.php +++ b/tests/acceptance/forms/post-types/PostFormCest.php @@ -362,9 +362,9 @@ public function testAddNewPostUsingDefaultLegacyForm(AcceptanceTester $I) $I->setupConvertKitPlugin( $I, [ - 'page_form' => '', - 'post_form' => $_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], - 'product_form' => '', + 'api_key' => $_ENV['CONVERTKIT_API_KEY'], + 'api_secret' => $_ENV['CONVERTKIT_API_SECRET'], + 'post_form' => $_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], ] ); $I->setupConvertKitPluginResources($I); @@ -466,7 +466,14 @@ public function testAddNewPostUsingDefinedForm(AcceptanceTester $I) public function testAddNewPostUsingDefinedLegacyForm(AcceptanceTester $I) { // Setup ConvertKit Plugin. - $I->setupConvertKitPlugin($I); + $I->setupConvertKitPlugin( + $I, + [ + 'api_key' => $_ENV['CONVERTKIT_API_KEY'], + 'api_secret' => $_ENV['CONVERTKIT_API_SECRET'], + 'post_form' => '', + ] + ); $I->setupConvertKitPluginResources($I); // Add a Post using the Gutenberg editor. diff --git a/tests/acceptance/integrations/other/DiviFormCest.php b/tests/acceptance/integrations/other/DiviFormCest.php index 06d368df..41aa4e42 100644 --- a/tests/acceptance/integrations/other/DiviFormCest.php +++ b/tests/acceptance/integrations/other/DiviFormCest.php @@ -152,8 +152,17 @@ public function testFormModuleInFrontendEditorWhenNoForms(AcceptanceTester $I) */ public function testFormModuleWithValidLegacyFormParameter(AcceptanceTester $I) { - // Setup Plugin, without defining default Forms. - $I->setupConvertKitPluginNoDefaultForms($I); + // Setup Plugin with API Key and Secret, which is required for Legacy Forms to work. + $I->setupConvertKitPlugin( + $I, + [ + 'api_key' => $_ENV['CONVERTKIT_API_KEY'], + 'api_secret' => $_ENV['CONVERTKIT_API_SECRET'], + 'post_form' => '', + 'page_form' => '', + 'product_form' => '', + ] + ); $I->setupConvertKitPluginResources($I); // Create Page with Form module in Divi. diff --git a/tests/acceptance/integrations/other/ElementorFormCest.php b/tests/acceptance/integrations/other/ElementorFormCest.php index 3f04c467..e34349eb 100644 --- a/tests/acceptance/integrations/other/ElementorFormCest.php +++ b/tests/acceptance/integrations/other/ElementorFormCest.php @@ -78,6 +78,18 @@ public function testFormWidgetWithValidFormParameter(AcceptanceTester $I) */ public function testFormWidgetWithValidLegacyFormParameter(AcceptanceTester $I) { + // Setup Plugin with API Key and Secret, which is required for Legacy Forms to work. + $I->setupConvertKitPlugin( + $I, + [ + 'api_key' => $_ENV['CONVERTKIT_API_KEY'], + 'api_secret' => $_ENV['CONVERTKIT_API_SECRET'], + 'post_form' => '', + 'page_form' => '', + 'product_form' => '', + ] + ); + // Create Page with Form widget in Elementor. $pageID = $this->_createPageWithFormWidget($I, 'Kit: Legacy Form: Elementor Widget: Valid Form Param', $_ENV['CONVERTKIT_API_LEGACY_FORM_ID']); From 85429d9081712a448f124282adc5c9249fbecaa2 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Mon, 28 Oct 2024 13:28:42 +0800 Subject: [PATCH 5/5] Fixed test comments --- tests/acceptance/forms/post-types/CPTFormCest.php | 4 ++-- tests/acceptance/forms/post-types/PageFormCest.php | 4 ++-- tests/acceptance/forms/post-types/PostFormCest.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/acceptance/forms/post-types/CPTFormCest.php b/tests/acceptance/forms/post-types/CPTFormCest.php index ffcfb6fb..59904c29 100644 --- a/tests/acceptance/forms/post-types/CPTFormCest.php +++ b/tests/acceptance/forms/post-types/CPTFormCest.php @@ -435,7 +435,7 @@ public function testAddNewCPTUsingDefaultFormAfterOutOfBoundsElement(AcceptanceT */ public function testAddNewCPTUsingDefaultLegacyForm(AcceptanceTester $I) { - // Setup Plugin, without defining default Forms. + // Setup Plugin with API Key and Secret, which is required for Legacy Forms to work. $I->setupConvertKitPlugin( $I, [ @@ -552,7 +552,7 @@ public function testAddNewCPTUsingDefinedForm(AcceptanceTester $I) */ public function testAddNewCPTUsingDefinedLegacyForm(AcceptanceTester $I) { - // Setup ConvertKit Plugin. + // Setup Plugin with API Key and Secret, which is required for Legacy Forms to work. $I->setupConvertKitPlugin( $I, [ diff --git a/tests/acceptance/forms/post-types/PageFormCest.php b/tests/acceptance/forms/post-types/PageFormCest.php index fbac66e1..a0ade86f 100644 --- a/tests/acceptance/forms/post-types/PageFormCest.php +++ b/tests/acceptance/forms/post-types/PageFormCest.php @@ -323,7 +323,7 @@ public function testAddNewPageUsingDefaultFormAfterOutOfBoundsElement(Acceptance */ public function testAddNewPageUsingDefaultLegacyForm(AcceptanceTester $I) { - // Setup ConvertKit plugin to use legacy Form as default for Pages. + // Setup Plugin with API Key and Secret, which is required for Legacy Forms to work. $I->setupConvertKitPlugin( $I, [ @@ -713,7 +713,7 @@ public function testAddNewPageUsingModalFormWithWPRocketPlugin(AcceptanceTester */ public function testAddNewPageUsingDefinedLegacyForm(AcceptanceTester $I) { - // Setup ConvertKit plugin. + // Setup Plugin with API Key and Secret, which is required for Legacy Forms to work. $I->setupConvertKitPlugin( $I, [ diff --git a/tests/acceptance/forms/post-types/PostFormCest.php b/tests/acceptance/forms/post-types/PostFormCest.php index e335f6e7..bb450c65 100644 --- a/tests/acceptance/forms/post-types/PostFormCest.php +++ b/tests/acceptance/forms/post-types/PostFormCest.php @@ -358,7 +358,7 @@ public function testAddNewPostUsingDefaultFormAfterOutOfBoundsElement(Acceptance */ public function testAddNewPostUsingDefaultLegacyForm(AcceptanceTester $I) { - // Setup Plugin, without defining default Forms. + // Setup Plugin with API Key and Secret, which is required for Legacy Forms to work. $I->setupConvertKitPlugin( $I, [ @@ -465,7 +465,7 @@ public function testAddNewPostUsingDefinedForm(AcceptanceTester $I) */ public function testAddNewPostUsingDefinedLegacyForm(AcceptanceTester $I) { - // Setup ConvertKit Plugin. + // Setup Plugin with API Key and Secret, which is required for Legacy Forms to work. $I->setupConvertKitPlugin( $I, [