-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Blocks: Ensure that metadata registered on the server for core block …
…is preserved on the client (#29213) * export metadata, temporary placeholder to not override server values * Add e2e test that ensure that filtered metadata is propagated to the client * Fix issues raised by PHP linter Co-authored-by: Kerry Liu <[email protected]>
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 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,28 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Gutenberg Test Register Block Type Hooks | ||
* Plugin URI: https://github.com/WordPress/gutenberg | ||
* Author: Gutenberg Team | ||
* | ||
* @package gutenberg-test-register-block-type-hooks | ||
*/ | ||
|
||
/** | ||
* Changes the category for the paragraph block. | ||
* | ||
* @param array $metadata Array of metadata for registering a block type. | ||
* | ||
* @return array Filtered metadata for registering a block type. | ||
*/ | ||
function gutenberg_test_block_type_metadata( $metadata ) { | ||
if ( 'core/paragraph' !== $metadata['name'] ) { | ||
return $metadata; | ||
} | ||
|
||
return array_merge( | ||
$metadata, | ||
array( 'category' => 'widgets' ) | ||
); | ||
} | ||
|
||
add_filter( 'block_type_metadata', 'gutenberg_test_block_type_metadata' ); |
32 changes: 32 additions & 0 deletions
32
packages/e2e-tests/specs/editor/plugins/register-block-type-hooks.test.js
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,32 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
activatePlugin, | ||
createNewPost, | ||
deactivatePlugin, | ||
openGlobalBlockInserter, | ||
} from '@wordpress/e2e-test-utils'; | ||
|
||
describe( 'Register block type hooks', () => { | ||
beforeEach( async () => { | ||
await activatePlugin( 'gutenberg-test-register-block-type-hooks' ); | ||
await createNewPost(); | ||
} ); | ||
|
||
afterEach( async () => { | ||
await deactivatePlugin( 'gutenberg-test-register-block-type-hooks' ); | ||
} ); | ||
|
||
it( 'has a custom category for Paragraph block', async () => { | ||
await openGlobalBlockInserter(); | ||
|
||
const widgetsCategory = await page.$( | ||
'.block-editor-block-types-list[aria-label="Widgets"]' | ||
); | ||
|
||
expect( | ||
await widgetsCategory.$( '.editor-block-list-item-paragraph' ) | ||
).toBeDefined(); | ||
} ); | ||
} ); |