From c016b8c233ea96d377b060300eea0b14dcf3aa13 Mon Sep 17 00:00:00 2001 From: Utkarsh Patel Date: Tue, 13 Oct 2026 15:06:42 +0530 Subject: [PATCH 1/2] test(e2e): Add SVG upload and delivery spec Cover the SVG Support feature end to end against a real Cloudinary account: - A valid SVG uploads, syncs, gets a Cloudinary attachment URL, and the front end serves it as image/svg+xml with its content intact. - An SVG with an inline diff --git a/tests/e2e/fixtures/svg-valid.svg b/tests/e2e/fixtures/svg-valid.svg new file mode 100644 index 000000000..328da1aa7 --- /dev/null +++ b/tests/e2e/fixtures/svg-valid.svg @@ -0,0 +1,2 @@ + + From d11f82b31837b71d6d8b32ef4577dc68a47b6196 Mon Sep 17 00:00:00 2001 From: Utkarsh Patel Date: Tue, 13 Oct 2026 15:24:46 +0530 Subject: [PATCH 2/2] test(e2e): Pin image format and quality in SVG spec The analytics specs flip image_format to webp and image_quality to 80 and leave them changed. With a fixed global format, the first render after sync delivers an SVG as f_webp without fl_sanitize, because Media::get_cloudinary_id() replaces the extension with the global format. CI ran the analytics specs first, so both SVG tests got image/webp. Pin both settings to auto for the spec and restore the previous values afterwards. --- tests/e2e/cloudinary-svg-delivery.spec.js | 60 +++++++++++++++++------ 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/tests/e2e/cloudinary-svg-delivery.spec.js b/tests/e2e/cloudinary-svg-delivery.spec.js index f99dda704..7d86990ef 100644 --- a/tests/e2e/cloudinary-svg-delivery.spec.js +++ b/tests/e2e/cloudinary-svg-delivery.spec.js @@ -15,8 +15,27 @@ const { wpCli, wpEvalFile } = require( './utils/wizard' ); const VALID_FIXTURE = path.join( __dirname, 'fixtures', 'svg-valid.svg' ); const UNSAFE_FIXTURE = path.join( __dirname, 'fixtures', 'svg-unsafe.svg' ); +/** + * Settings the spec depends on. + * + * `image_format` and `image_quality` are pinned because the analytics specs + * flip them and leave them changed. With a fixed global format such as + * `webp`, the first render after sync delivers the SVG as `f_webp` without + * `fl_sanitize`, because `Media::get_cloudinary_id()` swaps the extension + * for the global format. + * + * @type {Record} + */ +const SETTINGS = { + svg_support: 'on', + image_format: 'auto', + image_quality: 'auto', +}; + let cloudName; -let previousSvgSupport; + +/** @type {Record|null} */ +let previousSettings = null; /** * Attachments and posts created by the current test, removed in afterEach. @@ -26,21 +45,29 @@ let previousSvgSupport; let createdIds = []; /** - * Read or write the plugin's `svg_support` setting. + * Save plugin settings and return their previous values. * - * Goes through the settings API rather than `wp option patch` so the value - * lands in the same place the settings screen saves it. + * Goes through the settings API rather than `wp option patch` so the values + * land in the same place the settings screen saves them. * - * @param {string} [value] `on` or `off`. Omit to only read. - * @return {string} The value before the write. + * @param {Record} values Setting slug to value. + * @return {Record} Setting slug to the value before the write. */ -function svgSupport( value ) { - const write = value ? `$setting->save_value( '${ value }' );` : ''; - return wpEvalFile( ` - $setting = get_plugin_instance()->settings->get_setting( 'svg_support' ); - echo $setting->get_value(); - ${ write } - ` ); +function saveSettings( values ) { + return JSON.parse( + wpEvalFile( ` + $settings = get_plugin_instance()->settings; + $previous = array(); + foreach ( json_decode( '${ JSON.stringify( + values + ) }', true ) as $slug => $value ) { + $setting = $settings->get_setting( $slug ); + $previous[ $slug ] = $setting->get_value(); + $setting->save_value( $value ); + } + echo wp_json_encode( $previous ); + ` ) + ); } /** @@ -169,12 +196,13 @@ test.describe( 'Cloudinary SVG upload and delivery', { tag: '@serial' }, () => { // SVG support is off by default. Without it WordPress rejects the // upload and the plugin does not sync or sanitize SVGs. - previousSvgSupport = svgSupport( 'on' ); + previousSettings = saveSettings( SETTINGS ); } ); test.afterAll( () => { - if ( previousSvgSupport ) { - svgSupport( previousSvgSupport ); + if ( previousSettings ) { + saveSettings( previousSettings ); + previousSettings = null; } } );