Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try fixing PHP errors trigger by navigation link block #58069

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 4 additions & 4 deletions packages/block-library/src/navigation-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,11 @@ function register_block_core_navigation_link() {
add_action( 'init', 'register_block_core_navigation_link' );
// Register actions for all post types and taxonomies, to add variations when they are registered.
// All post types/taxonomies registered before register_block_core_navigation_link, will be handled by that function.
add_action( 'registered_post_type', 'block_core_navigation_link_register_post_type_variation', 10, 2 );
add_action( 'registered_taxonomy', 'block_core_navigation_link_register_taxonomy_variation', 10, 3 );
// add_action( 'registered_post_type', 'block_core_navigation_link_register_post_type_variation', 10, 2 );
// add_action( 'registered_taxonomy', 'block_core_navigation_link_register_taxonomy_variation', 10, 3 );
// Handle unregistering of post types and taxonomies and remove the variations.
add_action( 'unregistered_post_type', 'block_core_navigation_link_unregister_post_type_variation' );
add_action( 'unregistered_taxonomy', 'block_core_navigation_link_unregister_taxonomy_variation' );
// add_action( 'unregistered_post_type', 'block_core_navigation_link_unregister_post_type_variation' );
// add_action( 'unregistered_taxonomy', 'block_core_navigation_link_unregister_taxonomy_variation' );

/**
* Register custom post type variations for navigation link on post type registration
Expand Down
77 changes: 0 additions & 77 deletions phpunit/blocks/block-navigation-link-variations-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,6 @@ public function test_navigation_link_variations_custom_post_type() {
$this->assertEquals( 'Custom Book', $variation['title'], 'Variation title is different than the post type label' );
}

/**
* @covers ::block_core_navigation_link_register_post_type_variation
*/
public function test_navigation_link_variations_private_custom_post_type() {
$registry = WP_Block_Type_Registry::get_instance();
$nav_link_block = $registry->get_registered( 'core/navigation-link' );
$this->assertNotEmpty( $nav_link_block->variations, 'Block has no variations' );
$variation = $this->get_variation_by_name( 'private_custom_book', $nav_link_block->variations );
$this->assertEmpty( $variation, 'Block variation for private post type exists.' );
}

/**
* @covers ::block_core_navigation_link_register_taxonomy_variation
*/
Expand All @@ -105,72 +94,6 @@ public function test_navigation_link_variations_custom_taxonomy() {
$this->assertEquals( 'Book Type', $variation['title'], 'Variation title is different than the post type label' );
}

/**
* @covers ::block_core_navigation_link_register_taxonomy_variation
*/
public function test_navigation_link_variations_private_custom_taxonomy() {
$registry = WP_Block_Type_Registry::get_instance();
$nav_link_block = $registry->get_registered( 'core/navigation-link' );
$this->assertNotEmpty( $nav_link_block->variations, 'Block has no variations' );
$variation = $this->get_variation_by_name( 'private_book_type', $nav_link_block->variations );
$this->assertEmpty( $variation, 'Block variation for private taxonomy exists.' );
}

/**
* @covers ::block_core_navigation_link_unregister_post_type_variation
*/
public function test_navigation_link_variations_unregister_post_type() {
register_post_type(
'temp_custom_book',
array(
'labels' => array(
'item_link' => 'Custom Book',
),
'public' => true,
'show_in_rest' => true,
'show_in_nav_menus' => true,
)
);

$registry = WP_Block_Type_Registry::get_instance();
$nav_link_block = $registry->get_registered( 'core/navigation-link' );
$this->assertNotEmpty( $nav_link_block->variations, 'Block has no variations' );
$variation = $this->get_variation_by_name( 'temp_custom_book', $nav_link_block->variations );
$this->assertIsArray( $variation, 'Block variation does not exist' );

unregister_post_type( 'temp_custom_book' );

$variation = $this->get_variation_by_name( 'temp_custom_book', $nav_link_block->variations );
$this->assertEmpty( $variation, 'Block variation still exists' );
}

/**
* @covers ::block_core_navigation_link_unregister_taxonomy_variation
*/
public function test_navigation_link_variations_unregister_taxonomy() {
register_taxonomy(
'temp_book_type',
'custom_book',
array(
'labels' => array(
'item_link' => 'Book Type',
),
'show_in_nav_menus' => true,
)
);

$registry = WP_Block_Type_Registry::get_instance();
$nav_link_block = $registry->get_registered( 'core/navigation-link' );
$this->assertNotEmpty( $nav_link_block->variations, 'Block has no variations' );
$variation = $this->get_variation_by_name( 'temp_book_type', $nav_link_block->variations );
$this->assertIsArray( $variation, 'Block variation does not exist' );

unregister_taxonomy( 'temp_book_type' );

$variation = $this->get_variation_by_name( 'temp_book_type', $nav_link_block->variations );
$this->assertEmpty( $variation, 'Block variation still exists' );
}

/**
* Get a variation by its name from an array of variations.
*
Expand Down
Loading