Skip to content

Commit

Permalink
Try fixing block context e2e test failure (#52513)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Jul 11, 2023
1 parent 83f3fbc commit 34c805d
Showing 1 changed file with 9 additions and 13 deletions.
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

0 comments on commit 34c805d

Please sign in to comment.