Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try fixing block context e2e test failure #52513

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions packages/e2e-tests/plugins/block-context.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
*/

/**
* Enqueues a custom script for the plugin.
* Registers plugin test context blocks.
*/
function gutenberg_test_enqueue_block_context_script() {
wp_enqueue_script(
function gutenberg_test_register_context_blocks() {
wp_register_script(
'gutenberg-test-block-context',
plugins_url( 'block-context/index.js', __FILE__ ),
array(
Expand All @@ -22,37 +22,32 @@ function gutenberg_test_enqueue_block_context_script() {
filemtime( plugin_dir_path( __FILE__ ) . 'block-context/index.js' ),
true
);
}
add_action( 'init', 'gutenberg_test_enqueue_block_context_script' );

/**
* Registers plugin test context blocks.
*/
function gutenberg_test_register_context_blocks() {
register_block_type(
'gutenberg/test-context-provider',
array(
'attributes' => array(
'attributes' => array(
'recordId' => array(
'type' => 'number',
'default' => 0,
),
),
'provides_context' => array(
'provides_context' => array(
'gutenberg/recordId' => 'recordId',
),
'editor_script_handles' => array( 'gutenberg-test-block-context' ),
)
);

register_block_type(
'gutenberg/test-context-consumer',
array(
'uses_context' => array(
'uses_context' => array(
'gutenberg/recordId',
'postId',
'postType',
),
'render_callback' => static function( $attributes, $content, $block ) {
'render_callback' => static function( $attributes, $content, $block ) {
$ordered_context = array(
$block->context['gutenberg/recordId'],
$block->context['postId'],
Expand All @@ -61,6 +56,7 @@ function gutenberg_test_register_context_blocks() {

return implode( ',', $ordered_context );
},
'editor_script_handles' => array( 'gutenberg-test-block-context' ),
)
);
}
Expand Down