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