diff --git a/admin/section/class-convertkit-settings-general.php b/admin/section/class-convertkit-settings-general.php index 16fe8259..b83f2491 100644 --- a/admin/section/class-convertkit-settings-general.php +++ b/admin/section/class-convertkit-settings-general.php @@ -610,7 +610,12 @@ 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' ), + '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' ), ), 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 e85849c7..21818b9d 100644 --- a/tests/_support/Helper/Acceptance/ConvertKitForms.php +++ b/tests/_support/Helper/Acceptance/ConvertKitForms.php @@ -50,7 +50,17 @@ public function seeFormOutput($I, $formID, $position = false, $element = false, break; case 'after_element': - $I->seeInSource('<' . $element . '>Item #' . $element_index . '
seeInSource('<' . $element . '>Item #' . $element_index . 'seeInSource('<' . $element . ' class="wp-block-heading">Item #' . $element_index . 'grabAttributeFrom('.post-publish-panel__postpublish-buttons a.components-button', 'href'); } + + /** + * Add a Page, Post or Custom Post Type directly to the WordPress database, + * with dummy content used for testing. + * + * @since 2.6.2 + * + * @param AcceptanceTester $I Acceptance Tester. + * @param string $postType Post Type. + * @param string $title Post Title. + * @param string $formID Meta Box `Form` value (-1: Default). + */ + public function addGutenbergPageToDatabase($I, $postType = 'page', $title = 'Gutenberg Title', $formID = '-1') + { + return $I->havePostInDatabase( + [ + 'post_title' => $title, + 'post_type' => $postType, + 'post_status' => 'publish', + 'meta_input' => [ + '_wp_convertkit_post_meta' => [ + 'form' => $formID, + 'landing_page' => '', + 'tag' => '', + ], + ], + 'post_content' => ' +
+
+

Item #1

+ + + +

Item #1

+ + + +

Item #2

+
+ + + +
+
Flowers
+
+
+ + + +

Item #2

+ + + +

Item #3

+ + + +
MacBook Pro beside plant in vase
+ + + +
+
+

Item #1

+ + + +

Item #4

+
+ + + +
+

Item #1

+ + + +

Item #5

+
+
+ + + +
Item #1
+ + + +

Item #6

+ + + +
Item #1
+ + + +

Item #7

+ + + +

Item #2

+ + + +

Item #2

+ + + +
Item #2
+ + + +
Item #2
+', + ] + ); + } } diff --git a/tests/acceptance/forms/post-types/CPTFormCest.php b/tests/acceptance/forms/post-types/CPTFormCest.php index 3e8ffe6a..faa56bbe 100644 --- a/tests/acceptance/forms/post-types/CPTFormCest.php +++ b/tests/acceptance/forms/post-types/CPTFormCest.php @@ -289,7 +289,7 @@ public function testAddNewCPTUsingDefaultFormBeforeAndAfterContent(AcceptanceTes * * @param AcceptanceTester $I Tester. */ - public function testAddNewCPTUsingDefaultFormAfterElement(AcceptanceTester $I) + public function testAddNewCPTUsingDefaultFormAfterParagraphElement(AcceptanceTester $I) { // Setup ConvertKit plugin with Default Form for CPTs set to be output after the 3rd paragraph of content. $I->setupConvertKitPlugin( @@ -303,30 +303,53 @@ public function testAddNewCPTUsingDefaultFormAfterElement(AcceptanceTester $I) ); $I->setupConvertKitPluginResources($I); - // Add a CPT using the Gutenberg editor. - $I->addGutenbergPage($I, 'article', 'Kit: CPT: Form: Default: After 3rd Paragraph Element'); + // Setup Article with placeholder content. + $pageID = $I->addGutenbergPageToDatabase($I, 'article', 'Kit: CPT: Form: Default: After 3rd Paragraph Element'); - // Add 5 paragraphs to CPT. - $I->addGutenbergParagraphBlock($I, 'Item #1'); - $I->addGutenbergParagraphBlock($I, 'Item #2'); - $I->addGutenbergParagraphBlock($I, 'Item #3'); - $I->addGutenbergParagraphBlock($I, 'Item #4'); - $I->addGutenbergParagraphBlock($I, 'Item #5'); + // View the CPT on the frontend site. + $I->amOnPage('?p=' . $pageID); - // Configure metabox's Form setting = Default. - $I->configureMetaboxSettings( + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that one ConvertKit Form is output in the DOM after the third paragraph. + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_ID'], 'after_element', 'p', 3); + } + + /** + * Test that the Default Form specified in the Plugin Settings works when + * creating and viewing a new WordPress CPT, and its position is set + * to after the 2nd

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

of content. + $I->setupConvertKitPlugin( $I, - 'wp-convertkit-meta-box', [ - 'form' => [ 'select2', 'Default' ], + 'article_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'article_form_position' => 'after_element', + 'article_form_position_element' => 'h2', + 'article_form_position_element_index' => 2, ] ); + $I->setupConvertKitPluginResources($I); - // Publish and view the CPT on the frontend site. - $I->publishAndViewGutenbergPage($I); + // Setup Article with placeholder content. + $pageID = $I->addGutenbergPageToDatabase($I, 'article', 'Kit: CPT: Form: Default: After 2nd H2 Element'); - // Confirm that one ConvertKit Form is output in the DOM after the third paragraph. - $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_ID'], 'after_element', 'p', 3); + // 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', 'h2', 2); } /** @@ -347,30 +370,19 @@ public function testAddNewCPTUsingDefaultFormAfterOutOfBoundsElement(AcceptanceT 'article_form' => $_ENV['CONVERTKIT_API_FORM_ID'], 'article_form_position' => 'after_element', 'article_form_position_element' => 'p', - 'article_form_position_element_index' => 7, + 'article_form_position_element_index' => 9, ] ); $I->setupConvertKitPluginResources($I); - // Add a CPT using the Gutenberg editor. - $I->addGutenbergPage($I, 'article', 'Kit: CPT: Form: Default: After 7th Paragraph Element'); + // Setup Article with placeholder content. + $pageID = $I->addGutenbergPageToDatabase($I, 'article', 'Kit: CPT: Form: Default: After 9th Paragraph Element'); - // Add 5 paragraphs to CPT. - $I->addGutenbergParagraphBlock($I, 'Item #1'); - $I->addGutenbergParagraphBlock($I, 'Item #2'); - $I->addGutenbergParagraphBlock($I, 'Item #3'); + // View the CPT on the frontend site. + $I->amOnPage('?p=' . $pageID); - // Configure metabox's Form setting = Default. - $I->configureMetaboxSettings( - $I, - 'wp-convertkit-meta-box', - [ - 'form' => [ 'select2', 'Default' ], - ] - ); - - // Publish and view the CPT on the frontend site. - $I->publishAndViewGutenbergPage($I); + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); // Confirm that one ConvertKit Form is output in the DOM after the content, as // the number of paragraphs is less than the position. diff --git a/tests/acceptance/forms/post-types/PageFormCest.php b/tests/acceptance/forms/post-types/PageFormCest.php index 9a7b0f95..596c0a84 100644 --- a/tests/acceptance/forms/post-types/PageFormCest.php +++ b/tests/acceptance/forms/post-types/PageFormCest.php @@ -213,7 +213,7 @@ public function testAddNewPageUsingDefaultFormBeforeAndAfterContent(AcceptanceTe * * @param AcceptanceTester $I Tester. */ - public function testAddNewPageUsingDefaultFormAfterElement(AcceptanceTester $I) + public function testAddNewPageUsingDefaultFormAfterParagraphElement(AcceptanceTester $I) { // Setup ConvertKit plugin with Default Form for Pages set to be output after the 3rd paragraph of content. $I->setupConvertKitPlugin( @@ -227,30 +227,53 @@ public function testAddNewPageUsingDefaultFormAfterElement(AcceptanceTester $I) ); $I->setupConvertKitPluginResources($I); - // Add a Page using the Gutenberg editor. - $I->addGutenbergPage($I, 'page', 'Kit: Page: Form: Default: After 3rd Paragraph Element'); + // Setup Page with placeholder content. + $pageID = $I->addGutenbergPageToDatabase($I, 'page', 'Kit: Page: Form: Default: After 3rd Paragraph Element'); - // Add 5 paragraphs to Page. - $I->addGutenbergParagraphBlock($I, 'Item #1'); - $I->addGutenbergParagraphBlock($I, 'Item #2'); - $I->addGutenbergParagraphBlock($I, 'Item #3'); - $I->addGutenbergParagraphBlock($I, 'Item #4'); - $I->addGutenbergParagraphBlock($I, 'Item #5'); + // View the Page on the frontend site. + $I->amOnPage('?p=' . $pageID); - // Configure metabox's Form setting = Default. - $I->configureMetaboxSettings( + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that one ConvertKit Form is output in the DOM after the third paragraph. + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_ID'], 'after_element', 'p', 3); + } + + /** + * 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. + * + * @since 2.6.2 + * + * @param AcceptanceTester $I Tester. + */ + public function testAddNewPageUsingDefaultFormAfterHeadingElement(AcceptanceTester $I) + { + // Setup ConvertKit plugin with Default Form for Posts set to be output after the 2nd

of content. + $I->setupConvertKitPlugin( $I, - 'wp-convertkit-meta-box', [ - 'form' => [ 'select2', 'Default' ], + 'page_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'page_form_position' => 'after_element', + 'page_form_position_element' => 'h2', + 'page_form_position_element_index' => 2, ] ); + $I->setupConvertKitPluginResources($I); - // Publish and view the Page on the frontend site. - $I->publishAndViewGutenbergPage($I); + // Setup Page with placeholder content. + $pageID = $I->addGutenbergPageToDatabase($I, 'page', 'Kit: Page: Form: Default: After 2nd H2 Element'); - // Confirm that one ConvertKit Form is output in the DOM after the third paragraph. - $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_ID'], 'after_element', 'p', 3); + // 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', 'h2', 2); } /** @@ -271,30 +294,19 @@ public function testAddNewPageUsingDefaultFormAfterOutOfBoundsElement(Acceptance 'page_form' => $_ENV['CONVERTKIT_API_FORM_ID'], 'page_form_position' => 'after_element', 'page_form_position_element' => 'p', - 'page_form_position_element_index' => 7, + 'page_form_position_element_index' => 9, ] ); $I->setupConvertKitPluginResources($I); - // Add a Page using the Gutenberg editor. - $I->addGutenbergPage($I, 'page', 'Kit: Page: Form: Default: After 7th Paragraph Element'); + // Setup Page with placeholder content. + $pageID = $I->addGutenbergPageToDatabase($I, 'page', 'Kit: Page: Form: Default: After 9th Paragraph Element'); - // Add 5 paragraphs to Page. - $I->addGutenbergParagraphBlock($I, 'Item #1'); - $I->addGutenbergParagraphBlock($I, 'Item #2'); - $I->addGutenbergParagraphBlock($I, 'Item #3'); + // View the Page on the frontend site. + $I->amOnPage('?p=' . $pageID); - // Configure metabox's Form setting = Default. - $I->configureMetaboxSettings( - $I, - 'wp-convertkit-meta-box', - [ - 'form' => [ 'select2', 'Default' ], - ] - ); - - // Publish and view the Page on the frontend site. - $I->publishAndViewGutenbergPage($I); + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); // Confirm that one ConvertKit Form is output in the DOM after the content, as // the number of paragraphs is less than the position. diff --git a/tests/acceptance/forms/post-types/PostFormCest.php b/tests/acceptance/forms/post-types/PostFormCest.php index 98939dcc..7d34bfd8 100644 --- a/tests/acceptance/forms/post-types/PostFormCest.php +++ b/tests/acceptance/forms/post-types/PostFormCest.php @@ -212,7 +212,7 @@ public function testAddNewPostUsingDefaultFormBeforeAndAfterContent(AcceptanceTe * * @param AcceptanceTester $I Tester. */ - public function testAddNewPostUsingDefaultFormAfterElement(AcceptanceTester $I) + public function testAddNewPostUsingDefaultFormAfterParagraphElement(AcceptanceTester $I) { // Setup ConvertKit plugin with Default Form for Posts set to be output after the 3rd paragraph of content. $I->setupConvertKitPlugin( @@ -226,30 +226,53 @@ public function testAddNewPostUsingDefaultFormAfterElement(AcceptanceTester $I) ); $I->setupConvertKitPluginResources($I); - // Add a Post using the Gutenberg editor. - $I->addGutenbergPage($I, 'post', 'Kit: Post: Form: Default: After 3rd Paragraph Element'); + // Setup Post with placeholder content. + $pageID = $I->addGutenbergPageToDatabase($I, 'post', 'Kit: Post: Form: Default: After 3rd Paragraph Element'); - // Add 5 paragraphs to Post. - $I->addGutenbergParagraphBlock($I, 'Item #1'); - $I->addGutenbergParagraphBlock($I, 'Item #2'); - $I->addGutenbergParagraphBlock($I, 'Item #3'); - $I->addGutenbergParagraphBlock($I, 'Item #4'); - $I->addGutenbergParagraphBlock($I, 'Item #5'); + // View the Post on the frontend site. + $I->amOnPage('?p=' . $pageID); - // Configure metabox's Form setting = Default. - $I->configureMetaboxSettings( + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that one ConvertKit Form is output in the DOM after the third paragraph. + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_ID'], 'after_element', 'p', 3); + } + + /** + * 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 testAddNewPostUsingDefaultFormAfterHeadingElement(AcceptanceTester $I) + { + // Setup ConvertKit plugin with Default Form for Posts set to be output after the 2nd

of content. + $I->setupConvertKitPlugin( $I, - 'wp-convertkit-meta-box', [ - 'form' => [ 'select2', 'Default' ], + 'post_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'post_form_position' => 'after_element', + 'post_form_position_element' => 'h2', + 'post_form_position_element_index' => 2, ] ); + $I->setupConvertKitPluginResources($I); - // Publish and view the Post on the frontend site. - $I->publishAndViewGutenbergPage($I); + // Setup Post with placeholder content. + $pageID = $I->addGutenbergPageToDatabase($I, 'post', 'Kit: Post: Form: Default: After 2nd H2 Element'); - // Confirm that one ConvertKit Form is output in the DOM after the third paragraph. - $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_ID'], 'after_element', 'p', 3); + // 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', 'h2', 2); } /** @@ -270,30 +293,19 @@ public function testAddNewPostUsingDefaultFormAfterOutOfBoundsElement(Acceptance 'post_form' => $_ENV['CONVERTKIT_API_FORM_ID'], 'post_form_position' => 'after_element', 'post_form_position_element' => 'p', - 'post_form_position_element_index' => 7, + 'post_form_position_element_index' => 9, ] ); $I->setupConvertKitPluginResources($I); - // Add a Post using the Gutenberg editor. - $I->addGutenbergPage($I, 'post', 'Kit: Post: Form: Default: After 7th Paragraph Element'); + // Setup Post with placeholder content. + $pageID = $I->addGutenbergPageToDatabase($I, 'post', 'Kit: Post: Form: Default: After 9th Paragraph Element'); - // Add 5 paragraphs to Post. - $I->addGutenbergParagraphBlock($I, 'Item #1'); - $I->addGutenbergParagraphBlock($I, 'Item #2'); - $I->addGutenbergParagraphBlock($I, 'Item #3'); + // View the Post on the frontend site. + $I->amOnPage('?p=' . $pageID); - // Configure metabox's Form setting = Default. - $I->configureMetaboxSettings( - $I, - 'wp-convertkit-meta-box', - [ - 'form' => [ 'select2', 'Default' ], - ] - ); - - // Publish and view the Post on the frontend site. - $I->publishAndViewGutenbergPage($I); + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); // Confirm that one ConvertKit Form is output in the DOM after the content, as // the number of paragraphs is less than the position.