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

Rest API: rename navigation fallback classes from WP_ to Gutenberg_ #51959

Merged
merged 5 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* WP_Classic_To_Block_Menu_Converter class
* Gutenberg_Classic_To_Block_Menu_Converter class
*
* @package gutenberg
* @since 6.3.0
Expand All @@ -11,7 +11,7 @@
*
* @access public
*/
class WP_Classic_To_Block_Menu_Converter {
class Gutenberg_Classic_To_Block_Menu_Converter {

/**
* Converts a Classic Menu to blocks.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* WP_Navigation_Fallback_Gutenberg class
* Gutenberg_Navigation_Fallback class
*
* Manages fallback behavior for Navigation menus.
*
Expand All @@ -9,17 +9,12 @@
* @since 6.3.0
*/

/**
* Import dependencies.
*/
require __DIR__ . '/class-wp-classic-to-block-menu-converter.php';

/**
* Manages fallback behavior for Navigation menus.
*
* @access public
*/
class WP_Navigation_Fallback_Gutenberg {
class Gutenberg_Navigation_Fallback {

/**
* Gets (and/or creates) an appropriate fallback Navigation Menu.
Expand Down Expand Up @@ -92,7 +87,7 @@ private static function create_classic_menu_fallback() {
}

// If there is a classic menu then convert it to blocks.
$classic_nav_menu_blocks = WP_Classic_To_Block_Menu_Converter::convert( $classic_nav_menu );
$classic_nav_menu_blocks = Gutenberg_Classic_To_Block_Menu_Converter::convert( $classic_nav_menu );

if ( empty( $classic_nav_menu_blocks ) ) {
return new WP_Error( 'cannot_convert_classic_menu', __( 'Unable to convert Classic Menu to blocks.', 'gutenberg' ) );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* WP_REST_Navigation_Fallback_Controller class
* Gutenberg_REST_Navigation_Fallback_Controller class
*
* REST Controller to create/fetch a fallback Navigation Menu.
*
Expand All @@ -9,15 +9,10 @@
* @since 6.3.0
*/

/**
* Import dependencies.
*/
require __DIR__ . '/class-wp-navigation-fallback-gutenberg.php';

/**
* REST Controller to fetch a fallback Navigation Block Menu. If needed it creates one.
*/
class WP_REST_Navigation_Fallback_Controller extends WP_REST_Controller {
class Gutenberg_REST_Navigation_Fallback_Controller extends WP_REST_Controller {

/**
* The Post Type for the Controller
Expand Down Expand Up @@ -98,7 +93,7 @@ public function get_item_permissions_check( $request ) {
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_item( $request ) {
$post = WP_Navigation_Fallback_Gutenberg::get_fallback();
$post = Gutenberg_Navigation_Fallback::get_fallback();

if ( empty( $post ) ) {
return rest_ensure_response( new WP_Error( 'no_fallback_menu', __( 'No fallback menu found.', 'gutenberg' ), array( 'status' => 404 ) ) );
Expand Down
10 changes: 10 additions & 0 deletions lib/compat/wordpress-6.3/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,13 @@ function gutenberg_register_rest_block_patterns() {
$block_patterns->register_routes();
}
add_action( 'rest_api_init', 'gutenberg_register_rest_block_patterns' );


/**
* Registers the Navigation Fallbacks REST API routes.
*/
function gutenberg_register_rest_navigation_fallbacks() {
$editor_settings = new Gutenberg_REST_Navigation_Fallback_Controller();
$editor_settings->register_routes();
}
add_action( 'rest_api_init', 'gutenberg_register_rest_navigation_fallbacks' );
10 changes: 0 additions & 10 deletions lib/experimental/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ function gutenberg_register_block_editor_settings() {
add_action( 'rest_api_init', 'gutenberg_register_block_editor_settings' );


/**
* Registers the Navigation Fallbacks REST API routes.
*/
function gutenberg_register_rest_navigation_fallbacks() {
$editor_settings = new WP_REST_Navigation_Fallback_Controller();
$editor_settings->register_routes();
}
add_action( 'rest_api_init', 'gutenberg_register_rest_navigation_fallbacks' );


/**
* Shim for get_sample_permalink() to add support for auto-draft status.
*
Expand Down
4 changes: 3 additions & 1 deletion lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ function gutenberg_is_experiment_enabled( $name ) {
require_once __DIR__ . '/compat/wordpress-6.3/class-gutenberg-rest-templates-controller-6-3.php';
require_once __DIR__ . '/compat/wordpress-6.3/class-gutenberg-rest-global-styles-controller-6-3.php';
require_once __DIR__ . '/compat/wordpress-6.3/class-gutenberg-rest-global-styles-revisions-controller-6-3.php';
require_once __DIR__ . '/compat/wordpress-6.3/class-wp-rest-navigation-fallback-controller.php';
require_once __DIR__ . '/compat/wordpress-6.3/class-gutenberg-classic-to-block-menu-converter.php';
require_once __DIR__ . '/compat/wordpress-6.3/class-gutenberg-navigation-fallback.php';
require_once __DIR__ . '/compat/wordpress-6.3/class-gutenberg-rest-navigation-fallback-controller.php';
require_once __DIR__ . '/compat/wordpress-6.3/rest-api.php';
require_once __DIR__ . '/compat/wordpress-6.3/theme-previews.php';
require_once __DIR__ . '/compat/wordpress-6.3/navigation-block-preloading.php';
Expand Down
12 changes: 6 additions & 6 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ function block_core_navigation_get_fallback_blocks() {
// If `core/page-list` is not registered then return empty blocks.
$fallback_blocks = $registry->is_registered( 'core/page-list' ) ? $page_list_fallback : array();

$navigation_post = WP_Navigation_Fallback_Gutenberg::get_fallback();
$navigation_post = Gutenberg_Navigation_Fallback::get_fallback();

// Use the first non-empty Navigation as fallback if available.
if ( $navigation_post ) {
Expand Down Expand Up @@ -846,7 +846,7 @@ function block_core_navigation_typographic_presets_backcompatibility( $parsed_bl
*/
function block_core_navigation_parse_blocks_from_menu_items( $menu_items, $menu_items_by_parent_id ) {

_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback_Gutenberg::parse_blocks_from_menu_items' );
_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback::parse_blocks_from_menu_items' );
ramonjd marked this conversation as resolved.
Show resolved Hide resolved

if ( empty( $menu_items ) ) {
return array();
Expand Down Expand Up @@ -895,7 +895,7 @@ function block_core_navigation_parse_blocks_from_menu_items( $menu_items, $menu_
*/
function block_core_navigation_get_classic_menu_fallback() {

_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback_Gutenberg::get_classic_menu_fallback' );
_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback::get_classic_menu_fallback' );
ramonjd marked this conversation as resolved.
Show resolved Hide resolved

$classic_nav_menus = wp_get_nav_menus();

Expand Down Expand Up @@ -938,7 +938,7 @@ static function( $a, $b ) {
*/
function block_core_navigation_get_classic_menu_fallback_blocks( $classic_nav_menu ) {

_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback_Gutenberg::get_classic_menu_fallback_blocks' );
_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback::get_classic_menu_fallback_blocks' );
ramonjd marked this conversation as resolved.
Show resolved Hide resolved

// BEGIN: Code that already exists in wp_nav_menu().
$menu_items = wp_get_nav_menu_items( $classic_nav_menu->term_id, array( 'update_post_term_cache' => false ) );
Expand Down Expand Up @@ -977,7 +977,7 @@ function block_core_navigation_get_classic_menu_fallback_blocks( $classic_nav_me
*/
function block_core_navigation_maybe_use_classic_menu_fallback() {

_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback_Gutenberg::create_classic_menu_fallback' );
_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback::create_classic_menu_fallback' );
ramonjd marked this conversation as resolved.
Show resolved Hide resolved

// See if we have a classic menu.
$classic_nav_menu = block_core_navigation_get_classic_menu_fallback();
Expand Down Expand Up @@ -1020,7 +1020,7 @@ function block_core_navigation_maybe_use_classic_menu_fallback() {
*/
function block_core_navigation_get_most_recently_published_navigation() {

_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback_Gutenberg::get_most_recently_published_navigation' );
_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback::get_most_recently_published_navigation' );
ramonjd marked this conversation as resolved.
Show resolved Hide resolved

// Default to the most recently created menu.
$parsed_args = array(
Expand Down
16 changes: 8 additions & 8 deletions phpunit/class-wp-classic-to-block-menu-converter-test.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?php
/**
* Tests WP_Classic_To_Block_Menu_Converter_Test
* Tests Gutenberg_Classic_To_Block_Menu_Converter
*
* @package WordPress
*/

/**
* Tests for the WP_Classic_To_Block_Menu_Converter_Test class.
* Tests for the Gutenberg_Classic_To_Block_Menu_Converter_Test class.
*/
class WP_Classic_To_Block_Menu_Converter_Test extends WP_UnitTestCase {
class Gutenberg_Classic_To_Block_Menu_Converter_Test extends WP_UnitTestCase {

/**
* @covers WP_Classic_To_Block_Menu_Converter::get_fallback
*/
public function test_class_exists() {
$this->assertTrue( class_exists( 'WP_Classic_To_Block_Menu_Converter' ) );
$this->assertTrue( class_exists( 'Gutenberg_Classic_To_Block_Menu_Converter' ) );
}

/**
Expand All @@ -23,7 +23,7 @@ public function test_class_exists() {
*/
public function test_passing_non_menu_object_to_converter_returns_wp_error( $data ) {

$result = WP_Classic_To_Block_Menu_Converter::convert( $data );
$result = Gutenberg_Classic_To_Block_Menu_Converter::convert( $data );

$this->assertTrue( is_wp_error( $result ), 'Should be a WP_Error instance' );

Expand Down Expand Up @@ -88,7 +88,7 @@ public function test_can_convert_classic_menu_to_blocks() {

$classic_nav_menu = wp_get_nav_menu_object( $menu_id );

$blocks = WP_Classic_To_Block_Menu_Converter::convert( $classic_nav_menu );
$blocks = Gutenberg_Classic_To_Block_Menu_Converter::convert( $classic_nav_menu );

$this->assertNotEmpty( $blocks );

Expand Down Expand Up @@ -179,7 +179,7 @@ public function test_does_not_convert_menu_items_with_non_publish_status() {

$classic_nav_menu = wp_get_nav_menu_object( $menu_id );

$blocks = WP_Classic_To_Block_Menu_Converter::convert( $classic_nav_menu );
$blocks = Gutenberg_Classic_To_Block_Menu_Converter::convert( $classic_nav_menu );

$this->assertNotEmpty( $blocks );

Expand All @@ -204,7 +204,7 @@ public function test_returns_empty_array_for_menus_with_no_items() {

$classic_nav_menu = wp_get_nav_menu_object( $menu_id );

$blocks = WP_Classic_To_Block_Menu_Converter::convert( $classic_nav_menu );
$blocks = Gutenberg_Classic_To_Block_Menu_Converter::convert( $classic_nav_menu );

$this->assertEmpty( $blocks, 'Result should be empty.' );

Expand Down
30 changes: 15 additions & 15 deletions phpunit/class-wp-navigation-fallback-gutenberg-test.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
/**
* Tests WP_Navigation_Fallback_Gutenberg
* Tests Gutenberg_Navigation_Fallback
*
* @package WordPress
*/

/**
* Tests for the WP_Navigation_Fallback_Gutenberg class.
* Tests for the Gutenberg_Navigation_Fallback class.
*/
class WP_Navigation_Fallback_Gutenberg_Test extends WP_UnitTestCase {
class Gutenberg_Navigation_Fallback_Test extends WP_UnitTestCase {

protected static $admin_user;
protected static $editor_user;
Expand All @@ -29,15 +29,15 @@ public function set_up() {
* @covers WP_REST_Navigation_Fallback_Controller
*/
public function test_it_exists() {
$this->assertTrue( class_exists( 'WP_Navigation_Fallback_Gutenberg' ), 'WP_Navigation_Fallback_Gutenberg class should exist.' );
$this->assertTrue( class_exists( 'Gutenberg_Navigation_Fallback' ), 'Gutenberg_Navigation_Fallback class should exist.' );
}


/**
* @covers WP_REST_Navigation_Fallback_Controller::get_fallback
*/
public function test_should_return_a_default_fallback_navigation_menu_in_absence_of_other_fallbacks() {
$data = WP_Navigation_Fallback_Gutenberg::get_fallback();
$data = Gutenberg_Navigation_Fallback::get_fallback();

$this->assertInstanceOf( 'WP_Post', $data, 'Response should be of the correct type.' );

Expand All @@ -63,7 +63,7 @@ public function test_should_return_a_default_fallback_navigation_menu_with_no_bl

unregister_block_type( 'core/page-list' );

$data = WP_Navigation_Fallback_Gutenberg::get_fallback();
$data = Gutenberg_Navigation_Fallback::get_fallback();

$this->assertInstanceOf( 'WP_Post', $data, 'Response should be of the correct type.' );

Expand All @@ -79,11 +79,11 @@ public function test_should_return_a_default_fallback_navigation_menu_with_no_bl
*/
public function test_should_handle_consecutive_invocations() {
// Invoke the method multiple times to ensure that it doesn't create a new fallback menu on each invocation.
WP_Navigation_Fallback_Gutenberg::get_fallback();
WP_Navigation_Fallback_Gutenberg::get_fallback();
Gutenberg_Navigation_Fallback::get_fallback();
Gutenberg_Navigation_Fallback::get_fallback();

// Assert on the final invocation.
$data = WP_Navigation_Fallback_Gutenberg::get_fallback();
$data = Gutenberg_Navigation_Fallback::get_fallback();

$this->assertInstanceOf( 'WP_Post', $data, 'Response should be of the correct type.' );

Expand Down Expand Up @@ -115,7 +115,7 @@ public function test_should_return_the_most_recently_created_navigation_menu() {
)
);

$data = WP_Navigation_Fallback_Gutenberg::get_fallback();
$data = Gutenberg_Navigation_Fallback::get_fallback();

$this->assertInstanceOf( 'WP_Post', $data, 'Response should be of the correct type.' );

Expand Down Expand Up @@ -147,7 +147,7 @@ public function test_should_return_fallback_navigation_from_existing_classic_men
)
);

$data = WP_Navigation_Fallback_Gutenberg::get_fallback();
$data = Gutenberg_Navigation_Fallback::get_fallback();

$this->assertInstanceOf( 'WP_Post', $data, 'Response should be of the correct type.' );

Expand Down Expand Up @@ -201,7 +201,7 @@ public function test_should_prioritise_fallback_to_classic_menu_in_primary_locat
$locations['header'] = $another_menu_id;
set_theme_mod( 'nav_menu_locations', $locations );

$data = WP_Navigation_Fallback_Gutenberg::get_fallback();
$data = Gutenberg_Navigation_Fallback::get_fallback();

$this->assertInstanceOf( 'WP_Post', $data, 'Response should be of the correct type.' );

Expand Down Expand Up @@ -238,7 +238,7 @@ public function test_should_fallback_to_classic_menu_with_primary_slug() {
)
);

$data = WP_Navigation_Fallback_Gutenberg::get_fallback();
$data = Gutenberg_Navigation_Fallback::get_fallback();

$this->assertInstanceOf( 'WP_Post', $data, 'Response should be of the correct type.' );

Expand Down Expand Up @@ -275,7 +275,7 @@ public function test_should_fallback_to_most_recently_created_classic_menu() {
)
);

$data = WP_Navigation_Fallback_Gutenberg::get_fallback();
$data = Gutenberg_Navigation_Fallback::get_fallback();

$this->assertInstanceOf( 'WP_Post', $data, 'Response should be of the correct type.' );

Expand Down Expand Up @@ -306,7 +306,7 @@ public function test_should_not_create_fallback_from_classic_menu_if_a_navigatio
)
);

$data = WP_Navigation_Fallback_Gutenberg::get_fallback();
$data = Gutenberg_Navigation_Fallback::get_fallback();

$this->assertInstanceOf( 'WP_Post', $data, 'Response should be of the correct type.' );

Expand Down
4 changes: 2 additions & 2 deletions phpunit/class-wp-rest-navigation-fallback-controller-test.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Unit tests covering WP_REST_Navigation_Fallback_Controller functionality.
* Unit tests covering Gutenberg_REST_Navigation_Fallback_Controller functionality.
*
* Note: that these tests are designed to provide high level coverage only. The majority of the tests
* are made directly against the WP_Navigation_Fallback_Gutenberg class as this:
Expand All @@ -16,7 +16,7 @@
* @group restapi
* @group navigation
*/
class WP_REST_Navigation_Fallback_Controller_Test extends WP_Test_REST_Controller_Testcase {
class Gutenberg_REST_Navigation_Fallback_Controller_Test extends WP_Test_REST_Controller_Testcase {

protected static $admin_user;
protected static $editor_user;
Expand Down