diff --git a/.env.dist.testing b/.env.dist.testing index 31a59c636..6d3e60201 100644 --- a/.env.dist.testing +++ b/.env.dist.testing @@ -28,8 +28,8 @@ CHROMEDRIVER_HOST=localhost CHROMEDRIVER_PORT=9515 # The user agents used in end-to-end tests. -TEST_SITE_HTTP_USER_AGENT=HeadlessChrome -TEST_SITE_HTTP_USER_AGENT_MOBILE=HeadlessChromeMobile +TEST_SITE_HTTP_USER_AGENT="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36 WordPress/7.0.1;PHP/8.4.1;ConvertKit/3.3.6;http://example.com" +TEST_SITE_HTTP_USER_AGENT_MOBILE="Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Mobile Safari/537.36 WordPress/7.0.1;PHP/8.4.1;ConvertKit/3.3.6;http://example.com" # Kit specific variables CONVERTKIT_API_SUBSCRIBER_EMAIL="optin@n7studios.com" diff --git a/includes/class-convertkit-post.php b/includes/class-convertkit-post.php index 58d1a4ab8..b13cf01b2 100644 --- a/includes/class-convertkit-post.php +++ b/includes/class-convertkit-post.php @@ -314,9 +314,9 @@ public function get_default_settings() { $defaults = array( 'form' => '-1', // -1: Plugin Default Form, 0: No Form, 1+: Specific Form ID on ConvertKit. - 'landing_page' => '', - 'tag' => '', - 'restrict_content' => '', + 'landing_page' => '0', // 0: None, 1+: Specific Landing Page ID. + 'tag' => '0', // 0: None, 1+: Specific Tag ID. + 'restrict_content' => '0', // 0: None, form_ / tag_ / product_: restrict to that resource. ); /** diff --git a/tests/EndToEnd.suite.yml b/tests/EndToEnd.suite.yml index 85037bdcf..f00924664 100644 --- a/tests/EndToEnd.suite.yml +++ b/tests/EndToEnd.suite.yml @@ -55,6 +55,7 @@ modules: port: '%CHROMEDRIVER_PORT%' path: '/wd/hub' window_size: 1920x1080 + log_js_errors: true capabilities: "goog:chromeOptions": args: diff --git a/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormCest.php b/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormCest.php index ab6c101ad..578098015 100644 --- a/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormCest.php +++ b/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormCest.php @@ -160,12 +160,12 @@ public function testFormBlockWithValidModalFormParameter(EndToEndTester $I) // 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->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID'] . '"]', 1); - // Confirm that the Form block container is not output. $I->dontSeeElementInDOM('div.convertkit-form.wp-block-convertkit-form'); + + // 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_FORMAT_MODAL_ID']); } /** @@ -223,7 +223,7 @@ public function testFormBlocksWithValidModalFormParameter(EndToEndTester $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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); // Confirm that the Form block container is not output. $I->dontSeeElementInDOM('div.convertkit-form.wp-block-convertkit-form'); @@ -272,12 +272,12 @@ public function testFormBlockWithValidSlideInFormParameter(EndToEndTester $I) // 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->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_SLIDE_IN_ID'] . '"]', 1); - // Confirm that the Form block container is not output. $I->dontSeeElementInDOM('div.convertkit-form.wp-block-convertkit-form'); + + // 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_FORMAT_SLIDE_IN_ID']); } /** @@ -333,12 +333,12 @@ public function testFormBlocksWithValidSlideInFormParameter(EndToEndTester $I) // 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->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_SLIDE_IN_ID'] . '"]', 1); - // Confirm that the Form block container is not output. $I->dontSeeElementInDOM('div.convertkit-form.wp-block-convertkit-form'); + + // 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_FORMAT_SLIDE_IN_ID']); } /** @@ -384,12 +384,12 @@ public function testFormBlockWithValidStickyBarFormParameter(EndToEndTester $I) // 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->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'] . '"]', 1); - // Confirm that the Form block container is not output. $I->dontSeeElementInDOM('div.convertkit-form.wp-block-convertkit-form'); + + // 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_FORMAT_STICKY_BAR_ID']); } /** @@ -445,12 +445,12 @@ public function testFormBlocksWithValidStickyBarFormParameter(EndToEndTester $I) // 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->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'] . '"]', 1); - // Confirm that the Form block container is not output. $I->dontSeeElementInDOM('div.convertkit-form.wp-block-convertkit-form'); + + // 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_FORMAT_STICKY_BAR_ID']); } /** diff --git a/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormTriggerCest.php b/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormTriggerCest.php index 9046ecbde..be76aebd6 100644 --- a/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormTriggerCest.php +++ b/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormTriggerCest.php @@ -128,7 +128,7 @@ public function testFormTriggerBlocksWithValidFormParameter(EndToEndTester $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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); } /** diff --git a/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormatterFormTriggerCest.php b/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormatterFormTriggerCest.php index e96e4e00e..f748740d8 100644 --- a/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormatterFormTriggerCest.php +++ b/tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormatterFormTriggerCest.php @@ -77,7 +77,7 @@ public function testFormTriggerFormatterWithModalForm(EndToEndTester $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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); } /** diff --git a/tests/EndToEnd/forms/general/NonInlineFormCest.php b/tests/EndToEnd/forms/general/NonInlineFormCest.php index c626e82b4..5a1cdcca5 100644 --- a/tests/EndToEnd/forms/general/NonInlineFormCest.php +++ b/tests/EndToEnd/forms/general/NonInlineFormCest.php @@ -71,14 +71,14 @@ public function testDefaultNonInlineForm(EndToEndTester $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_STICKY_BAR_ID'] . '"]', 1); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID']); // View Page. $I->amOnPage('/kit-default-non-inline-global'); // 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_STICKY_BAR_ID'] . '"]', 1); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID']); // View a search page. $I->amOnPage('/?s=test'); @@ -129,15 +129,15 @@ public function testDefaultNonInlineForms(EndToEndTester $I) $I->amOnPage('/'); // Confirm that two Kit Forms are output in the DOM. - $I->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'] . '"]', 1); - $I->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID'] . '"]', 1); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID']); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); // View Page. $I->amOnPage('/kit-default-non-inline-global-forms'); // Confirm that two Kit Forms are output in the DOM. - $I->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'] . '"]', 1); - $I->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID'] . '"]', 1); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID']); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); // View a search page. $I->amOnPage('/?s=test'); @@ -697,7 +697,7 @@ public function testNonInlineFormLimitPerSession(EndToEndTester $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_STICKY_BAR_ID'] . '"]', 1); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID']); // View Page. $I->amOnPage('/kit-non-inline-form-limit-per-session'); @@ -750,7 +750,7 @@ public function testNonInlineFormLimitPerSessionDoesNotSetCookieWhenDisabled(End // 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_STICKY_BAR_ID'] . '"]', 1); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID']); // Confirm no cookie is set. $I->dontSeeCookie('ck_non_inline_form_displayed'); @@ -760,7 +760,7 @@ public function testNonInlineFormLimitPerSessionDoesNotSetCookieWhenDisabled(End // 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_STICKY_BAR_ID'] . '"]', 1); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID']); // Confirm no cookie is set. $I->dontSeeCookie('ck_non_inline_form_displayed'); @@ -803,14 +803,14 @@ public function testDefaultNonInlineFormOnUpgrade(EndToEndTester $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_STICKY_BAR_ID'] . '"]', 1); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID']); // View Page. $I->amOnPage('/kit-default-non-inline-global-upgrade'); // 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_STICKY_BAR_ID'] . '"]', 1); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID']); } /** diff --git a/tests/EndToEnd/forms/post-types/BlockEditorFormCest.php b/tests/EndToEnd/forms/post-types/BlockEditorFormCest.php index 50f84b9d6..403f65a6c 100644 --- a/tests/EndToEnd/forms/post-types/BlockEditorFormCest.php +++ b/tests/EndToEnd/forms/post-types/BlockEditorFormCest.php @@ -311,7 +311,7 @@ public function testAddNewPostTypeUsingDefaultNonInlineFormAfterParagraphElement // 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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); // Confirm character encoding is not broken due to using DOMDocument. $I->seeInSource('Adhaésionés altéram improbis mi pariendarum sit stulti triarium'); @@ -676,7 +676,7 @@ public function testAddNewPostTypeUsingModalFormWithAutoptimizePlugin(EndToEndTe // 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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); } // Deactivate Autoptimize Plugin. @@ -725,7 +725,7 @@ public function testAddNewPostTypeUsingModalFormWithDebloatPlugin(EndToEndTester // 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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); } // Deactivate Debloat Plugin. @@ -776,7 +776,7 @@ public function testAddNewPostTypeUsingModalFormWithJetpackBoostPlugin(EndToEndT // 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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); } // Deactivate Jetpack Boost Plugin. @@ -826,7 +826,7 @@ public function testAddNewPostTypeUsingModalFormWithLiteSpeedCachePlugin(EndToEn // 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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); } // Deactivate LiteSpeed Cache Plugin. @@ -877,7 +877,7 @@ public function testAddNewPostTypeUsingModalFormWithSitegroundSpeedOptimizerPlug $I->publishAndViewGutenbergPage($I); // Confirm that one Kit Form is output in the DOM. - $I->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID'] . '"]', 1); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); } // Deactivate Siteground Speed Optimizer Plugin. @@ -934,7 +934,7 @@ public function testAddNewPostTypeUsingModalFormWithPerfmattersPlugin(EndToEndTe // Confirm that one Kit Form is output in the DOM within the
element. // 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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); } // Deactivate Perfmatters Plugin. @@ -983,7 +983,7 @@ public function testAddNewPostTypeUsingModalFormWithWPRocketPlugin(EndToEndTeste // Confirm that one Kit Form is output in the DOM within the
element. // 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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); } // Deactivate WP Rocket Plugin. diff --git a/tests/EndToEnd/forms/post-types/ClassicEditorFormCest.php b/tests/EndToEnd/forms/post-types/ClassicEditorFormCest.php index c46126e96..1a587c81f 100644 --- a/tests/EndToEnd/forms/post-types/ClassicEditorFormCest.php +++ b/tests/EndToEnd/forms/post-types/ClassicEditorFormCest.php @@ -379,7 +379,7 @@ public function testAddNewPostTypeUsingDefaultNonInlineFormAfterParagraphElement // 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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); // Confirm character encoding is not broken due to using DOMDocument. $I->seeInSource('Adhaésionés altéram improbis mi pariendarum sit stulti triarium'); @@ -761,7 +761,7 @@ public function testAddNewPostTypeUsingModalFormWithAutoptimizePlugin(EndToEndTe // 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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); } // Deactivate Autoptimize Plugin. @@ -813,7 +813,7 @@ public function testAddNewPostTypeUsingModalFormWithDebloatPlugin(EndToEndTester // 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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); } // Deactivate Debloat Plugin. @@ -867,7 +867,7 @@ public function testAddNewPostTypeUsingModalFormWithJetpackBoostPlugin(EndToEndT // 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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); } // Deactivate Jetpack Boost Plugin. @@ -920,7 +920,7 @@ public function testAddNewPostTypeUsingModalFormWithLiteSpeedCachePlugin(EndToEn // 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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); } // Deactivate LiteSpeed Cache Plugin. @@ -974,7 +974,7 @@ public function testAddNewPostTypeUsingModalFormWithSitegroundSpeedOptimizerPlug $I->publishAndViewClassicEditorPage($I); // Confirm that one Kit Form is output in the DOM. - $I->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID'] . '"]', 1); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); } // Deactivate Siteground Speed Optimizer Plugin. @@ -1034,7 +1034,7 @@ public function testAddNewPostTypeUsingModalFormWithPerfmattersPlugin(EndToEndTe // Confirm that one Kit Form is output in the DOM within the
element. // 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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); } // Deactivate Perfmatters Plugin. @@ -1086,7 +1086,7 @@ public function testAddNewPostTypeUsingModalFormWithWPRocketPlugin(EndToEndTeste // Confirm that one Kit Form is output in the DOM within the
element. // 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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); } // Deactivate WP Rocket Plugin. diff --git a/tests/EndToEnd/general/plugin-screens/PluginSettingsGeneralCest.php b/tests/EndToEnd/general/plugin-screens/PluginSettingsGeneralCest.php index c938f0bc8..1f949ca9c 100644 --- a/tests/EndToEnd/general/plugin-screens/PluginSettingsGeneralCest.php +++ b/tests/EndToEnd/general/plugin-screens/PluginSettingsGeneralCest.php @@ -372,7 +372,7 @@ public function testChangeDefaultSiteWideFormsSettingAndPreviewFormLinks(EndToEn // 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_STICKY_BAR_ID'] . '"]', 1); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID']); // Close newly opened tab. $I->closeTab(); @@ -395,8 +395,8 @@ public function testChangeDefaultSiteWideFormsSettingAndPreviewFormLinks(EndToEn $I->seeElementInDOM('body.home'); // Confirm that two Kit Forms are output in the DOM. - $I->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID'] . '"]', 1); - $I->seeNumberOfElementsInDOM('form[data-sv-form="' . $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID'] . '"]', 1); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_STICKY_BAR_ID']); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); // Close newly opened tab. $I->closeTab(); diff --git a/tests/EndToEnd/integrations/divi-builder/DiviPluginFormTriggerCest.php b/tests/EndToEnd/integrations/divi-builder/DiviPluginFormTriggerCest.php index eb7d567c3..048278bf2 100644 --- a/tests/EndToEnd/integrations/divi-builder/DiviPluginFormTriggerCest.php +++ b/tests/EndToEnd/integrations/divi-builder/DiviPluginFormTriggerCest.php @@ -59,7 +59,7 @@ public function testFormTriggerModuleInBackendEditor(EndToEndTester $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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); // Deactivate Classic Editor. $I->deactivateThirdPartyPlugin($I, 'classic-editor'); @@ -99,7 +99,7 @@ public function testFormTriggerModuleInFrontendEditor(EndToEndTester $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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); } /** diff --git a/tests/EndToEnd/integrations/divi-theme/DiviThemeFormTriggerCest.php b/tests/EndToEnd/integrations/divi-theme/DiviThemeFormTriggerCest.php index 984d5ea02..0a0cba483 100644 --- a/tests/EndToEnd/integrations/divi-theme/DiviThemeFormTriggerCest.php +++ b/tests/EndToEnd/integrations/divi-theme/DiviThemeFormTriggerCest.php @@ -61,7 +61,7 @@ public function testFormTriggerModule(EndToEndTester $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); + $I->seeFormOutput($I, $_ENV['CONVERTKIT_API_FORM_FORMAT_MODAL_ID']); } /** diff --git a/tests/EndToEnd/integrations/elementor/ElementorBroadcastsCest.php b/tests/EndToEnd/integrations/elementor/ElementorBroadcastsCest.php index fca89425d..c429cde3f 100644 --- a/tests/EndToEnd/integrations/elementor/ElementorBroadcastsCest.php +++ b/tests/EndToEnd/integrations/elementor/ElementorBroadcastsCest.php @@ -44,10 +44,6 @@ public function testBroadcastsWidgetIsRegistered(EndToEndTester $I) // Click Edit with Elementor button. $I->click('#elementor-switch-mode-button'); - // When Elementor loads, dismiss the browser incompatibility message. - $I->waitForElementVisible('#elementor-fatal-error-dialog'); - $I->click('#elementor-fatal-error-dialog button.dialog-confirm-ok'); - // Search for the Kit Broadcasts block. $I->waitForElementVisible('#elementor-panel-elements-search-input'); $I->fillField('#elementor-panel-elements-search-input', 'Kit Broadcasts'); @@ -74,10 +70,6 @@ public function testBroadcastsWidgetConditionalFields(EndToEndTester $I) // Click Edit with Elementor button. $I->click('#elementor-switch-mode-button'); - // When Elementor loads, dismiss the browser incompatibility message. - $I->waitForElementVisible('#elementor-fatal-error-dialog'); - $I->click('#elementor-fatal-error-dialog button.dialog-confirm-ok'); - // Search for the Kit Broadcasts block. $I->waitForElementVisible('#elementor-panel-elements-search-input'); $I->fillField('#elementor-panel-elements-search-input', 'Kit Broadcasts'); diff --git a/tests/EndToEnd/integrations/elementor/ElementorFormCest.php b/tests/EndToEnd/integrations/elementor/ElementorFormCest.php index 8b71e5746..55609fbbe 100644 --- a/tests/EndToEnd/integrations/elementor/ElementorFormCest.php +++ b/tests/EndToEnd/integrations/elementor/ElementorFormCest.php @@ -46,10 +46,6 @@ public function testFormWidgetIsRegistered(EndToEndTester $I) // Click Edit with Elementor button. $I->click('#elementor-switch-mode-button'); - // When Elementor loads, dismiss the browser incompatibility message. - $I->waitForElementVisible('#elementor-fatal-error-dialog'); - $I->click('#elementor-fatal-error-dialog button.dialog-confirm-ok'); - // Search for the Kit Form block. $I->waitForElementVisible('#elementor-panel-elements-search-input'); $I->fillField('#elementor-panel-elements-search-input', 'Kit Form'); diff --git a/tests/EndToEnd/integrations/elementor/ElementorFormTriggerCest.php b/tests/EndToEnd/integrations/elementor/ElementorFormTriggerCest.php index 754b3098f..05fa479d5 100644 --- a/tests/EndToEnd/integrations/elementor/ElementorFormTriggerCest.php +++ b/tests/EndToEnd/integrations/elementor/ElementorFormTriggerCest.php @@ -44,10 +44,6 @@ public function testFormTriggerWidgetIsRegistered(EndToEndTester $I) // Click Edit with Elementor button. $I->click('#elementor-switch-mode-button'); - // When Elementor loads, dismiss the browser incompatibility message. - $I->waitForElementVisible('#elementor-fatal-error-dialog'); - $I->click('#elementor-fatal-error-dialog button.dialog-confirm-ok'); - // Search for the Kit Form Trigger block. $I->waitForElementVisible('#elementor-panel-elements-search-input'); $I->fillField('#elementor-panel-elements-search-input', 'Kit Form Trigger'); diff --git a/tests/EndToEnd/integrations/elementor/ElementorProductCest.php b/tests/EndToEnd/integrations/elementor/ElementorProductCest.php index 96a4b0a35..920e700c4 100644 --- a/tests/EndToEnd/integrations/elementor/ElementorProductCest.php +++ b/tests/EndToEnd/integrations/elementor/ElementorProductCest.php @@ -44,10 +44,6 @@ public function testProductWidgetIsRegistered(EndToEndTester $I) // Click Edit with Elementor button. $I->click('#elementor-switch-mode-button'); - // When Elementor loads, dismiss the browser incompatibility message. - $I->waitForElementVisible('#elementor-fatal-error-dialog'); - $I->click('#elementor-fatal-error-dialog button.dialog-confirm-ok'); - // Search for the Kit Product block. $I->waitForElementVisible('#elementor-panel-elements-search-input'); $I->fillField('#elementor-panel-elements-search-input', 'Kit Product'); diff --git a/tests/Support/Helper/KitPlugin.php b/tests/Support/Helper/KitPlugin.php index 790877f81..473622aa2 100644 --- a/tests/Support/Helper/KitPlugin.php +++ b/tests/Support/Helper/KitPlugin.php @@ -1103,35 +1103,9 @@ public function selectAllText($I, $selector) */ public function enableMobileEmulation() { - $this->getModule(\lucatume\WPBrowser\Module\WPWebDriver::class)->_restart( - [ - 'browser' => 'chrome', - 'capabilities' => [ - 'goog:chromeOptions' => [ - 'args' => [ - '--headless', - '--disable-gpu', - '--disable-dev-shm-usage', - "--proxy-server='direct://'", - '--proxy-bypass-list=*', - '--no-sandbox', - '--user-agent=' . $_ENV['TEST_SITE_HTTP_USER_AGENT_MOBILE'], - ], - 'mobileEmulation' => [ - 'deviceMetrics' => [ - 'width' => 430, - 'height' => 932, - 'pixelRatio' => 1, - ], - 'clientHints' => [ - 'platform' => 'Android', - 'mobile' => true, - ], - 'userAgent' => $_ENV['TEST_SITE_HTTP_USER_AGENT_MOBILE'], - ], - ], - ], - ] + $this->changeUserAgent( + userAgent: $_ENV['TEST_SITE_HTTP_USER_AGENT_MOBILE'], + isMobile: true ); } @@ -1143,22 +1117,59 @@ public function enableMobileEmulation() */ public function disableMobileEmulation() { + $this->changeUserAgent( + userAgent: $_ENV['TEST_SITE_HTTP_USER_AGENT'], + isMobile: false + ); + } + + /** + * Changes the WPWebBrowser Chrome User Agent, + * restarting the headless Chrome instance. + * + * @since 3.3.6 + * + * @param string $userAgent User Agent. + * @param bool $isMobile Whether the user agent is for a mobile device. + */ + public function changeUserAgent($userAgent, $isMobile = false) + { + // Build base options. + $options = [ + 'args' => [ + '--headless', + '--disable-gpu', + '--disable-dev-shm-usage', + '--disable-software-rasterizer', + "--proxy-server='direct://'", + '--proxy-bypass-list=*', + '--no-sandbox', + '--user-agent=' . $userAgent, + ], + ]; + + // If mobile, add mobile emulation options. + if ($isMobile) { + $options['mobileEmulation'] = [ + 'deviceMetrics' => [ + 'width' => 430, + 'height' => 932, + 'pixelRatio' => 1, + ], + 'clientHints' => [ + 'platform' => 'Android', + 'mobile' => true, + ], + 'userAgent' => $userAgent, + ]; + } + + // Restart chromedriver with the new options. $this->getModule(\lucatume\WPBrowser\Module\WPWebDriver::class)->_restart( [ 'browser' => 'chrome', 'capabilities' => [ - 'goog:chromeOptions' => [ - 'args' => [ - '--headless', - '--disable-gpu', - '--disable-dev-shm-usage', - "--proxy-server='direct://'", - '--proxy-bypass-list=*', - '--no-sandbox', - '--user-agent=' . $_ENV['TEST_SITE_HTTP_USER_AGENT'], - ], - // excluding mobileEmulation arguments here makes chromedriver behave in desktop mode. - ], + 'goog:chromeOptions' => $options, ], ] );