From cdecc9f1ce2a5fa384affbcc870ee2c4bde9162f Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Wed, 24 Apr 2019 08:30:36 -0400 Subject: [PATCH] Reusable Blocks: Preload user permissions (#15061) * Reusable Blocks: Preload user permissions * Testing: Unskip block deletion test See https://github.com/WordPress/gutenberg/pull/15059#issuecomment-484647474 --- lib/client-assets.php | 29 +++++++++++++++++++ .../e2e-tests/specs/block-deletion.test.js | 2 +- phpunit/class-extend-preload-paths-test.php | 26 +++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 phpunit/class-extend-preload-paths-test.php diff --git a/lib/client-assets.php b/lib/client-assets.php index 419c4131c98e8..d9fcc8105249b 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -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' ); diff --git a/packages/e2e-tests/specs/block-deletion.test.js b/packages/e2e-tests/specs/block-deletion.test.js index a5dc9bb9c4475..fb975fb61e88c 100644 --- a/packages/e2e-tests/specs/block-deletion.test.js +++ b/packages/e2e-tests/specs/block-deletion.test.js @@ -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' ); diff --git a/phpunit/class-extend-preload-paths-test.php b/phpunit/class-extend-preload-paths-test.php new file mode 100644 index 0000000000000..5d683b87204a9 --- /dev/null +++ b/phpunit/class-extend-preload-paths-test.php @@ -0,0 +1,26 @@ +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 ); + } +}