diff --git a/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormPerformancePluginsCest.php b/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormPerformancePluginsCest.php index fbc5d43a6..dbcaac603 100644 --- a/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormPerformancePluginsCest.php +++ b/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormPerformancePluginsCest.php @@ -47,12 +47,9 @@ public function testFormBlockWithAutoptimizePlugin(EndToEndTester $I) ); // Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg. - $I->configureMetaboxSettings( + $I->configurePluginSidebarSettings( $I, - 'wp-convertkit-meta-box', - [ - 'form' => [ 'select2', 'None' ], - ] + form: 'None' ); // Add block to Page, setting the Form setting to the value specified in the .env file. @@ -105,12 +102,9 @@ public function testFormBlockWithDebloatPlugin(EndToEndTester $I) ); // Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg. - $I->configureMetaboxSettings( + $I->configurePluginSidebarSettings( $I, - 'wp-convertkit-meta-box', - [ - 'form' => [ 'select2', 'None' ], - ] + form: 'None' ); // Add block to Page, setting the Form setting to the value specified in the .env file. @@ -164,12 +158,9 @@ public function testFormBlockWithJetpackBoostPlugin(EndToEndTester $I) ); // Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg. - $I->configureMetaboxSettings( + $I->configurePluginSidebarSettings( $I, - 'wp-convertkit-meta-box', - [ - 'form' => [ 'select2', 'None' ], - ] + form: 'None' ); // Add block to Page, setting the Form setting to the value specified in the .env file. @@ -227,12 +218,9 @@ public function testFormBlockWithSitegroundSpeedOptimizerPlugin(EndToEndTester $ ); // Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg. - $I->configureMetaboxSettings( + $I->configurePluginSidebarSettings( $I, - 'wp-convertkit-meta-box', - [ - 'form' => [ 'select2', 'None' ], - ] + form: 'None' ); // Add block to Page, setting the Form setting to the value specified in the .env file. @@ -284,12 +272,9 @@ public function testFormBlockWithLiteSpeedCachePlugin(EndToEndTester $I) ); // Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg. - $I->configureMetaboxSettings( + $I->configurePluginSidebarSettings( $I, - 'wp-convertkit-meta-box', - [ - 'form' => [ 'select2', 'None' ], - ] + form: 'None' ); // Add block to Page, setting the Form setting to the value specified in the .env file. @@ -350,12 +335,9 @@ public function testFormBlockWithPerfmattersPlugin(EndToEndTester $I) ); // Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg. - $I->configureMetaboxSettings( + $I->configurePluginSidebarSettings( $I, - 'wp-convertkit-meta-box', - [ - 'form' => [ 'select2', 'None' ], - ] + form: 'None' ); // Add block to Page, setting the Form setting to the value specified in the .env file. @@ -407,12 +389,9 @@ public function testFormBlockWithWPRocketPluginDelayJS(EndToEndTester $I) ); // Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg. - $I->configureMetaboxSettings( + $I->configurePluginSidebarSettings( $I, - 'wp-convertkit-meta-box', - [ - 'form' => [ 'select2', 'None' ], - ] + form: 'None' ); // Add block to Page, setting the Form setting to the value specified in the .env file. @@ -471,12 +450,9 @@ public function testFormBlockWithWPRocketPluginMinifyJS(EndToEndTester $I) ); // Configure metabox's Form setting = None, ensuring we only test the block in Gutenberg. - $I->configureMetaboxSettings( + $I->configurePluginSidebarSettings( $I, - 'wp-convertkit-meta-box', - [ - 'form' => [ 'select2', 'None' ], - ] + form: 'None' ); // Add block to Page, setting the Form setting to the value specified in the .env file. diff --git a/tests/EndToEnd/forms/post-types/BlockEditorFormCest.php b/tests/EndToEnd/forms/post-types/BlockEditorFormCest.php new file mode 100644 index 000000000..764183ccb --- /dev/null +++ b/tests/EndToEnd/forms/post-types/BlockEditorFormCest.php @@ -0,0 +1,1192 @@ +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, Post or Article, and there is no Default Form specified in the Plugin + * settings. + * + * @since 1.9.6 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPostTypeUsingDefaultFormWithNoDefaultFormSpecifiedInPlugin(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 Post Type using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Form: Default: None' + ); + + // Publish and view the Post Type 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, Post or Article. + * + * @since 1.9.6 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPostTypeUsingDefaultForm(EndToEndTester $I) + { + // Setup Kit plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Post Type using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Form: Default' + ); + + // Publish and view the Post Type 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, Post or Article, and its position is set + * to after the Post Type content. + * + * @since 2.5.8 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPostTypeUsingDefaultFormBeforeContent(EndToEndTester $I) + { + // Setup Kit plugin with Default Form for Pages, Posts and Articles set to be output before the Post Type content. + $I->setupKitPlugin( + $I, + [ + 'page_form_position' => 'before_content', + 'post_form_position' => 'before_content', + 'article_form_position' => 'before_content', + ] + ); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Post Type using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Form: Default: Before Content' + ); + + // Add paragraph to Post Type. + $I->addGutenbergParagraphBlock($I, $postType . ' content'); + + // Publish and view the Post Type on the frontend site. + $I->publishAndViewGutenbergPage($I); + + // Confirm that one Kit Form is output in the DOM after the Post Type 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, Post or Article, and its position is set + * to before and after the Post Type content. + * + * @since 2.5.9 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPostTypeUsingDefaultFormBeforeAndAfterContent(EndToEndTester $I) + { + // Setup Kit plugin with Default Form for Pages, Posts and Articles set to be output before and after the Post Type content. + $I->setupKitPlugin( + $I, + [ + 'page_form_position' => 'before_after_content', + 'post_form_position' => 'before_after_content', + 'article_form_position' => 'before_after_content', + ] + ); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Post Type using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Form: Default: Before and After Content' + ); + + // Add paragraph to Post Type. + $I->addGutenbergParagraphBlock($I, $postType . ' content'); + + // Publish and view the Post Type on the frontend site. + $I->publishAndViewGutenbergPage($I); + + // Confirm that two Kit Forms are output in the DOM before and after the Post Type 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, Post or Article, and its position is set + * to after the 3rd paragraph of Post Type content. + * + * @since 2.6.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPostTypeUsingDefaultFormAfterParagraphElement(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 Post Type with placeholder content. + $pageID = $I->addGutenbergPageToDatabase( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Form: Default: After 3rd Paragraph Element' + ); + + // View the Post Type 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 of Post Type content. + * + * @since 2.6.8 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPostTypeUsingDefaultNonInlineFormAfterParagraphElement(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 Post Type with placeholder content. + $pageID = $I->addGutenbergPageToDatabase( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Non-Inline Form: Default: After 3rd Paragraph Element' + ); + + // View the Post Type 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, Post or Article, and its position is set + * to after the 2nd

element of Post Type content. + * + * @since 2.6.6 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPostTypeUsingDefaultFormAfterHeadingElement(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 Post Type with placeholder content. + $pageID = $I->addGutenbergPageToDatabase( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Form: Default: After 2nd H2 Element' + ); + + // View the Post Type 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, Post or Article, and its position is set + * to after the 2nd element of Post Type content. + * + * @since 2.6.2 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPostTypeUsingDefaultFormAfterImageElement(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' => 'img', + '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 Post Type with placeholder content. + $pageID = $I->addGutenbergPageToDatabase( + $I, + title: 'Kit: Page: Form: Default: After 2nd Image Element' + ); + + // View the Post Type 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, Post or Article, 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 testAddNewPostTypeUsingDefaultFormAfterOutOfBoundsElement(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 Post Type with placeholder content. + $pageID = $I->addGutenbergPageToDatabase( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Form: Default: After 9th Paragraph Element' + ); + + // View the Post Type 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, Post or Article. + * + * @since 1.9.6.3 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPostTypeUsingDefaultLegacyForm(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 Post Type using the Gutenberg editor. + $I->addGutenbergPage( + $I, + postType: $postType, + title: 'Kit: ' . $postType . ': Form: Legacy: Default' + ); + + // Publish and view the Post Type 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, Post or Article. + * + * @since 1.9.6 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPostTypeUsingNoForm(EndToEndTester $I) + { + // Setup Kit plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Post Type 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 Post Type 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, Post or Article. + * + * @since 1.9.6 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPostTypeUsingDefinedForm(EndToEndTester $I) + { + // Setup Kit plugin. + $I->setupKitPlugin($I); + $I->setupKitPluginResources($I); + + // Test each Post Type. + foreach ( $this->postTypes as $postType ) { + // Add a Post Type 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 Post Type 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 for a WordPress Page, Post or Article. + * + * @since 2.4.9 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPostTypeUsingModalFormWithAutoptimizePlugin(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 Post Type 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 Post Type 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 for a WordPress Page, Post or Article. + * + * @since 2.8.6 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPostTypeUsingModalFormWithDebloatPlugin(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 Post Type 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 Post Type 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 for a WordPress Page, Post or Article. + * + * @since 2.4.5 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPostTypeUsingModalFormWithJetpackBoostPlugin(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 Post Type 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 Post Type 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 for a WordPress Page, Post or Article. + * + * @since 2.4.5 + * + * @param EndToEndTester $I Tester. + */ + public function testAddNewPostTypeUsingModalFormWithLiteSpeedCachePlugin(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 Post Type 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 Post Type 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