Skip to content

Commit

Permalink
Add regression E2E test for the bug that caused some wp_options to ge…
Browse files Browse the repository at this point in the history
…t corrupted data (#32797)

* Manually revert the relevant portions of #32229 in order to reproduce the wp_option data corruption bug

* Test regression for settings update corrupting some wp_options

* Cleanup

* Revert "Manually revert the relevant portions of #32229 in order to reproduce the wp_option data corruption bug"

This reverts commit 17eb33b.

* Add comment to remind us that to eventually add a similar test to core
  • Loading branch information
fullofcaffeine authored Jun 26, 2021
1 parent afee31e commit 0ad973b
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/e2e-tests/specs/misc/settings.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* WordPress dependencies
*/
import { visitAdminPage } from '@wordpress/e2e-test-utils';

async function getOptionsValues( selector ) {
await visitAdminPage( 'options.php' );
return page.evaluate( ( theSelector ) => {
const inputs = Array.from( document.querySelectorAll( theSelector ) );
return inputs.reduce( ( memo, input ) => {
memo[ input.id ] = input.value;
return memo;
}, {} );
}, selector );
}

// It might make sense to include a similar test in WP core (or move this one over).
// See discussion here: https://github.com/WordPress/gutenberg/pull/32797#issuecomment-864192088.
describe( 'Settings', () => {
test( 'Regression: updating a specific option will only change its value and will not corrupt others', async () => {
// We won't select the option that we updated and will also remove some
// _transient options that seem to change at every update.
const optionsInputsSelector =
'form#all-options table.form-table input:not([id*="_transient"]):not([id="blogdescription"])';
const optionsBefore = await getOptionsValues( optionsInputsSelector );

await visitAdminPage( 'options-general.php' );
await page.type(
'input#blogdescription',
'Just another Gutenberg site'
);
await page.click( 'input#submit' );

const optionsAfter = await getOptionsValues( optionsInputsSelector );

Object.entries( optionsBefore ).forEach( ( optionBefore ) => {
const [ id ] = optionBefore;
const optionAfter = [ id, optionsAfter[ id ] ];
expect( optionAfter ).toStrictEqual( optionBefore );
} );
} );
} );

0 comments on commit 0ad973b

Please sign in to comment.