Skip to content

Commit

Permalink
Navigation Link: Remove unit test code for < WP 6.5
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed Feb 6, 2025
1 parent 3f0a805 commit 54cefa8
Showing 1 changed file with 0 additions and 98 deletions.
98 changes: 0 additions & 98 deletions phpunit/blocks/block-navigation-link-variations-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
*/
class Block_Navigation_Link_Variations_Test extends WP_UnitTestCase {

/**
* Whether to use a shim/workaround for WordPress Core versions < 6.5.
* See https://github.com/WordPress/gutenberg/pull/58389 for details.
*
* @var bool
*/
private $pre_65_compat = false;

public function set_up() {
parent::set_up();

Expand Down Expand Up @@ -66,22 +58,6 @@ public function set_up() {
'show_in_nav_menus' => false,
)
);

$this->pre_65_compat = ! method_exists( 'WP_Block_Type', 'get_variations' );

/*
* In Core versions < 6.5, variations for post types/taxonomies registered after init#10 (= after the block type was registered)
* need to be manually registered.
* set_up runs after init#10, therefore register the variations here with the old deprecated functions.
*
* TODO: After two WP versions (6.7), we can remove this.
*/
if ( $this->pre_65_compat ) {
$this->handle_pre_65_post_type_variation_registration( $post_type );
$this->handle_pre_65_post_type_variation_registration( $private_post_type );
$this->handle_pre_65_taxonomy_variation_registration( $taxonomy );
$this->handle_pre_65_taxonomy_variation_registration( $private_taxonomoy );
}
}

public function tear_down() {
Expand All @@ -92,16 +68,6 @@ public function tear_down() {
unregister_post_type( 'temp_custom_book' );
unregister_taxonomy( 'temp_book_type' );

// See comment in set_up for explanation.
if ( $this->pre_65_compat ) {
$this->handle_pre_65_post_type_variation_unregistration( 'custom_book' );
$this->handle_pre_65_post_type_variation_unregistration( 'private_custom_book' );
$this->handle_pre_65_post_type_variation_unregistration( 'temp_custom_book' );
$this->handle_pre_65_taxonomy_variation_unregistration( 'book_type' );
$this->handle_pre_65_taxonomy_variation_unregistration( 'private_book_type' );
$this->handle_pre_65_taxonomy_variation_unregistration( 'temp_book_type' );
}

parent::tear_down();
}

Expand Down Expand Up @@ -177,10 +143,6 @@ public function test_navigation_link_variations_unregister_post_type() {
)
);

if ( $this->pre_65_compat ) {
$this->handle_pre_65_post_type_variation_registration( $post_type );
}

$registry = WP_Block_Type_Registry::get_instance();
$nav_link_block = $registry->get_registered( 'core/navigation-link' );
// Use property and let __get handle it, so it works for core versions before adding get_variations as well
Expand All @@ -191,10 +153,6 @@ public function test_navigation_link_variations_unregister_post_type() {

unregister_post_type( $post_type->name );

if ( $this->pre_65_compat ) {
$this->handle_pre_65_post_type_variation_unregistration( $post_type->name );
}

// Update array, since it's an dynamic built array
$variations = $nav_link_block->variations;
$variation = $this->get_variation_by_name( 'temp_custom_book', $variations );
Expand All @@ -216,10 +174,6 @@ public function test_navigation_link_variations_unregister_taxonomy() {
)
);

if ( $this->pre_65_compat ) {
$this->handle_pre_65_taxonomy_variation_registration( $taxonomy );
}

$registry = WP_Block_Type_Registry::get_instance();
$nav_link_block = $registry->get_registered( 'core/navigation-link' );
// Use property and let __get handle it, so it works for core versions before adding get_variations as well
Expand All @@ -230,10 +184,6 @@ public function test_navigation_link_variations_unregister_taxonomy() {

unregister_taxonomy( $taxonomy->name );

if ( $this->pre_65_compat ) {
$this->handle_pre_65_taxonomy_variation_unregistration( $taxonomy->name );
}

// Update array, since it's an dynamic built array
$variations = $nav_link_block->variations;
$variation = $this->get_variation_by_name( 'temp_book_type', $variations );
Expand All @@ -257,52 +207,4 @@ private function get_variation_by_name( $variation_name, $variations ) {

return $found_variation;
}

/**
* Registers a block variation for a post type with the deprecated methods for Core versions < 6.5.
* See comment in set_up for dexplanation.
*
* @param WP_Post_Type $post_type
*/
private function handle_pre_65_post_type_variation_registration( $post_type ) {
$this->setExpectedDeprecated( 'gutenberg_block_core_navigation_link_register_post_type_variation' );
$this->setExpectedDeprecated( 'gutenberg_block_core_navigation_link_register_variation' );
gutenberg_block_core_navigation_link_register_post_type_variation( $post_type->name, $post_type );
}

/**
* Unregisters a block variation for a post type with the deprecated methods for Core versions < 6.5.
* See comment in set_up for dexplanation.
*
* @param string $post_type
*/
private function handle_pre_65_post_type_variation_unregistration( $post_type ) {
$this->setExpectedDeprecated( 'gutenberg_block_core_navigation_link_unregister_post_type_variation' );
$this->setExpectedDeprecated( 'gutenberg_block_core_navigation_link_unregister_variation' );
gutenberg_block_core_navigation_link_unregister_post_type_variation( $post_type );
}

/**
* Registers a block variation for a taxonomy with the deprecated methods for Core versions < 6.5.
* See comment in set_up for dexplanation.
*
* @param WP_Taxonomy $post_type
*/
private function handle_pre_65_taxonomy_variation_registration( $taxonomy ) {
$this->setExpectedDeprecated( 'gutenberg_block_core_navigation_link_register_taxonomy_variation' );
$this->setExpectedDeprecated( 'gutenberg_block_core_navigation_link_register_variation' );
gutenberg_block_core_navigation_link_register_taxonomy_variation( $taxonomy->name, $taxonomy->object_type, (array) $taxonomy );
}

/**
* Unregisters a block variation for a taxonomy with the deprecated methods for Core versions < 6.5.
* See comment in set_up for dexplanation.
*
* @param string $post_type
*/
private function handle_pre_65_taxonomy_variation_unregistration( $taxonomy ) {
$this->setExpectedDeprecated( 'gutenberg_block_core_navigation_link_unregister_taxonomy_variation' );
$this->setExpectedDeprecated( 'gutenberg_block_core_navigation_link_unregister_variation' );
gutenberg_block_core_navigation_link_unregister_taxonomy_variation( $taxonomy );
}
}

0 comments on commit 54cefa8

Please sign in to comment.