Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion backport-changelog/7.1/11712.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
https://github.com/WordPress/wordpress-develop/pull/11712

* https://github.com/WordPress/gutenberg/pull/77911
* https://github.com/WordPress/gutenberg/pull/78613
* https://github.com/WordPress/gutenberg/pull/78613
* https://github.com/WordPress/gutenberg/pull/79434
1 change: 1 addition & 0 deletions lib/compat/wordpress-7.1/classic-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Declares a flag that the Classic block is necessary for the current post.
*
* @since 7.1.0
* @access private
*/
function wp_declare_classic_block_necessary(): void {
/**
Expand Down
67 changes: 67 additions & 0 deletions phpunit/script-loader-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,71 @@ public function test_should_enqueue_stored_styles() {
'Registered styles with handle of "wp-style-engine-my-styles" do not match expected value from the Style Engine store.'
);
}

/**
* Tests that the Classic block is hidden from the inserter by default.
*
* @covers ::wp_declare_classic_block_necessary
*/
public function test_wp_declare_classic_block_necessary_does_nothing_by_default() {
wp_register_script( 'wp-block-library', 'https://example.org/wp-block-library.js' );

wp_declare_classic_block_necessary();

$this->assertFalse(
wp_scripts()->get_data( 'wp-block-library', 'before' ),
'No inline script should be enqueued when the filter is not used.'
);
}

/**
* Tests that the Classic block can be opted into the inserter via the filter.
*
* @covers ::wp_declare_classic_block_necessary
*/
public function test_wp_declare_classic_block_necessary_enqueues_flag_when_filter_enabled() {
wp_register_script( 'wp-block-library', 'https://example.org/wp-block-library.js' );
add_filter( 'wp_classic_block_supports_inserter', '__return_true' );

wp_declare_classic_block_necessary();

$before = wp_scripts()->get_data( 'wp-block-library', 'before' );
$this->assertIsArray(
$before,
'An inline script should be enqueued when the filter opts in.'
);
$this->assertContains(
'window.__needsClassicBlock = true;',
$before,
'The Classic block flag should be added to the wp-block-library inline scripts.'
);
}

/**
* Tests that the current post is passed to the filter.
*
* @covers ::wp_declare_classic_block_necessary
*/
public function test_wp_declare_classic_block_necessary_passes_post_to_filter() {
wp_register_script( 'wp-block-library', 'https://example.org/wp-block-library.js' );

$post_id = self::factory()->post->create();
$GLOBALS['post'] = get_post( $post_id );

$filter_post = false;
add_filter(
'wp_classic_block_supports_inserter',
static function ( $supports_inserter, $post ) use ( &$filter_post ) {
$filter_post = $post;
return $supports_inserter;
},
10,
2
);

wp_declare_classic_block_necessary();

$this->assertInstanceOf( WP_Post::class, $filter_post, 'The post should be passed to the filter.' );
$this->assertSame( $post_id, $filter_post->ID, 'The current post should be passed to the filter.' );
}
}
Loading