From 0bd621e34af794f3cb881c9920b7b739d6ecb466 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Thu, 26 Mar 2026 12:47:38 +0800 Subject: [PATCH 1/7] Tests: Block Editor: Form Setting: Refactor Tests --- .../forms/post-types/BlockEditorFormCest.php | 1183 +++++++++++++++++ .../EndToEnd/forms/post-types/CPTFormCest.php | 853 ------------ .../forms/post-types/PageFormCest.php | 1073 --------------- .../forms/post-types/PostFormCest.php | 757 ----------- 4 files changed, 1183 insertions(+), 2683 deletions(-) create mode 100644 tests/EndToEnd/forms/post-types/BlockEditorFormCest.php delete mode 100644 tests/EndToEnd/forms/post-types/CPTFormCest.php delete mode 100644 tests/EndToEnd/forms/post-types/PageFormCest.php delete mode 100644 tests/EndToEnd/forms/post-types/PostFormCest.php diff --git a/tests/EndToEnd/forms/post-types/BlockEditorFormCest.php b/tests/EndToEnd/forms/post-types/BlockEditorFormCest.php new file mode 100644 index 000000000..d3acb36c7 --- /dev/null +++ b/tests/EndToEnd/forms/post-types/BlockEditorFormCest.php @@ -0,0 +1,1183 @@ +activateKitPlugin($I); + + // Create Custom Post Types using the Custom Post Type UI Plugin. + $I->registerCustomPostTypes($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 1.9.6 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingDefaultFormWithNoDefaultFormSpecifiedInPlugin(EndToEndTester $I) + { + // Setup Kit plugin with no default Forms configured. + $I->setupKitPluginNoDefaultForms($I); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Form: Default: 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 Default Form specified in the Plugin Settings works when + * creating and viewing a new WordPress Page. + * + * @since 1.9.6 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingDefaultForm(EndToEndTester $I) + { + // Setup Kit plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': 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 2.5.8 + * + * @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); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Form: Default: Before Content' + ); + + // Add paragraph to Page. + $I->addGutenbergParagraphBlock($I, 'Page content'); + + // 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 2.5.9 + * + * @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); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Form: Default: Before and After Content' + ); + + // Add paragraph to Page. + $I->addGutenbergParagraphBlock($I, 'Page content'); + + // 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 2.6.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingDefaultFormAfterParagraphElement(EndToEndTester $I) + { + // Setup Kit plugin with Default Form for Pages, Posts and Articles 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, + 'post_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'post_form_position' => 'after_element', + 'post_form_position_element' => 'p', + 'post_form_position_element_index' => 3, + 'article_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'article_form_position' => 'after_element', + 'article_form_position_element' => 'p', + 'article_form_position_element_index' => 3, + ] + ); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Setup Page with placeholder content. + $pageID = $I->addGutenbergPageToDatabase( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': 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 2.6.8 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingDefaultNonInlineFormAfterParagraphElement(EndToEndTester $I) + { + // Setup Kit plugin with Default Form for Pages, Posts and Articles 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, + 'post_form' => $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID'], + 'post_form_position' => 'after_element', + 'post_form_position_element' => 'p', + 'post_form_position_element_index' => 3, + 'article_form' => $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID'], + 'article_form_position' => 'after_element', + 'article_form_position_element' => 'p', + 'article_form_position_element_index' => 3, + ] + ); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Setup Page with placeholder content. + $pageID = $I->addGutenbergPageToDatabase( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': 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 2.6.6 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingDefaultFormAfterHeadingElement(EndToEndTester $I) + { + // Setup Kit plugin with Default Form for Pages, Posts and Articles 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, + 'post_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'post_form_position' => 'after_element', + 'post_form_position_element' => 'h2', + 'post_form_position_element_index' => 2, + 'article_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'article_form_position' => 'after_element', + 'article_form_position_element' => 'h2', + 'article_form_position_element_index' => 2, + ] + ); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Setup Page with placeholder content. + $pageID = $I->addGutenbergPageToDatabase( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': 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 2.6.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingDefaultFormAfterImageElement(EndToEndTester $I) + { + // Setup Kit plugin with Default Form for Pages, Posts and Articles set to be output after the 2nd of content. + $I->setupKitPlugin( + $I, + [ + 'page_form_position_element_index' => 2, + 'post_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'post_form_position' => 'after_element', + 'post_form_position_element' => 'img', + 'post_form_position_element_index' => 2, + 'article_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'article_form_position' => 'after_element', + 'article_form_position_element' => 'img', + 'article_form_position_element_index' => 2, + ] + ); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // 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 2.6.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingDefaultFormAfterOutOfBoundsElement(EndToEndTester $I) + { + // Setup Kit plugin with Default Form for Pages, Posts and Articles set to be output after the 9th 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, + 'post_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'post_form_position' => 'after_element', + 'post_form_position_element' => 'p', + 'post_form_position_element_index' => 9, + 'article_form' => $_ENV['CONVERTKIT_API_FORM_ID'], + 'article_form_position' => 'after_element', + 'article_form_position_element' => 'p', + 'article_form_position_element_index' => 9, + ] + ); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Setup Page with placeholder content. + $pageID = $I->addGutenbergPageToDatabase( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': 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 1.9.6.3 + * + * @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'], + 'post_form' => $_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], + 'article_form' => $_ENV['CONVERTKIT_API_LEGACY_FORM_ID'], + ] + ); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Form: Legacy: 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 1.9.6 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingNoForm(EndToEndTester $I) + { + // Setup Kit plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Form: None' + ); + + // Configure metabox'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 1.9.6 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPageUsingDefinedForm(EndToEndTester $I) + { + // Setup Kit plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Form: ' . $_ENV['CONVERTKIT_API_FORM_NAME'] + ); + + // Configure metabox'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 2.4.9 + * + * @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'); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Form: ' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] . ': Autoptimize' + ); + + // Configure metabox'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 2.8.6 + * + * @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); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Form: ' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] . ': Debloat' + ); + + // Configure metabox'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 2.4.5 + * + * @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'); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Form: ' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] . ': Jetpack Boost' + ); + + // Configure metabox'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 2.4.5 + * + * @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); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Page using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Form: ' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_NAME'] . ': LiteSpeed Cache' + ); + + // Configure metabox'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