From 3bfc54e9d70ecdaf09847787c143bb4511d30dad Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Wed, 11 Mar 2026 16:43:45 +0800 Subject: [PATCH 01/18] Tests: Block Editor: Register Post Settings --- tests/Support/Helper/WPGutenberg.php | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/Support/Helper/WPGutenberg.php b/tests/Support/Helper/WPGutenberg.php index e1ae82bf1..fe6017de3 100644 --- a/tests/Support/Helper/WPGutenberg.php +++ b/tests/Support/Helper/WPGutenberg.php @@ -611,6 +611,52 @@ function($I) { return $I->grabAttributeFrom('.post-publish-panel__postpublish-buttons a.components-button', 'href'); } + /** + * Configure the settings for the Plugin sidebar in Gutenberg. + * + * @since 3.2.2 + * + * @param EndToEndTester $I EndToEnd Tester. + * @param string $form Form ID. + * @param string $landingPage Landing Page ID. + * @param string $tag Tag ID. + * @param string $restrictContent Restrict Content ID. + */ + public function configurePluginSidebarSettings($I, $form = false, $landingPage = false, $tag = false, $restrictContent = false) + { + // Click the Plugin sidebar button. + $I->waitForElementVisible('button[aria-controls="convertkit-post-settings:post-settings"]'); + $I->click('button[aria-controls="convertkit-post-settings:post-settings"]'); + + // Wait for the Plugin sidebar to be fully loaded. + $I->waitForElementVisible('.editor-sidebar'); + + // Gutenberg doesn't expose the field names as IDs, so we need to use the index. + // Form. + if ( $form ) { + $I->waitForElementVisible('.editor-sidebar #inspector-select-control-0'); + $I->selectOption('.editor-sidebar #inspector-select-control-0', $form); + } + + // Landing Page. + if ( $landingPage ) { + $I->selectOption('#convertkit-post-settings:post-settings #inspector-select-control-1', $landingPage); + } + + // Tag. + if ( $tag ) { + $I->selectOption('#convertkit-post-settings:post-settings #inspector-select-control-2', $tag); + } + + // Restrict Content. + if ( $restrictContent ) { + $I->selectOption('#convertkit-post-settings:post-settings #inspector-select-control-3', $restrictContent); + } + + // Close the Plugin sidebar by opening the Page sidebar. + $I->click('.interface-pinned-items button[aria-label="Settings"]'); + } + /** * Add a Page, Post or Custom Post Type directly to the WordPress database, * with dummy content used for testing. From ccf4d3e2b3b2dcb78e8f643090e423ebe9a96f03 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Wed, 11 Mar 2026 16:43:53 +0800 Subject: [PATCH 02/18] Tests: Page Form --- .../forms/post-types/PageFormCest.php | 137 ++++++------------ 1 file changed, 46 insertions(+), 91 deletions(-) diff --git a/tests/EndToEnd/forms/post-types/PageFormCest.php b/tests/EndToEnd/forms/post-types/PageFormCest.php index 7d58b1884..a75e66c1b 100644 --- a/tests/EndToEnd/forms/post-types/PageFormCest.php +++ b/tests/EndToEnd/forms/post-types/PageFormCest.php @@ -70,20 +70,17 @@ public function testAddNewPageUsingDefaultFormWithNoDefaultFormSpecifiedInPlugin // Check the order of the Form resources are alphabetical, with the Default and None options prepending the Forms. $I->checkSelectFormOptionOrder( $I, - selectElement: '#wp-convertkit-form', + selectElement: '.editor-sidebar #inspector-select-control-0', prependOptions: [ 'Default', 'None', ] ); - // Configure metabox's Form setting = Default. - $I->configureMetaboxSettings( + // Configure Plugin Sidebar's Form setting = Default. + $I->configurePluginSidebarSettings( $I, - metabox: 'wp-convertkit-meta-box', - configuration: [ - 'form' => [ 'select2', 'Default' ], - ] + form: 'Default' ); // Publish and view the Page on the frontend site. @@ -113,13 +110,10 @@ public function testAddNewPageUsingDefaultForm(EndToEndTester $I) title: 'Kit: Page: Form: Default' ); - // Configure metabox's Form setting = Default. - $I->configureMetaboxSettings( + // Configure Plugin Sidebar's Form setting = Default. + $I->configurePluginSidebarSettings( $I, - metabox: 'wp-convertkit-meta-box', - configuration: [ - 'form' => [ 'select2', 'Default' ], - ] + form: 'Default' ); // Publish and view the Page on the frontend site. @@ -159,13 +153,10 @@ public function testAddNewPageUsingDefaultFormBeforeContent(EndToEndTester $I) // Add paragraph to Page. $I->addGutenbergParagraphBlock($I, 'Page content'); - // Configure metabox's Form setting = Default. - $I->configureMetaboxSettings( + // Configure Plugin Sidebar's Form setting = Default. + $I->configurePluginSidebarSettings( $I, - metabox: 'wp-convertkit-meta-box', - configuration: [ - 'form' => [ 'select2', 'Default' ], - ] + form: 'Default' ); // Publish and view the Page on the frontend site. @@ -209,13 +200,10 @@ public function testAddNewPageUsingDefaultFormBeforeAndAfterContent(EndToEndTest // Add paragraph to Page. $I->addGutenbergParagraphBlock($I, 'Page content'); - // Configure metabox's Form setting = Default. - $I->configureMetaboxSettings( + // Configure Plugin Sidebar's Form setting = Default. + $I->configurePluginSidebarSettings( $I, - metabox: 'wp-convertkit-meta-box', - configuration: [ - 'form' => [ 'select2', 'Default' ], - ] + form: 'Default' ); // Publish and view the Page on the frontend site. @@ -520,13 +508,10 @@ public function testAddNewPageUsingDefaultLegacyForm(EndToEndTester $I) title: 'Kit: Page: Form: Legacy: Default' ); - // Configure metabox's Form setting = Default. - $I->configureMetaboxSettings( + // Configure Plugin Sidebar's Form setting = Default. + $I->configurePluginSidebarSettings( $I, - metabox: 'wp-convertkit-meta-box', - configuration: [ - 'form' => [ 'select2', 'Default' ], - ] + form: 'Default' ); // Publish and view the Page on the frontend site. @@ -559,13 +544,10 @@ public function testAddNewPageUsingNoForm(EndToEndTester $I) title: 'Kit: Page: Form: None' ); - // Configure metabox's Form setting = None. - $I->configureMetaboxSettings( + // Configure Plugin Sidebar's Form setting = None. + $I->configurePluginSidebarSettings( $I, - metabox: 'wp-convertkit-meta-box', - configuration: [ - 'form' => [ 'select2', 'None' ], - ] + form: 'None' ); // Publish and view the Page on the frontend site. @@ -595,13 +577,10 @@ public function testAddNewPageUsingDefinedForm(EndToEndTester $I) title: 'Kit: Page: Form: ' . $_ENV['CONVERTKIT_API_FORM_NAME'] ); - // Configure metabox's Form setting = None. - $I->configureMetaboxSettings( + // Configure Plugin Sidebar's Form setting = Inline Form. + $I->configurePluginSidebarSettings( $I, - metabox: 'wp-convertkit-meta-box', - configuration: [ - 'form' => [ 'select2', $_ENV['CONVERTKIT_API_FORM_NAME'] ], - ] + form: $_ENV['CONVERTKIT_API_FORM_NAME'] ); // Publish and view the Page on the frontend site. @@ -635,13 +614,10 @@ public function testAddNewPageUsingModalFormWithAutoptimizePlugin(EndToEndTester title: 'Kit: Page: Form: ' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] . ': Autoptimize' ); - // Configure metabox's Form setting = None. - $I->configureMetaboxSettings( + // Configure Plugin Sidebar's Form setting = Modal Form. + $I->configurePluginSidebarSettings( $I, - metabox: 'wp-convertkit-meta-box', - configuration: [ - 'form' => [ 'select2', $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] ], - ] + form: $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] ); // Publish and view the Page on the frontend site. @@ -683,13 +659,10 @@ public function testAddNewPageUsingModalFormWithDebloatPlugin(EndToEndTester $I) title: 'Kit: Page: Form: ' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] . ': Debloat' ); - // Configure metabox's Form setting = None. - $I->configureMetaboxSettings( + // Configure Plugin Sidebar's Form setting = Modal Form. + $I->configurePluginSidebarSettings( $I, - metabox: 'wp-convertkit-meta-box', - configuration: [ - 'form' => [ 'select2', $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] ], - ] + form: $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] ); // Publish and view the Page on the frontend site. @@ -733,13 +706,10 @@ public function testAddNewPageUsingModalFormWithJetpackBoostPlugin(EndToEndTeste title: 'Kit: Page: Form: ' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] . ': Jetpack Boost' ); - // Configure metabox's Form setting = None. - $I->configureMetaboxSettings( + // Configure Plugin Sidebar's Form setting = Modal Form. + $I->configurePluginSidebarSettings( $I, - metabox: 'wp-convertkit-meta-box', - configuration: [ - 'form' => [ 'select2', $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] ], - ] + form: $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] ); // Publish and view the Page on the frontend site. @@ -782,13 +752,10 @@ public function testAddNewPageUsingModalFormWithLiteSpeedCachePlugin(EndToEndTes title: 'Kit: Page: Form: ' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] . ': LiteSpeed Cache' ); - // Configure metabox's Form setting = None. - $I->configureMetaboxSettings( + // Configure Plugin Sidebar's Form setting = Modal Form. + $I->configurePluginSidebarSettings( $I, - metabox: 'wp-convertkit-meta-box', - configuration: [ - 'form' => [ 'select2', $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] ], - ] + form: $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] ); // Publish and view the Page on the frontend site. @@ -834,13 +801,10 @@ public function testAddNewPageUsingModalFormWithSitegroundSpeedOptimizerPlugin(E title: 'Kit: Page: Form: ' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] . ': Siteground Speed Optimizer' ); - // Configure metabox's Form setting = None. - $I->configureMetaboxSettings( + // Configure Plugin Sidebar's Form setting = Modal Form. + $I->configurePluginSidebarSettings( $I, - metabox: 'wp-convertkit-meta-box', - configuration: [ - 'form' => [ 'select2', $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] ], - ] + form: $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] ); // Publish and view the Page on the frontend site. @@ -888,13 +852,10 @@ public function testAddNewPageUsingModalFormWithPerfmattersPlugin(EndToEndTester title: 'Kit: Page: Form: ' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] . ': Perfmatters' ); - // Configure metabox's Form setting = None. - $I->configureMetaboxSettings( + // Configure Plugin Sidebar's Form setting = Modal Form. + $I->configurePluginSidebarSettings( $I, - metabox: 'wp-convertkit-meta-box', - configuration: [ - 'form' => [ 'select2', $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] ], - ] + form: $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] ); // Publish and view the Page on the frontend site. @@ -935,13 +896,10 @@ public function testAddNewPageUsingModalFormWithWPRocketPlugin(EndToEndTester $I title: 'Kit: Page: Form: ' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] . ': WP Rocket' ); - // Configure metabox's Form setting = None. - $I->configureMetaboxSettings( + // Configure Plugin Sidebar's Form setting = Modal Form. + $I->configurePluginSidebarSettings( $I, - metabox: 'wp-convertkit-meta-box', - configuration: [ - 'form' => [ 'select2', $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] ], - ] + form: $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] ); // Publish and view the Page on the frontend site. @@ -983,13 +941,10 @@ public function testAddNewPageUsingDefinedLegacyForm(EndToEndTester $I) title: 'Kit: Page: Form: ' . $_ENV['CONVERTKIT_API_LEGACY_FORM_NAME'] ); - // Configure metabox's Form setting = None. - $I->configureMetaboxSettings( + // Configure Plugin Sidebar's Form setting = Legacy Form. + $I->configurePluginSidebarSettings( $I, - metabox: 'wp-convertkit-meta-box', - configuration: [ - 'form' => [ 'select2', $_ENV['CONVERTKIT_API_LEGACY_FORM_NAME'] ], - ] + form: $_ENV['CONVERTKIT_API_LEGACY_FORM_NAME'] ); // Publish and view the Page on the frontend site. From 04ccb626b8003b495a1b311e241ba060d99baf3a Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Wed, 11 Mar 2026 16:53:21 +0800 Subject: [PATCH 03/18] Create new cest for block editor pages --- .../post-types/PageFormBlockEditorCest.php | 991 ++++++++++++++++++ .../forms/post-types/PageFormCest.php | 2 +- 2 files changed, 992 insertions(+), 1 deletion(-) create mode 100644 tests/EndToEnd/forms/post-types/PageFormBlockEditorCest.php diff --git a/tests/EndToEnd/forms/post-types/PageFormBlockEditorCest.php b/tests/EndToEnd/forms/post-types/PageFormBlockEditorCest.php new file mode 100644 index 000000000..f06390cd1 --- /dev/null +++ b/tests/EndToEnd/forms/post-types/PageFormBlockEditorCest.php @@ -0,0 +1,991 @@ +activateKitPlugin($I); + } + + /** + * Test that the 'Default' option for the Default Form setting in the Plugin Settings works when + * creating and viewing a new WordPress Page, and there is no Default Form specified in the Plugin + * settings. + * + * @since 3.2.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingDefaultFormWithNoDefaultFormSpecifiedInPlugin(EndToEndTester $I) + { + // Setup Kit plugin with no default Forms configured. + $I->setupKitPluginNoDefaultForms($I); + $I->setupKitPluginResources($I); + + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + title: 'Kit: Page: Form: Default: None' + ); + + // Configure Plugin Sidebar's Form setting = Default. + $I->configurePluginSidebarSettings( + $I, + form: 'Default' + ); + + // Publish and view the Page on the frontend site. + $I->publishAndViewGutenbergPage($I); + + // Confirm that no Kit Form is displayed. + $I->dontSeeElementInDOM('form[data-sv-form]'); + } + + /** + * Test that the Default Form specified in the Plugin Settings works when + * creating and viewing a new WordPress Page. + * + * @since 3.2.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingDefaultForm(EndToEndTester $I) + { + // Setup Kit plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + title: 'Kit: Page: Form: Default' + ); + + // Configure Plugin Sidebar's Form setting = Default. + $I->configurePluginSidebarSettings( + $I, + form: 'Default' + ); + + // Publish and view the Page on the frontend site. + $I->publishAndViewGutenbergPage($I); + + // Confirm that one Kit Form is output in the DOM. + // This confirms that there is only one script on the page for this form, which renders the form. + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_ID']); + } + + /** + * 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 Page content. + * + * @since 3.2.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingDefaultFormBeforeContent(EndToEndTester $I) + { + // Setup Kit plugin with Default Form for Pages set to be output before the Page content. + $I->setupKitPlugin( + $I, + [ + 'page_form_position' => 'before_content', + ] + ); + $I->setupKitPluginResources($I); + + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + title: 'Kit: Page: Form: Default: Before Content' + ); + + // Add paragraph to Page. + $I->addGutenbergParagraphBlock($I, 'Page content'); + + // Configure Plugin Sidebar's Form setting = Default. + $I->configurePluginSidebarSettings( + $I, + form: 'Default' + ); + + // Publish and view the Page on the frontend site. + $I->publishAndViewGutenbergPage($I); + + // Confirm that one Kit Form is output in the DOM after the Page content. + // This confirms that there is only one script on the page for this form, which renders the form. + $I->seeFormOutput( + $I, + formID: $_ENV['CONVERTKIT_API_FORM_ID'], + position: 'before_content' + ); + } + + /** + * 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 before and after the Page content. + * + * @since 3.2.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingDefaultFormBeforeAndAfterContent(EndToEndTester $I) + { + // Setup Kit plugin with Default Form for Pages set to be output before and after the Page content. + $I->setupKitPlugin( + $I, + [ + 'page_form_position' => 'before_after_content', + ] + ); + $I->setupKitPluginResources($I); + + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + title: 'Kit: Page: Form: Default: Before and After Content' + ); + + // Add paragraph to Page. + $I->addGutenbergParagraphBlock($I, 'Page content'); + + // Configure Plugin Sidebar's Form setting = Default. + $I->configurePluginSidebarSettings( + $I, + form: 'Default' + ); + + // Publish and view the Page on the frontend site. + $I->publishAndViewGutenbergPage($I); + + // Confirm that two Kit Forms are output in the DOM before and after the Page content. + $I->seeFormOutput( + $I, + formID: $_ENV['CONVERTKIT_API_FORM_ID'], + position: 'before_after_content' + ); + } + + /** + * 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 3rd paragraph. + * + * @since 3.2.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingDefaultFormAfterParagraphElement(EndToEndTester $I) + { + // Setup Kit plugin with Default Form for Pages set to be output after the 3rd paragraph of content. + $I->setupKitPlugin( + $I, + [ + 'page_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'page_form_position' => 'after_element', + 'page_form_position_element' => 'p', + 'page_form_position_element_index' => 3, + ] + ); + $I->setupKitPluginResources($I); + + // Setup Page with placeholder content. + $pageID = $I->addGutenbergPageToDatabase( + $I, + title: 'Kit: Page: Form: Default: After 3rd Paragraph Element' + ); + + // View the Page on the frontend site. + $I->amOnPage('?p=' . $pageID); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that one Kit Form is output in the DOM after the third paragraph. + $I->seeFormOutput( + $I, + formID: $_ENV['CONVERTKIT_API_FORM_ID'], + position: 'after_element', + element: 'p', + elementIndex: 3 + ); + + // Confirm character encoding is not broken due to using DOMDocument. + $I->seeInSource('Adhaésionés altéram improbis mi pariendarum sit stulti triarium'); + + // Confirm no meta tag exists within the content. + $I->dontSeeInSource(''); + + // Confirm no extra , or tags are output i.e. injecting the form doesn't result in DOMDocument adding tags. + $I->seeNoExtraHtmlHeadBodyTagsOutput($I); + } + + /** + * Test that specifying a non-inline Form specified in the Plugin Settings does not + * result in a fatal error when creating and viewing a new WordPress Page, and its position is set + * to after the 3rd paragraph. + * + * @since 3.2.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingDefaultNonInlineFormAfterParagraphElement(EndToEndTester $I) + { + // Setup Kit plugin with Default Form for Pages set to be output after the 3rd paragraph of content. + $I->setupKitPlugin( + $I, + [ + 'page_form' => $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID'], + 'page_form_position' => 'after_element', + 'page_form_position_element' => 'p', + 'page_form_position_element_index' => 3, + ] + ); + $I->setupKitPluginResources($I); + + // Setup Page with placeholder content. + $pageID = $I->addGutenbergPageToDatabase( + $I, + title: 'Kit: Page: Non-Inline Form: Default: After 3rd Paragraph Element' + ); + + // View the Page on the frontend site. + $I->amOnPage('?p=' . $pageID); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that one Kit Form is output in the DOM. + // This confirms that there is only one script on the page for this form, which renders the form. + $I->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID'] . '"]', 1); + + // Confirm character encoding is not broken due to using DOMDocument. + $I->seeInSource('Adhaésionés altéram improbis mi pariendarum sit stulti triarium'); + + // Confirm no meta tag exists within the content. + $I->dontSeeInSource(''); + + // Confirm no extra , or tags are output i.e. injecting the form doesn't result in DOMDocument adding tags. + $I->seeNoExtraHtmlHeadBodyTagsOutput($I); + } + + /** + * 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 3.2.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingDefaultFormAfterHeadingElement(EndToEndTester $I) + { + // Setup Kit plugin with Default Form for Pages set to be output after the 2nd

of content. + $I->setupKitPlugin( + $I, + [ + 'page_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'page_form_position' => 'after_element', + 'page_form_position_element' => 'h2', + 'page_form_position_element_index' => 2, + ] + ); + $I->setupKitPluginResources($I); + + // Setup Page with placeholder content. + $pageID = $I->addGutenbergPageToDatabase( + $I, + title: 'Kit: Page: Form: Default: After 2nd H2 Element' + ); + + // View the Page on the frontend site. + $I->amOnPage('?p=' . $pageID); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that one Kit Form is output in the DOM after the second

element. + $I->seeFormOutput( + $I, + formID: $_ENV['CONVERTKIT_API_FORM_ID'], + position: 'after_element', + element: 'h2', + elementIndex: 2 + ); + + // Confirm character encoding is not broken due to using DOMDocument. + $I->seeInSource('Adhaésionés altéram improbis mi pariendarum sit stulti triarium'); + + // Confirm no meta tag exists within the content. + $I->dontSeeInSource(''); + + // Confirm no extra , or tags are output i.e. injecting the form doesn't result in DOMDocument adding tags. + $I->seeNoExtraHtmlHeadBodyTagsOutput($I); + } + + /** + * 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 3.2.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingDefaultFormAfterImageElement(EndToEndTester $I) + { + // Setup Kit plugin with Default Form for Posts set to be output after the 2nd of content. + $I->setupKitPlugin( + $I, + [ + 'page_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'page_form_position' => 'after_element', + 'page_form_position_element' => 'img', + 'page_form_position_element_index' => 2, + ] + ); + $I->setupKitPluginResources($I); + + // Setup Page with placeholder content. + $pageID = $I->addGutenbergPageToDatabase( + $I, + title: 'Kit: Page: 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 Kit Form is output in the DOM after the second element. + $I->seeFormOutput( + $I, + formID: $_ENV['CONVERTKIT_API_FORM_ID'], + position: 'after_element', + element: 'img', + elementIndex: 2 + ); + + // Confirm character encoding is not broken due to using DOMDocument. + $I->seeInSource('Adhaésionés altéram improbis mi pariendarum sit stulti triarium'); + + // Confirm no meta tag exists within the content. + $I->dontSeeInSource(''); + + // Confirm no extra , or tags are output i.e. injecting the form doesn't result in DOMDocument adding tags. + $I->seeNoExtraHtmlHeadBodyTagsOutput($I); + } + + /** + * 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 a number greater than the number of elements in the content. + * + * @since 3.2.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingDefaultFormAfterOutOfBoundsElement(EndToEndTester $I) + { + // Setup Kit plugin with Default Form for Pages set to be output after the 7rd paragraph of content. + $I->setupKitPlugin( + $I, + [ + 'page_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'page_form_position' => 'after_element', + 'page_form_position_element' => 'p', + 'page_form_position_element_index' => 9, + ] + ); + $I->setupKitPluginResources($I); + + // Setup Page with placeholder content. + $pageID = $I->addGutenbergPageToDatabase( + $I, + title: 'Kit: Page: Form: Default: After 9th Paragraph Element' + ); + + // View the Page on the frontend site. + $I->amOnPage('?p=' . $pageID); + + // Check that no PHP warnings or notices were output. + $I->checkNoWarningsAndNoticesOnScreen($I); + + // Confirm that one Kit Form is output in the DOM after the content, as + // the number of paragraphs is less than the position. + $I->seeFormOutput( + $I, + formID: $_ENV['CONVERTKIT_API_FORM_ID'], + position: 'after_content' + ); + + // Confirm character encoding is not broken due to using DOMDocument. + $I->seeInSource('Adhaésionés altéram improbis mi pariendarum sit stulti triarium'); + + // Confirm no meta tag exists within the content. + $I->dontSeeInSource(''); + + // Confirm no extra , or tags are output i.e. injecting the form doesn't result in DOMDocument adding tags. + $I->seeNoExtraHtmlHeadBodyTagsOutput($I); + } + + /** + * Test that the Default Legacy Form specified in the Plugin Settings works when + * creating and viewing a new WordPress Page. + * + * @since 3.2.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingDefaultLegacyForm(EndToEndTester $I) + { + // Setup Plugin with API Key and Secret, which is required for Legacy Forms to work. + $I->setupKitPlugin( + $I, + [ + 'api_key' => $_ENV['CONVERTKIT_API_KEY'], + 'api_secret' => $_ENV['CONVERTKIT_API_SECRET'], + 'page_form' => $_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], + ] + ); + $I->setupKitPluginResources($I); + + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + title: 'Kit: Page: Form: Legacy: Default' + ); + + // Configure Plugin Sidebar's Form setting = Default. + $I->configurePluginSidebarSettings( + $I, + form: 'Default' + ); + + // Publish and view the Page on the frontend site. + $I->publishAndViewGutenbergPage($I); + + // Confirm that the Kit Default Legacy Form displays. + $I->seeInSource('
'); + + // Confirm that the Legacy Form title's character encoding is correct. + $I->seeInSource('Vantar þinn ungling sjálfstraust í stærðfræði?'); + } + + /** + * Test that 'None' Form specified in the Page Settings works when + * creating and viewing a new WordPress Page. + * + * @since 3.2.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingNoForm(EndToEndTester $I) + { + // Setup Kit plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + title: 'Kit: Page: Form: None' + ); + + // Configure Plugin Sidebar's Form setting = None. + $I->configurePluginSidebarSettings( + $I, + form: 'None' + ); + + // Publish and view the Page on the frontend site. + $I->publishAndViewGutenbergPage($I); + + // Confirm that no Kit Form is displayed. + $I->dontSeeElementInDOM('form[data-sv-form]'); + } + + /** + * Test that the Form specified in the Page Settings works when + * creating and viewing a new WordPress Page. + * + * @since 3.2.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingDefinedForm(EndToEndTester $I) + { + // Setup Kit plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + title: 'Kit: Page: Form: ' . $_ENV['CONVERTKIT_API_FORM_NAME'] + ); + + // Configure Plugin Sidebar's Form setting = Inline Form. + $I->configurePluginSidebarSettings( + $I, + form: $_ENV['CONVERTKIT_API_FORM_NAME'] + ); + + // Publish and view the Page on the frontend site. + $I->publishAndViewGutenbergPage($I); + + // Confirm that one Kit Form is output in the DOM. + // This confirms that there is only one script on the page for this form, which renders the form. + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_ID']); + } + + /** + * Test that the Modal Form is output once when the Autoptimize Plugin is active and + * its "Defer JavaScript" setting is enabled. + * + * @since 3.2.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingModalFormWithAutoptimizePlugin(EndToEndTester $I) + { + // Setup Plugin and Resources. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Activate Autoptimize Plugin. + $I->activateThirdPartyPlugin($I, 'autoptimize'); + + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + title: 'Kit: Page: Form: ' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] . ': Autoptimize' + ); + + // Configure Plugin Sidebar's Form setting = Modal Form. + $I->configurePluginSidebarSettings( + $I, + form: $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] + ); + + // Publish and view the Page on the frontend site. + $I->publishAndViewGutenbergPage($I); + + // Confirm that one Kit Form is output in the DOM. + // This confirms that there is only one script on the page for this form, which renders the form, + // and that Autoptimize hasn't moved the script embed to the footer of the site. + $I->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID'] . '"]', 1); + + // Deactivate Autoptimize Plugin. + $I->deactivateThirdPartyPlugin($I, 'autoptimize'); + } + + /** + * Test that the Modal Form is output once when the Debloat Plugin is active and + * its "Defer JavaScript" and "Delay All Scripts" settings are enabled. + * + * @since 3.2.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingModalFormWithDebloatPlugin(EndToEndTester $I) + { + // Setup Plugin and Resources. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Activate Debloat Plugin. + $I->activateThirdPartyPlugin($I, 'disable-_load_textdomain_just_in_time-doing_it_wrong-notice'); + $I->activateThirdPartyPlugin($I, 'debloat'); + + // Enable Debloat's "Defer JavaScript" and "Delay All Scripts" settings. + $I->enableJSDeferDelayAllScriptsDebloatPlugin($I); + + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + title: 'Kit: Page: Form: ' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] . ': Debloat' + ); + + // Configure Plugin Sidebar's Form setting = Modal Form. + $I->configurePluginSidebarSettings( + $I, + form: $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] + ); + + // Publish and view the Page on the frontend site. + $I->publishAndViewGutenbergPage($I); + + // Confirm that one Kit Form is output in the DOM. + // This confirms that there is only one script on the page for this form, which renders the form, + // and that Debloat hasn't moved the script embed to the footer of the site. + $I->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID'] . '"]', 1); + + // Deactivate Debloat Plugin. + $I->deactivateThirdPartyPlugin($I, 'debloat'); + $I->deactivateThirdPartyPlugin($I, 'disable-_load_textdomain_just_in_time-doing_it_wrong-notice'); + } + + /** + * Test that the Modal Form is output once when the Jetpack Boost Plugin is active and + * its "Defer Non-Essential JavaScript" setting is enabled. + * + * @since 3.2.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingModalFormWithJetpackBoostPlugin(EndToEndTester $I) + { + // Setup Plugin and Resources. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Activate Jetpack Boost Plugin. + $I->activateThirdPartyPlugin($I, 'disable-_load_textdomain_just_in_time-doing_it_wrong-notice'); + $I->activateThirdPartyPlugin($I, 'jetpack-boost'); + + // Enable Jetpack Boost's "Defer Non-Essential JavaScript" setting. + $I->amOnAdminPage('admin.php?page=jetpack-boost'); + $I->click('#inspector-toggle-control-1'); + + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + title: 'Kit: Page: Form: ' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] . ': Jetpack Boost' + ); + + // Configure Plugin Sidebar's Form setting = Modal Form. + $I->configurePluginSidebarSettings( + $I, + form: $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] + ); + + // Publish and view the Page on the frontend site. + $I->publishAndViewGutenbergPage($I); + + // Confirm that one Kit Form is output in the DOM. + // This confirms that there is only one script on the page for this form, which renders the form, + // and that Jetpack Boost hasn't moved the script embed to the footer of the site. + $I->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID'] . '"]', 1); + + // Deactivate Jetpack Boost Plugin. + $I->deactivateThirdPartyPlugin($I, 'jetpack-boost'); + $I->deactivateThirdPartyPlugin($I, 'disable-_load_textdomain_just_in_time-doing_it_wrong-notice'); + } + + /** + * Test that the Modal Form is output once when the LiteSpeed Cache Plugin is active and + * its "Load JS Deferred" setting is enabled. + * + * @since 3.2.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingModalFormWithLiteSpeedCachePlugin(EndToEndTester $I) + { + // Setup Kit plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Activate and enable LiteSpeed Cache Plugin. + $I->activateThirdPartyPlugin($I, 'litespeed-cache'); + $I->enableCachingLiteSpeedCachePlugin($I); + + // Enable LiteSpeed Cache's "Load JS Deferred" setting. + $I->enableLiteSpeedCacheLoadJSDeferred($I); + + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + title: 'Kit: Page: Form: ' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] . ': LiteSpeed Cache' + ); + + // Configure Plugin Sidebar's Form setting = Modal Form. + $I->configurePluginSidebarSettings( + $I, + form: $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] + ); + + // Publish and view the Page on the frontend site. + $I->publishAndViewGutenbergPage($I); + + // Confirm that one Kit Form is output in the DOM. + // This confirms that there is only one script on the page for this form, which renders the form, + // and that LiteSpeed Cache hasn't moved the script embed to the footer of the site. + $I->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID'] . '"]', 1); + + // Deactivate LiteSpeed Cache Plugin. + $I->deactivateThirdPartyPlugin($I, 'litespeed-cache'); + } + + /** + * Test that the Modal Form