diff --git a/tests/e2e/specs/tracking-parameters.test.ts b/tests/e2e/specs/tracking-parameters.test.ts new file mode 100644 index 00000000..7904f4ed --- /dev/null +++ b/tests/e2e/specs/tracking-parameters.test.ts @@ -0,0 +1,33 @@ +import { beforeAll, beforeEach, describe, expect, test } from '@jest/globals'; +import { load as parseDom } from 'cheerio'; +import { updateSettings } from '../lib/plugin-settings'; +import { deleteCacheDirectory, getAuthCookie } from '../lib/plugin-tools'; +import { loadPage } from '../lib/test-tools'; +import { resetEnvironmnt, wpcli } from '../lib/wordpress-tools'; + +describe( 'ignored tracking parameters', () => { + beforeAll( async () => { + await resetEnvironmnt(); + await wpcli( 'plugin', 'activate', 'wp-super-cache' ); + await updateSettings( await getAuthCookie(), { + wp_cache_enabled: true, + } ); + await wpcli( + 'eval', + "wp_cache_setting( 'wpsc_tracking_parameters', array( 'gclid', 'fbclid', 'utm_source' ) ); wp_cache_setting( 'wpsc_ignore_tracking_parameters', 1 );" + ); + } ); + + beforeEach( async () => { + await deleteCacheDirectory(); + } ); + + test( 'does not cache visitor A click ID in visitor B form action', async () => { + const visitorA = await loadPage( '/', { gclid: 'A' } ); + const visitorB = await loadPage(); + + expect( visitorA ).toBe( visitorB ); + expect( parseDom( visitorA )( '#wpsc-request-uri-form' ).attr( 'action' ) ).toBe( '/' ); + expect( parseDom( visitorB )( '#wpsc-request-uri-form' ).attr( 'action' ) ).toBe( '/' ); + } ); +} ); diff --git a/tests/e2e/tools/mu-test-helpers.php b/tests/e2e/tools/mu-test-helpers.php index 91ae2708..44e7dd2d 100644 --- a/tests/e2e/tools/mu-test-helpers.php +++ b/tests/e2e/tools/mu-test-helpers.php @@ -17,6 +17,16 @@ function wpsc_test_inject_footer() { add_action( 'wp_footer', 'wpsc_test_inject_footer' ); add_action( 'admin_footer', 'wpsc_test_inject_footer' ); +/** + * Render a request-derived form action, matching the boundary used by Gravity Forms. + */ +function wpsc_test_request_uri_form() { + $action = isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : '/'; + + echo '
'; +} +add_action( 'wp_footer', 'wpsc_test_request_uri_form' ); + /** * Allow per-request login via HTTP header for a single request. Makes testing easier. */