Block Editor: Add helper functions for displaying the editor.

`use_block_editor_for_post()` and `use_block_editor_for_post_type()` determine if the block editor should be loaded.

`get_block_categories()` and `get_block_editor_server_block_settings()` provide data be included while the block editor is loading.

Props pento.

Merges [43762] to trunk.

See #45110.

git-svn-id: https://develop.svn.wordpress.org/trunk@44122 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers
2018-12-13 20:22:06 +00:00
parent 09b9302705
commit ab070e219b
2 changed files with 192 additions and 0 deletions
@@ -750,4 +750,53 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
$this->assertSame( $p, post_exists( $title, $content, $date ) );
}
function test_use_block_editor_for_post() {
$this->assertFalse( use_block_editor_for_post( -1 ) );
$bogus_post_id = $this->factory()->post->create(
array(
'post_type' => 'bogus',
)
);
$this->assertFalse( use_block_editor_for_post( $bogus_post_id ) );
register_post_type(
'restless',
array(
'show_in_rest' => false,
)
);
$restless_post_id = $this->factory()->post->create(
array(
'post_type' => 'restless',
)
);
$this->assertFalse( use_block_editor_for_post( $restless_post_id ) );
$generic_post_id = $this->factory()->post->create();
add_filter( 'use_block_editor_for_post', '__return_false' );
$this->assertFalse( use_block_editor_for_post( $generic_post_id ) );
remove_filter( 'use_block_editor_for_post', '__return_false' );
add_filter( 'use_block_editor_for_post', '__return_true' );
$this->assertTrue( use_block_editor_for_post( $restless_post_id ) );
remove_filter( 'use_block_editor_for_post', '__return_true' );
}
function test_get_block_editor_server_block_settings() {
$name = 'core/test';
$settings = array(
'icon' => 'text',
'render_callback' => 'foo',
);
register_block_type( $name, $settings );
$blocks = get_block_editor_server_block_settings();
unregister_block_type( $name );
$this->assertArrayHasKey( $name, $blocks );
$this->assertSame( array( 'icon' => 'text' ), $blocks[ $name ] );
}
}