Skip to content

Commit

Permalink
Fix upload button on overriden empty image block in patterns (#59169)
Browse files Browse the repository at this point in the history
Co-authored-by: kevin940726 <kevin940726@git.wordpress.org>
Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: talldan <talldanwp@git.wordpress.org>
  • Loading branch information
4 people authored Feb 20, 2024
1 parent ad1c0b4 commit e9980ac
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/compat/wordpress-6.5/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function gutenberg_process_block_bindings( $block_content, $parsed_block, $block
$supported_block_attrs = array(
'core/paragraph' => array( 'content' ),
'core/heading' => array( 'content' ),
'core/image' => array( 'url', 'title', 'alt' ),
'core/image' => array( 'id', 'url', 'title', 'alt' ),
'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ),
);

Expand Down
1 change: 1 addition & 0 deletions packages/patterns/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const PARTIAL_SYNCING_SUPPORTED_BLOCKS = {
rel: __( 'Link Relationship' ),
},
'core/image': {
id: __( 'Image ID' ),
url: __( 'URL' ),
title: __( 'Title' ),
alt: __( 'Alt Text' ),
Expand Down
67 changes: 67 additions & 0 deletions test/e2e/specs/editor/various/pattern-overrides.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

/**
* External dependencies
*/
const path = require( 'path' );

test.describe( 'Pattern Overrides', () => {
test.beforeAll( async ( { requestUtils } ) => {
await Promise.all( [
Expand Down Expand Up @@ -584,4 +589,66 @@ test.describe( 'Pattern Overrides', () => {
await editor.showBlockToolbar();
await expect( resetButton ).toBeDisabled();
} );

// Fix https://github.com/WordPress/gutenberg/issues/58708.
test( 'overridden empty images should not have upload button', async ( {
page,
admin,
requestUtils,
editor,
} ) => {
const imageId = 'image-id';
const TEST_IMAGE_FILE_PATH = path.resolve(
__dirname,
'../../../assets/10x10_e2e_test_image_z9T8jK.png'
);
const { id } = await requestUtils.createBlock( {
title: 'Pattern',
content: `<!-- wp:image {"metadata":{"id":"${ imageId }","bindings":{"id":{"source":"core/pattern-overrides"},"url":{"source":"core/pattern-overrides"},"title":{"source":"core/pattern-overrides"},"alt":{"source":"core/pattern-overrides"}}}} -->
<figure class="wp-block-image"><img alt=""/></figure>
<!-- /wp:image -->`,
status: 'publish',
} );

await admin.createNewPost();

await editor.insertBlock( {
name: 'core/block',
attributes: { ref: id },
} );

const imageBlock = editor.canvas.getByRole( 'document', {
name: 'Block: Image',
} );
await editor.selectBlocks( imageBlock );
await imageBlock
.getByTestId( 'form-file-upload-input' )
.setInputFiles( TEST_IMAGE_FILE_PATH );
await expect( imageBlock.getByRole( 'img' ) ).toHaveCount( 1 );
await expect( imageBlock.getByRole( 'img' ) ).toHaveAttribute(
'src',
/\/wp-content\/uploads\//
);

await editor.publishPost();
await page.reload();

await editor.selectBlocks( imageBlock );
await editor.showBlockToolbar();
const blockToolbar = page.getByRole( 'toolbar', {
name: 'Block tools',
} );
await expect( imageBlock.getByRole( 'img' ) ).toHaveAttribute(
'src',
/\/wp-content\/uploads\//
);
await expect(
blockToolbar.getByRole( 'button', { name: 'Replace' } )
).toBeEnabled();
await expect(
blockToolbar.getByRole( 'button', {
name: 'Upload to Media Library',
} )
).toBeHidden();
} );
} );

1 comment on commit e9980ac

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in e9980ac.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7967683736
📝 Reported issues:

Please sign in to comment.