-
Notifications
You must be signed in to change notification settings - Fork 375
Add E2E tests for Enhanced Conversions data collection during WPForms submissions #13162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JakePT
wants to merge
5
commits into
develop
Choose a base branch
from
enhancement/12013-wpforms-ecee-e2e-tests
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4efe5c8
Add E2E tests for Enhanced Conversions data collection during WPForms…
JakePT 51c365e
Merge branch 'develop' into enhancement/12013-wpforms-ecee-e2e-tests.
JakePT 5a6a2f6
Revert Docker image tag revision change.
JakePT 41c2f52
Address code review feedback.
JakePT bc00f45
Revert image name change.
JakePT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| <?php | ||
| /** | ||
| * Create WPForms forms and associated pages for E2E tests. | ||
| * | ||
| * @package Google\Site_Kit | ||
| * @copyright 2026 Google LLC | ||
| * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 | ||
| * @link https://sitekit.withgoogle.com | ||
| */ | ||
|
|
||
| /** | ||
| * Gets the WPForms fixtures used by the Enhanced Conversions Playwright tests. | ||
| * | ||
| * @return array[] Form and page definitions. | ||
| */ | ||
| function google_site_kit_e2e_get_wpforms_fixtures() { | ||
| $email_field = array( | ||
| 'type' => 'email', | ||
| 'label' => 'Email Address', | ||
| ); | ||
| $name_field = array( | ||
| 'type' => 'name', | ||
| 'label' => 'Name', | ||
| 'size' => 'medium', | ||
| ); | ||
| $phone_field = array( | ||
| 'type' => 'text', | ||
| 'label' => 'Phone Number', | ||
| ); | ||
|
|
||
| return array( | ||
| array( | ||
| 'title' => 'E2E WPForms Email', | ||
| 'fields' => array( $email_field ), | ||
| ), | ||
| array( | ||
| 'title' => 'E2E WPForms Name', | ||
| 'fields' => array( $name_field ), | ||
| ), | ||
| array( | ||
| 'title' => 'E2E WPForms Phone', | ||
| 'fields' => array( $phone_field ), | ||
| ), | ||
| array( | ||
| 'title' => 'E2E WPForms All Fields', | ||
| 'fields' => array( $email_field, $name_field, $phone_field ), | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a WPForms form for an Enhanced Conversions fixture. | ||
| * | ||
| * @param string $title Form title. | ||
| * @param array $fields Form fields. | ||
| * @return int Form ID. | ||
| */ | ||
| function google_site_kit_e2e_create_wpforms_form( $title, $fields ) { | ||
| // WPForms needs an explicit numeric field ID that matches the index. | ||
| foreach ( $fields as $field_id => $field ) { | ||
| $fields[ $field_id ]['id'] = (string) $field_id; | ||
| } | ||
|
|
||
| $forms = wpforms()->get( 'form' ); | ||
| $form_id = $forms->add( $title ); | ||
|
|
||
| $forms->update( | ||
| $form_id, | ||
| array( | ||
| 'id' => $form_id, | ||
| 'fields' => $fields, | ||
| 'settings' => array( | ||
| 'submit_text' => 'Submit', | ||
| 'ajax_submit' => '1', | ||
| ), | ||
| ) | ||
| ); | ||
|
|
||
| return $form_id; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a page containing a WPForms form block. | ||
| * | ||
| * @param string $title Page title. | ||
| * @param int $form_id Form ID. | ||
| */ | ||
| function google_site_kit_e2e_create_wpforms_page( $title, $form_id ) { | ||
| wp_insert_post( | ||
| array( | ||
| 'post_type' => 'page', | ||
| 'post_status' => 'publish', | ||
| 'post_title' => $title, | ||
| 'post_content' => sprintf( '<!-- wp:wpforms/form-selector {"formId":"%d"} /-->', $form_id ), | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Creates all WPForms fixtures for the Enhanced Conversions Playwright tests. | ||
| */ | ||
| function google_site_kit_e2e_create_wpforms_fixtures() { | ||
| foreach ( google_site_kit_e2e_get_wpforms_fixtures() as $fixture ) { | ||
| if ( get_page_by_path( sanitize_title( $fixture['title'] ), OBJECT, 'page' ) ) { | ||
| continue; | ||
| } | ||
|
|
||
| $form_id = google_site_kit_e2e_create_wpforms_form( $fixture['title'], $fixture['fields'] ); | ||
|
|
||
| google_site_kit_e2e_create_wpforms_page( $fixture['title'], $form_id ); | ||
| } | ||
|
|
||
| WP_CLI::success( 'The WPForms test fixtures are ready.' ); | ||
| } | ||
|
|
||
| /** | ||
| * Run. | ||
| */ | ||
| google_site_kit_e2e_create_wpforms_fixtures(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
tests/playwright/docker/wordpress/mu-plugins/e2e-conversion-tracking.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?php | ||
| /** | ||
| * Plugin Name: E2E Conversion Tracking | ||
| * Description: Enables Conversion Tracking during E2E tests based on a cookie set by the Playwright fixture. | ||
| * | ||
| * @package Google\Site_Kit | ||
| * @copyright 2026 Google LLC | ||
| * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 | ||
| * @link https://sitekit.withgoogle.com | ||
| */ | ||
|
|
||
| if ( ! empty( $_COOKIE['_wp_test_conversion_tracking'] ) ) { | ||
| add_filter( | ||
| 'pre_option_googlesitekit_conversion_tracking', | ||
| function () { | ||
| return array( 'enabled' => true ); | ||
| } | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.