From 7b674f43aef5030607f2ab026fd461c080ceed35 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 17 Oct 2024 16:34:08 +0800 Subject: [PATCH] Added support for positioning form after images --- .../class-convertkit-settings-general.php | 13 +++---- .../Helper/Acceptance/ConvertKitForms.php | 4 +++ .../Helper/Acceptance/WPGutenberg.php | 4 +-- .../forms/post-types/CPTFormCest.php | 36 +++++++++++++++++++ .../forms/post-types/PageFormCest.php | 12 +++---- .../forms/post-types/PostFormCest.php | 36 +++++++++++++++++++ 6 files changed, 91 insertions(+), 14 deletions(-) diff --git a/admin/section/class-convertkit-settings-general.php b/admin/section/class-convertkit-settings-general.php index b83f2491..ce7076e6 100644 --- a/admin/section/class-convertkit-settings-general.php +++ b/admin/section/class-convertkit-settings-general.php @@ -610,12 +610,13 @@ public function default_form_position_element_callback( $args ) { $args['post_type'] . '_form_position_element', esc_attr( $this->settings->get_default_form_position_element( $args['post_type'] ) ), array( - 'p' => esc_html__( 'Paragraphs', 'convertkit' ), - 'h2' => esc_html__( 'Headings

', 'convertkit' ), - 'h3' => esc_html__( 'Headings

', 'convertkit' ), - 'h4' => esc_html__( 'Headings

', 'convertkit' ), - 'h5' => esc_html__( 'Headings

', 'convertkit' ), - 'h6' => esc_html__( 'Headings
', 'convertkit' ), + 'p' => esc_html__( 'Paragraphs', 'convertkit' ), + 'h2' => esc_html__( 'Headings

', 'convertkit' ), + 'h3' => esc_html__( 'Headings

', 'convertkit' ), + 'h4' => esc_html__( 'Headings

', 'convertkit' ), + 'h5' => esc_html__( 'Headings

', 'convertkit' ), + 'h6' => esc_html__( 'Headings
', 'convertkit' ), + 'img' => esc_html__( 'Images', 'convertkit' ), ), esc_html__( 'The number of elements before outputting the form.', 'convertkit' ), array( 'after_element' ) diff --git a/tests/_support/Helper/Acceptance/ConvertKitForms.php b/tests/_support/Helper/Acceptance/ConvertKitForms.php index 21818b9d..403c683c 100644 --- a/tests/_support/Helper/Acceptance/ConvertKitForms.php +++ b/tests/_support/Helper/Acceptance/ConvertKitForms.php @@ -56,6 +56,10 @@ public function seeFormOutput($I, $formID, $position = false, $element = false, $I->seeInSource('<' . $element . '>Item #' . $element_index . '
seeInSource('<' . $element . ' decoding="async" src="https://placehold.co/600x400" alt="Image #' . $element_index . '">seeInSource('<' . $element . ' class="wp-block-heading">Item #' . $element_index . ' element. + * + * @since 2.6.2 + * + * @param AcceptanceTester $I Tester. + */ + public function testAddNewCPTUsingDefaultFormAfterImageElement(AcceptanceTester $I) + { + // Setup ConvertKit plugin with Default Form for CPTs set to be output after the 2nd of content. + $I->setupConvertKitPlugin( + $I, + [ + 'article_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'article_form_position' => 'after_element', + 'article_form_position_element' => 'img', + 'article_form_position_element_index' => 2, + ] + ); + $I->setupConvertKitPluginResources($I); + + // Setup Article with placeholder content. + $pageID = $I->addGutenbergPageToDatabase($I, 'article', 'Kit: CPT: Form: Default: After 2nd Image Element'); + + // View the CPT on the frontend site. + $I->amOnPage('?p=' . $pageID); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that one ConvertKit Form is output in the DOM after the second element. + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_ID'], 'after_element', 'img', 2); + } + /** * Test that the Default Form specified in the Plugin Settings works when * creating and viewing a new WordPress CPT, and its position is set diff --git a/tests/acceptance/forms/post-types/PageFormCest.php b/tests/acceptance/forms/post-types/PageFormCest.php index 596c0a84..6a3d8881 100644 --- a/tests/acceptance/forms/post-types/PageFormCest.php +++ b/tests/acceptance/forms/post-types/PageFormCest.php @@ -243,21 +243,21 @@ public function testAddNewPageUsingDefaultFormAfterParagraphElement(AcceptanceTe /** * Test that the Default Form specified in the Plugin Settings works when * creating and viewing a new WordPress Page, and its position is set - * to after the 2nd

element. + * to after the 2nd element. * * @since 2.6.2 * * @param AcceptanceTester $I Tester. */ - public function testAddNewPageUsingDefaultFormAfterHeadingElement(AcceptanceTester $I) + public function testAddNewPageUsingDefaultFormAfterImageElement(AcceptanceTester $I) { - // Setup ConvertKit plugin with Default Form for Posts set to be output after the 2nd

of content. + // Setup ConvertKit plugin with Default Form for Posts set to be output after the 2nd of content. $I->setupConvertKitPlugin( $I, [ 'page_form' => $_ENV['CONVERTKIT_API_FORM_ID'], 'page_form_position' => 'after_element', - 'page_form_position_element' => 'h2', + 'page_form_position_element' => 'img', 'page_form_position_element_index' => 2, ] ); @@ -272,8 +272,8 @@ public function testAddNewPageUsingDefaultFormAfterHeadingElement(AcceptanceTest // Check that no PHP warnings or notices were output. $I->checkNoWarningsAndNoticesOnScreen($I); - // Confirm that one ConvertKit Form is output in the DOM after the second

element. - $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_ID'], 'after_element', 'h2', 2); + // Confirm that one ConvertKit Form is output in the DOM after the second element. + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_ID'], 'after_element', 'img', 2); } /** diff --git a/tests/acceptance/forms/post-types/PostFormCest.php b/tests/acceptance/forms/post-types/PostFormCest.php index 7d34bfd8..ec1c76a4 100644 --- a/tests/acceptance/forms/post-types/PostFormCest.php +++ b/tests/acceptance/forms/post-types/PostFormCest.php @@ -275,6 +275,42 @@ public function testAddNewPostUsingDefaultFormAfterHeadingElement(AcceptanceTest $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_ID'], 'after_element', 'h2', 2); } + /** + * Test that the Default Form specified in the Plugin Settings works when + * creating and viewing a new WordPress Post, and its position is set + * to after the 2nd element. + * + * @since 2.6.2 + * + * @param AcceptanceTester $I Tester. + */ + public function testAddNewPostUsingDefaultFormAfterImageElement(AcceptanceTester $I) + { + // Setup ConvertKit plugin with Default Form for Posts set to be output after the 2nd of content. + $I->setupConvertKitPlugin( + $I, + [ + 'post_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'post_form_position' => 'after_element', + 'post_form_position_element' => 'img', + 'post_form_position_element_index' => 2, + ] + ); + $I->setupConvertKitPluginResources($I); + + // Setup Post with placeholder content. + $pageID = $I->addGutenbergPageToDatabase($I, 'post', 'Kit: Post: Form: Default: After 2nd Image Element'); + + // View the Post on the frontend site. + $I->amOnPage('?p=' . $pageID); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that one ConvertKit Form is output in the DOM after the second element. + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_ID'], 'after_element', 'img', 2); + } + /** * Test that the Default Form specified in the Plugin Settings works when * creating and viewing a new WordPress Post, and its position is set