Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce grace period before asking guests to verify their email add…
…ress (#39191) * Add a grace period during which email verification is not required (order pay/conf page). When the order confirmation (or payment) page is requested, we often want to ensure the visitor is associated with the order. However, this relies heavily on information stored in the user session and, depending on the payment gateway in use, this may not be dependable. Therefore, we've introduced a grace period during which no such verification will take place. * Provide a mechanism for establishing server-side filters from our E2E tests. * Make our utilities for setting up filters from E2E available in the test env. * Update guest shopper workflow to account for order conf/payment access grace period. * Tidy verbiage. * Add changefile(s) from automation for the following project(s): woocommerce * Only activate the Filter Setter (e2e utility) during e2e tests. * Coding standard fixes for E2E utility plugin. * e2e: Update locators for headings to use getByRole, add await to clearFilters * e2e: Abstract the cookie domain to work on non-localhost test sites --------- Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Corey McKrill <916023+coreymckrill@users.noreply.github.com>
- Loading branch information
1 parent
032beaa
commit e97eda1
Showing
8 changed files
with
202 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,4 @@ | ||
Significance: patch | ||
Type: fix | ||
|
||
Adds a grace period during which email verification will not be needed before the order confirmation (or payment) page is rendered. |
This file contains 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
This file contains 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,87 @@ | ||
<?php | ||
/** | ||
* Plugin name: Filter Setter | ||
* Description: Utility intended to be used during E2E testing, to make it easy to setup WordPress filters. | ||
* | ||
* Intended to function as a (mu-)plugin while tests are running, this code works by inspecting the current cookie | ||
* for an entry called 'e2e-filters', which is expected to be a JSON description of filter hooks and the values we want | ||
* to set via those filters. For example, given the JSON (pretty printed here for clarity): | ||
* | ||
* { | ||
* "wooocommerce_system_timeout": 10 | ||
* } | ||
* | ||
* Then a filter will be added that returns 10 when 'woocommerce_system_timeout' is invoked. Or, given: | ||
* | ||
* { | ||
* "woocommerce_enable_deathray": { | ||
* "callback": "__return_false" | ||
* } | ||
* } | ||
* | ||
* Then the `__return_false()` convenience function will be set up in relation to filter hook | ||
* 'woocommerce_enable_deathray'. Additionally, priorities can be specified. Example: | ||
* | ||
* { | ||
* "woocommerce_enable_deathray": { | ||
* "callback": "__return_false", | ||
* "priority": 20 | ||
* } | ||
* } | ||
* | ||
* Priorities can also be used in combination with literal values. For example: | ||
* | ||
* { | ||
* "woocommerce_default_username": { | ||
* "value": "Geoffrey", | ||
* "priority": 20 | ||
* } | ||
* } | ||
* | ||
* It hopefully goes without saying, this should not be used in a production environment. | ||
* | ||
* @package Automattic\WooCommerce\E2EPlaywright | ||
*/ | ||
|
||
if ( ! isset( $_COOKIE ) || ! isset( $_COOKIE['e2e-filters'] ) ) { | ||
return; | ||
} | ||
|
||
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash | ||
$filters = json_decode( $_COOKIE['e2e-filters'], true ); | ||
|
||
if ( ! is_array( $filters ) ) { | ||
return; | ||
} | ||
|
||
foreach ( $filters as $hook => $spec ) { | ||
// A priority may be specified as part of the spec, else use the default priority (10). | ||
$priority = isset( $spec['priority'] ) && is_int( $spec['priority'] ) | ||
? $spec['priority'] | ||
: 10; | ||
|
||
// If the spec is not an array, then it is probably intended as the literal value. | ||
if ( ! is_array( $spec ) ) { | ||
$value = $spec; | ||
} elseif ( isset( $spec['value'] ) ) { | ||
$value = $spec['value']; | ||
} | ||
|
||
// If we know the value, we can establish our filter callback. | ||
if ( isset( $value ) ) { | ||
$callback = function () use ( $value ) { | ||
return $value; | ||
}; | ||
} | ||
|
||
// We also support specifying a callback function. | ||
if ( is_array( $spec ) && isset( $spec['callback'] ) && is_string( $spec['callback'] ) ) { | ||
$callback = $spec['callback']; | ||
} | ||
|
||
// Ensure we have a callback, then setup the filter. | ||
if ( isset( $callback ) ) { | ||
add_filter( $hook, $callback, $priority ); | ||
} | ||
} | ||
|
This file contains 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
This file contains 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
This file contains 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,56 @@ | ||
const defaultConfig = require( '../playwright.config' ); | ||
const testURL = new URL( defaultConfig.use.baseURL ); | ||
|
||
/** | ||
* Request that a WordPress filter be established for the specified hook and returning the specified value. | ||
* | ||
* 'Under the hood', this is done by communicating to a server-side plugin via cookies. Therefore, for the server-side | ||
* code to observe the requested filter, you may need to `page.reload()` prior to writing assertions that rely on your | ||
* filter. | ||
* | ||
* @param page | ||
* @param hook | ||
* @param value | ||
* @param priority | ||
*/ | ||
export async function setFilterValue( page, hook, value, priority = 10 ) { | ||
const context = page.context(); | ||
const existingCookies = await context.cookies(); | ||
let filterSpecs = {}; | ||
|
||
for ( const cookie of existingCookies ) { | ||
if ( cookie.name === 'e2e-filters' ) { | ||
filterSpecs = JSON.parse( cookie.value ); | ||
break; | ||
} | ||
} | ||
|
||
filterSpecs[hook] = { | ||
value: value, | ||
priority: priority | ||
}; | ||
|
||
await context.addCookies( [ { | ||
name: 'e2e-filters', | ||
value: JSON.stringify( filterSpecs ), | ||
path: '/', | ||
domain: testURL.hostname | ||
} ] ); | ||
} | ||
|
||
/** | ||
* Clears any server-side filters setup via setFilterValue(). | ||
* | ||
* As with its sister function, this mechanism relies on cookies and therefore a call to `page.reload()` may be required | ||
* before performing further assertions. | ||
* | ||
* @param page | ||
*/ | ||
export async function clearFilters( page ) { | ||
await page.context().addCookies( [ { | ||
name: 'e2e-filters', | ||
value: '', | ||
path: '/', | ||
domain: testURL.hostname | ||
} ] ); | ||
} |
This file contains 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