Skip to content

Commit

Permalink
Reusable Blocks: Preload user permissions (#15061)
Browse files Browse the repository at this point in the history
* Reusable Blocks: Preload user permissions

* Testing: Unskip block deletion test

See #15059 (comment)
  • Loading branch information
aduth committed Apr 24, 2019
1 parent 9db86a8 commit cdecc9f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
29 changes: 29 additions & 0 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,32 @@ function gutenberg_extend_block_editor_styles( $settings ) {
return $settings;
}
add_filter( 'block_editor_settings', 'gutenberg_extend_block_editor_styles' );

/**
* Extends block editor preload paths to preload additional data. Note that any
* additions here should be complemented with a corresponding core ticket to
* reconcile the change upstream for future removal from Gutenberg.
*
* @since 5.6.0
*
* @param array $preload_paths $preload_paths Array of paths to preload.
*
* @return array Filtered array of paths to preload.
*/
function gutenberg_extend_block_editor_preload_paths( $preload_paths ) {
/*
* Used in considering user permissions for creating and updating blocks,
* as condition for displaying relevant actions in the interface.
*
* Trac ticket: https://core.trac.wordpress.org/ticket/46429
*
* This is present in WordPress 5.2 and should be removed from Gutenberg
* once WordPress 5.2 is the minimum supported version.
*/
if ( ! in_array( array( '/wp/v2/blocks', 'OPTIONS' ), $preload_paths ) ) {
$preload_paths[] = array( '/wp/v2/blocks', 'OPTIONS' );
}

return $preload_paths;
}
add_filter( 'block_editor_preload_paths', 'gutenberg_extend_block_editor_preload_paths' );
2 changes: 1 addition & 1 deletion packages/e2e-tests/specs/block-deletion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe( 'block deletion -', () => {
beforeEach( addThreeParagraphsToNewPost );

describe( 'deleting the third block using the Remove Block menu item', () => {
it.skip( 'results in two remaining blocks and positions the caret at the end of the second block', async () => {
it( 'results in two remaining blocks and positions the caret at the end of the second block', async () => {
// The blocks can't be empty to trigger the toolbar
await page.keyboard.type( 'Paragraph to remove' );

Expand Down
26 changes: 26 additions & 0 deletions phpunit/class-extend-preload-paths-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Test `gutenberg_extend_block_editor_preload_paths`.
*
* @package Gutenberg
*/

class Extend_Preload_Paths_Test extends WP_UnitTestCase {
/**
* Tests '/wp/v2/blocks' added if missing.
*/
function test_localizes_script() {
$preload_paths = gutenberg_extend_block_editor_preload_paths( array() );

$this->assertEquals( array( array( '/wp/v2/blocks', 'OPTIONS' ) ), $preload_paths );
}

/**
* Tests '/wp/v2/blocks' not added if present.
*/
function test_replaces_registered_properties() {
$preload_paths = gutenberg_extend_block_editor_preload_paths( array( array( '/wp/v2/blocks', 'OPTIONS' ) ) );

$this->assertEquals( array( array( '/wp/v2/blocks', 'OPTIONS' ) ), $preload_paths );
}
}

0 comments on commit cdecc9f

Please sign in to comment.