diff --git a/src/wp-admin/site-editor.php b/src/wp-admin/site-editor.php index b858d7ee53a0f..14eec7c6c1480 100644 --- a/src/wp-admin/site-editor.php +++ b/src/wp-admin/site-editor.php @@ -99,17 +99,8 @@ static function( $classes ) { '/wp/v2/global-styles/' . $active_global_styles_id . '?context=edit', '/wp/v2/global-styles/' . $active_global_styles_id, '/wp/v2/themes/' . $active_theme . '/global-styles', - '/wp/v2/block-navigation-areas?context=edit', ); - $areas = get_option( 'wp_navigation_areas', array() ); - $active_areas = array_intersect_key( $areas, get_navigation_areas() ); - foreach ( $active_areas as $post_id ) { - if ( $post_id ) { - $preload_paths[] = add_query_arg( 'context', 'edit', rest_get_route_for_post( $post_id ) ); - } - } - block_editor_rest_api_preload( $preload_paths, $block_editor_context ); wp_add_inline_script( diff --git a/src/wp-includes/blocks/index.php b/src/wp-includes/blocks/index.php index 3ff63f5738dbe..727c7f313bf8c 100644 --- a/src/wp-includes/blocks/index.php +++ b/src/wp-includes/blocks/index.php @@ -15,7 +15,6 @@ require ABSPATH . WPINC . '/blocks/latest-posts.php'; require ABSPATH . WPINC . '/blocks/legacy-widget.php'; require ABSPATH . WPINC . '/blocks/loginout.php'; -require ABSPATH . WPINC . '/blocks/navigation-area.php'; require ABSPATH . WPINC . '/blocks/navigation-link.php'; require ABSPATH . WPINC . '/blocks/navigation-submenu.php'; require ABSPATH . WPINC . '/blocks/navigation.php'; diff --git a/src/wp-includes/blocks/navigation-area.php b/src/wp-includes/blocks/navigation-area.php deleted file mode 100644 index 65c64428d0c2e..0000000000000 --- a/src/wp-includes/blocks/navigation-area.php +++ /dev/null @@ -1,22 +0,0 @@ - array( - 'navigationArea' => 'area', - ), - ) - ); -} -add_action( 'init', 'register_block_core_navigation_area' ); diff --git a/src/wp-includes/blocks/navigation-area/block.json b/src/wp-includes/blocks/navigation-area/block.json deleted file mode 100644 index 95ad0a513e65b..0000000000000 --- a/src/wp-includes/blocks/navigation-area/block.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "apiVersion": 2, - "name": "core/navigation-area", - "title": "Navigation Area", - "category": "theme", - "description": "Define a navigation area for your theme. The navigation block associated with this area will be automatically displayed.", - "keywords": [ - "menu", - "navigation", - "links", - "location" - ], - "textdomain": "default", - "attributes": { - "area": { - "type": "string", - "default": "primary" - } - }, - "providesContext": { - "navigationArea": "area" - }, - "supports": { - "html": false, - "inserter": true - } -} diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 5c1ed7178ad34..24396236484ff 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -681,8 +681,4 @@ add_action( 'wp_footer', 'the_block_template_skip_link' ); add_action( 'setup_theme', 'wp_enable_block_templates' ); -// Navigation areas. -add_action( 'setup_theme', '_wp_register_default_navigation_areas' ); -add_action( 'switch_theme', '_wp_migrate_menu_to_navigation_post', 99, 3 ); - unset( $filter, $action ); diff --git a/src/wp-includes/navigation-areas.php b/src/wp-includes/navigation-areas.php deleted file mode 100644 index 5d946973bb802..0000000000000 --- a/src/wp-includes/navigation-areas.php +++ /dev/null @@ -1,262 +0,0 @@ - 'Primary', - * 'secondary' => 'Secondary', - * 'tertiary' => 'Tertiary', - * ) - * - * @since 5.9.0 - * - * @param array $new_areas Supported navigation areas. - */ -function register_navigation_areas( $new_areas ) { - global $navigation_areas; - $navigation_areas = $new_areas; -} - -/** - * Register the default navigation areas. - * - * @since 5.9.0 - * @access private - */ -function _wp_register_default_navigation_areas() { - register_navigation_areas( - array( - 'primary' => _x( 'Primary', 'navigation area' ), - 'secondary' => _x( 'Secondary', 'navigation area' ), - 'tertiary' => _x( 'Tertiary', 'navigation area' ), - ) - ); -} - -/** - * Returns the available navigation areas. - * - * @since 5.9.0 - * - * @return array Registered navigation areas. - */ -function get_navigation_areas() { - global $navigation_areas; - return $navigation_areas; -} - -/** - * Migrates classic menus to a block-based navigation post on theme switch. - * Assigns the created navigation post to the corresponding navigation area. - * - * @since 5.9.0 - * @access private - * - * @param string $new_name Name of the new theme. - * @param WP_Theme $new_theme New theme. - * @param WP_Theme $old_theme Old theme. - */ -function _wp_migrate_menu_to_navigation_post( $new_name, WP_Theme $new_theme, WP_Theme $old_theme ) { - // Do nothing when switching to a theme that does not support site editor. - if ( ! wp_is_block_template_theme() ) { - return; - } - - // get_nav_menu_locations() calls get_theme_mod() which depends on the stylesheet option. - // At the same time, switch_theme runs only after the stylesheet option was updated to $new_theme. - // To retrieve theme mods of the old theme, the getter is hooked to get_option( 'stylesheet' ) so that we - // get the old theme, which causes the get_nav_menu_locations to get the locations of the old theme. - $get_old_theme_stylesheet = static function() use ( $old_theme ) { - return $old_theme->get_stylesheet(); - }; - add_filter( 'option_stylesheet', $get_old_theme_stylesheet ); - - $locations = get_nav_menu_locations(); - $area_mapping = get_option( 'wp_navigation_areas', array() ); - - foreach ( $locations as $location_name => $menu_id ) { - // Get the menu from the location, skipping if there is no - // menu or there was an error. - $menu = wp_get_nav_menu_object( $menu_id ); - if ( ! $menu || is_wp_error( $menu ) ) { - continue; - } - - $menu_items = _wp_get_menu_items_at_location( $location_name ); - if ( empty( $menu_items ) ) { - continue; - } - - $post_name = 'classic_menu_' . $menu_id; - - // Get or create to avoid creating too many wp_navigation posts. - $query = new WP_Query; - $matching_posts = $query->query( - array( - 'name' => $post_name, - 'post_status' => 'publish', - 'post_type' => 'wp_navigation', - 'posts_per_page' => 1, - 'fields' => 'ids', - ) - ); - - if ( ! empty( $matching_posts ) ) { - $navigation_post_id = $matching_posts[0]; - } else { - $menu_items_by_parent_id = _wp_sort_menu_items_by_parent_id( $menu_items ); - $parsed_blocks = _wp_parse_blocks_from_menu_items( $menu_items_by_parent_id[0], $menu_items_by_parent_id ); - $post_data = array( - 'post_type' => 'wp_navigation', - 'post_title' => sprintf( - /* translators: %s: the name of the menu, e.g. "Main Menu". */ - __( 'Classic menu: %s' ), - $menu->name - ), - 'post_name' => $post_name, - 'post_content' => serialize_blocks( $parsed_blocks ), - 'post_status' => 'publish', - ); - $navigation_post_id = wp_insert_post( $post_data, true ); - // If wp_insert_post fails *at any time*, then bail out of the - // entire migration attempt returning the WP_Error object. - if ( is_wp_error( $navigation_post_id ) ) { - return $navigation_post_id; - } - } - - $area_mapping[ $location_name ] = $navigation_post_id; - } - remove_filter( 'option_stylesheet', $get_old_theme_stylesheet ); - - update_option( 'wp_navigation_areas', $area_mapping ); -} - -/** - * Returns the menu items for a WordPress menu location. - * - * @since 5.9.0 - * @access private - * - * @param string $location The menu location. - * @return array Menu items for the location. - */ -function _wp_get_menu_items_at_location( $location ) { - if ( empty( $location ) ) { - return; - } - - // Build menu data. The following approximates the code in `wp_nav_menu()`. - - // Find the location in the list of locations, returning early if the - // location can't be found. - $locations = get_nav_menu_locations(); - if ( ! isset( $locations[ $location ] ) ) { - return; - } - - // Get the menu from the location, returning early if there is no - // menu or there was an error. - $menu = wp_get_nav_menu_object( $locations[ $location ] ); - if ( ! $menu || is_wp_error( $menu ) ) { - return; - } - - $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) ); - _wp_menu_item_classes_by_context( $menu_items ); - - return $menu_items; -} - -/** - * Sorts a standard array of menu items into a nested structure keyed by the - * id of the parent menu. - * - * @since 5.9.0 - * @access private - * - * @param array $menu_items Menu items to sort. - * @return array An array keyed by the id of the parent menu where each element - * is an array of menu items that belong to that parent. - */ -function _wp_sort_menu_items_by_parent_id( $menu_items ) { - $sorted_menu_items = array(); - foreach ( $menu_items as $menu_item ) { - $sorted_menu_items[ $menu_item->menu_order ] = $menu_item; - } - unset( $menu_items, $menu_item ); - - $menu_items_by_parent_id = array(); - foreach ( $sorted_menu_items as $menu_item ) { - $menu_items_by_parent_id[ $menu_item->menu_item_parent ][] = $menu_item; - } - - return $menu_items_by_parent_id; -} - -/** - * Turns menu item data into a nested array of parsed blocks - * - * @since 5.9.0 - * @access private - * - * @param array $menu_items An array of menu items that represent - * an individual level of a menu. - * @param array $menu_items_by_parent_id An array keyed by the id of the - * parent menu where each element is an - * array of menu items that belong to - * that parent. - * @return array An array of parsed block data. - */ -function _wp_parse_blocks_from_menu_items( $menu_items, $menu_items_by_parent_id ) { - if ( empty( $menu_items ) ) { - return array(); - } - - $blocks = array(); - - foreach ( $menu_items as $menu_item ) { - $class_name = ! empty( $menu_item->classes ) ? implode( ' ', (array) $menu_item->classes ) : null; - $id = ( null !== $menu_item->object_id && 'custom' !== $menu_item->object ) ? $menu_item->object_id : null; - $opens_in_new_tab = null !== $menu_item->target && '_blank' === $menu_item->target; - $rel = ( null !== $menu_item->xfn && '' !== $menu_item->xfn ) ? $menu_item->xfn : null; - $kind = null !== $menu_item->type ? str_replace( '_', '-', $menu_item->type ) : 'custom'; - - $block = array( - 'blockName' => isset( $menu_items_by_parent_id[ $menu_item->ID ] ) ? 'core/navigation-submenu' : 'core/navigation-link', - 'attrs' => array( - 'className' => $class_name, - 'description' => $menu_item->description, - 'id' => $id, - 'kind' => $kind, - 'label' => $menu_item->title, - 'opensInNewTab' => $opens_in_new_tab, - 'rel' => $rel, - 'title' => $menu_item->attr_title, - 'type' => $menu_item->object, - 'url' => $menu_item->url, - ), - ); - - if ( isset( $menu_items_by_parent_id[ $menu_item->ID ] ) ) { - $block['innerBlocks'] = _wp_parse_blocks_from_menu_items( - $menu_items_by_parent_id[ $menu_item->ID ], - $menu_items_by_parent_id - ); - } else { - $block['innerBlocks'] = array(); - } - - $block['innerContent'] = array_map( 'serialize_block', $block['innerBlocks'] ); - - $blocks[] = $block; - } - - return $blocks; -} diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 9f385efcf2070..25f23fae64396 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -349,10 +349,6 @@ function create_initial_rest_routes() { // Menu Locations. $controller = new WP_REST_Menu_Locations_Controller(); $controller->register_routes(); - - // Block Navigation Areas - $controller = new WP_REST_Block_Navigation_Areas_Controller(); - $controller->register_routes(); } /** diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-block-navigation-areas-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-block-navigation-areas-controller.php deleted file mode 100644 index 84f09fac21988..0000000000000 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-block-navigation-areas-controller.php +++ /dev/null @@ -1,310 +0,0 @@ -namespace = 'wp/v2'; - $this->rest_base = 'block-navigation-areas'; - } - - /** - * Registers the routes for the objects of the controller. - * - * @since 5.9.0 - * - * @see register_rest_route() - */ - public function register_routes() { - register_rest_route( - $this->namespace, - '/' . $this->rest_base, - array( - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_items' ), - 'permission_callback' => array( $this, 'get_items_permissions_check' ), - 'args' => $this->get_collection_params(), - ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) - ); - - register_rest_route( - $this->namespace, - '/' . $this->rest_base . '/(?P[\w-]+)', - array( - 'args' => array( - 'area' => array( - 'description' => __( 'An alphanumeric identifier for the navigation area.' ), - 'type' => 'string', - ), - ), - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_item' ), - 'permission_callback' => array( $this, 'get_item_permissions_check' ), - 'args' => array( - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), - ), - ), - array( - 'methods' => WP_REST_Server::EDITABLE, - 'callback' => array( $this, 'update_item' ), - 'permission_callback' => array( $this, 'update_item_permissions_check' ), - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), - ), - 'allow_batch' => array( 'v1' => true ), - 'schema' => array( $this, 'get_public_item_schema' ), - ) - ); - } - - /** - * Checks whether a given request has permission to read navigation areas. - * - * @since 5.9.0 - * - * @param WP_REST_Request $request Full details about the request. - * @return WP_Error|bool True if the request has read access, WP_Error object otherwise. - */ - public function get_items_permissions_check( $request ) { - if ( ! current_user_can( 'edit_theme_options' ) ) { - return new WP_Error( - 'rest_cannot_view', - __( 'Sorry, you are not allowed to view navigation areas.' ), - array( 'status' => rest_authorization_required_code() ) - ); - } - - return true; - } - - /** - * Retrieves all navigation areas, depending on user context. - * - * @since 5.9.0 - * - * @param WP_REST_Request $request Full details about the request. - * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. - */ - public function get_items( $request ) { - $data = array(); - foreach ( get_navigation_areas() as $name => $description ) { - $area = $this->get_navigation_area_object( $name ); - $area = $this->prepare_item_for_response( $area, $request ); - $data[] = $this->prepare_response_for_collection( $area ); - } - return rest_ensure_response( $data ); - } - - /** - * Checks if a given request has access to read a navigation area. - * - * @since 5.9.0 - * - * @param WP_REST_Request $request Full details about the request. - * @return WP_Error|bool True if the request has read access for the item, WP_Error object otherwise. - */ - public function get_item_permissions_check( $request ) { - if ( ! current_user_can( 'edit_theme_options' ) ) { - return new WP_Error( - 'rest_cannot_view', - __( 'Sorry, you are not allowed to view navigation areas.' ), - array( 'status' => rest_authorization_required_code() ) - ); - } - if ( ! array_key_exists( $request['area'], get_navigation_areas() ) ) { - return new WP_Error( 'rest_navigation_area_invalid', __( 'Invalid navigation area.' ), array( 'status' => 404 ) ); - } - - return true; - } - - /** - * Checks if a request has access to update the specified term. - * - * @since 5.9.0 - * - * @param WP_REST_Request $request Full details about the request. - * @return bool|WP_Error True if the request has access to update the item, false or WP_Error object otherwise. - */ - public function update_item_permissions_check( $request ) { - return $this->get_item_permissions_check( $request ); - } - - /** - * Retrieves a specific navigation area. - * - * @since 5.9.0 - * - * @param WP_REST_Request $request Full details about the request. - * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. - */ - public function get_item( $request ) { - $name = $request['area']; - $area = $this->get_navigation_area_object( $name ); - $data = $this->prepare_item_for_response( $area, $request ); - - return rest_ensure_response( $data ); - } - - /** - * Updates a specific navigation area. - * - * @since 5.9.0 - * - * @param WP_REST_Request $request Full details about the request. - * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. - */ - public function update_item( $request ) { - $name = $request['area']; - - $mapping = get_option( 'wp_navigation_areas', array() ); - $mapping[ $name ] = $request['navigation']; - update_option( 'wp_navigation_areas', $mapping ); - - $area = $this->get_navigation_area_object( $name ); - $data = $this->prepare_item_for_response( $area, $request ); - return rest_ensure_response( $data ); - } - - /** - * Converts navigation area name to a convenient object that this endpoint can reason about. - * - * @since 5.9.0 - * - * @param string $name Navigation area name. - * @return stdClass An object representation of the navigation area. - */ - protected function get_navigation_area_object( $name ) { - $available_areas = get_navigation_areas(); - $mapping = get_option( 'wp_navigation_areas', array() ); - $area = new stdClass(); - $area->name = $name; - $area->navigation = ! empty( $mapping[ $name ] ) ? $mapping[ $name ] : null; - $area->description = $available_areas[ $name ]; - return $area; - } - - /** - * Prepares a navigation area object for serialization. - * - * @since 5.9.0 - * - * @param stdClass $area Post status data. - * @param WP_REST_Request $request Full details about the request. - * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. - */ - public function prepare_item_for_response( $area, $request ) { - $areas = get_navigation_areas(); - $navigation = ( isset( $areas[ $area->name ] ) ) ? $area->navigation : 0; - - $fields = $this->get_fields_for_response( $request ); - $data = array(); - - if ( rest_is_field_included( 'name', $fields ) ) { - $data['name'] = $area->name; - } - - if ( rest_is_field_included( 'description', $fields ) ) { - $data['description'] = $area->description; - } - - if ( rest_is_field_included( 'navigation', $fields ) ) { - $data['navigation'] = (int) $navigation; - } - - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; - $data = $this->add_additional_fields_to_object( $data, $request ); - $data = $this->filter_response_by_context( $data, $context ); - - $response = rest_ensure_response( $data ); - - /** - * Filters a navigation area returned from the REST API. - * - * @since 5.9.0 - * - * Allows modification of the navigation area data right before it is - * returned. - * - * @param WP_REST_Response|WP_Error $response The response object, or WP_Error object on failure. - * @param object $area The original status object. - * @param WP_REST_Request $request Request used to generate the response. - */ - return apply_filters( 'rest_prepare_navigation_area', $response, $area, $request ); - } - - /** - * Retrieves the navigation area's schema, conforming to JSON Schema. - * - * @since 5.9.0 - * - * @return array Item schema data. - */ - public function get_item_schema() { - if ( $this->schema ) { - return $this->schema; - } - - $this->schema = array( - '$schema' => 'http://json-schema.org/draft-04/schema#', - 'title' => 'navigation-area', - 'type' => 'object', - 'properties' => array( - 'name' => array( - 'description' => __( 'The name of the navigation area.' ), - 'type' => 'string', - 'context' => array( 'embed', 'view', 'edit' ), - 'readonly' => true, - ), - 'description' => array( - 'description' => __( 'The description of the navigation area.' ), - 'type' => 'string', - 'context' => array( 'embed', 'view', 'edit' ), - 'readonly' => true, - ), - 'navigation' => array( - 'description' => __( 'The ID of the assigned navigation.' ), - 'type' => 'integer', - 'context' => array( 'embed', 'view', 'edit' ), - 'readonly' => true, - ), - ), - ); - - return $this->add_additional_fields_schema( $this->schema ); - } - - /** - * Retrieves the query params for collections. - * - * @since 5.9.0 - * - * @return array Collection parameters. - */ - public function get_collection_params() { - return array( - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), - ); - } - -} diff --git a/src/wp-settings.php b/src/wp-settings.php index 0a55449bfc319..3b0e179baf149 100644 --- a/src/wp-settings.php +++ b/src/wp-settings.php @@ -246,7 +246,6 @@ require ABSPATH . WPINC . '/class-wp-widget-factory.php'; require ABSPATH . WPINC . '/nav-menu-template.php'; require ABSPATH . WPINC . '/nav-menu.php'; -require ABSPATH . WPINC . '/navigation-areas.php'; require ABSPATH . WPINC . '/admin-bar.php'; require ABSPATH . WPINC . '/class-wp-application-passwords.php'; require ABSPATH . WPINC . '/rest-api.php'; @@ -276,7 +275,6 @@ require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-themes-controller.php'; require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-plugins-controller.php'; require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-block-directory-controller.php'; -require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-block-navigation-areas-controller.php'; require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php'; require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-application-passwords-controller.php'; require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-site-health-controller.php'; diff --git a/tests/phpunit/includes/functions.php b/tests/phpunit/includes/functions.php index 1a100a3432168..323043dfba305 100644 --- a/tests/phpunit/includes/functions.php +++ b/tests/phpunit/includes/functions.php @@ -312,7 +312,6 @@ function _unhook_block_registration() { remove_action( 'init', 'register_block_core_legacy_widget' ); remove_action( 'init', 'register_block_core_loginout' ); remove_action( 'init', 'register_block_core_navigation' ); - remove_action( 'init', 'register_block_core_navigation_area' ); remove_action( 'init', 'register_block_core_navigation_link' ); remove_action( 'init', 'register_block_core_navigation_submenu' ); remove_action( 'init', 'register_block_core_page_list' ); diff --git a/tests/phpunit/tests/rest-api/rest-schema-setup.php b/tests/phpunit/tests/rest-api/rest-schema-setup.php index 500f6acdd0fe2..1ed1d8961150e 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-setup.php +++ b/tests/phpunit/tests/rest-api/rest-schema-setup.php @@ -171,8 +171,6 @@ public function test_expected_routes_in_schema() { '/wp/v2/navigation/(?P[\d]+)/autosaves/(?P[\d]+)', '/wp/v2/navigation/(?P[\d]+)/revisions', '/wp/v2/navigation/(?P[\d]+)/revisions/(?P[\d]+)', - '/wp/v2/block-navigation-areas', - '/wp/v2/block-navigation-areas/(?P[\w-]+)', '/wp-site-health/v1', '/wp-site-health/v1/tests/background-updates', '/wp-site-health/v1/tests/loopback-requests', diff --git a/tests/phpunit/tests/rest-api/wpRestBlockNavigationAreasController.php b/tests/phpunit/tests/rest-api/wpRestBlockNavigationAreasController.php deleted file mode 100644 index 128832cd35d5e..0000000000000 --- a/tests/phpunit/tests/rest-api/wpRestBlockNavigationAreasController.php +++ /dev/null @@ -1,136 +0,0 @@ -user->create( - array( - 'role' => 'administrator', - ) - ); - - static::$old_mapping = get_option( static::OPTION, array() ); - } - - public static function wpTearDownAfterClass() { - self::delete_user( self::$admin_id ); - update_option( static::OPTION, static::$old_mapping ); - } - - public function test_get_items() { - wp_set_current_user( static::$admin_id ); - $request = new WP_REST_Request( 'GET', '/wp/v2/block-navigation-areas' ); - - $response = rest_get_server()->dispatch( $request ); - $this->assertSame( 200, $response->get_status() ); - $data = $response->get_data(); - $this->assertIsArray( $data ); - $navigation_areas = get_navigation_areas(); - $expected_data = array(); - foreach ( $navigation_areas as $name => $navigation_area ) { - $expected_data[] = array( - 'name' => $name, - 'description' => $navigation_area, - 'navigation' => 0, - ); - } - $this->assertSameSets( $expected_data, $data ); - } - - public function test_register_routes() { - wp_set_current_user( static::$admin_id ); - $routes = rest_get_server()->get_routes(); - $this->assertArrayHasKey( '/wp/v2/block-navigation-areas', $routes ); - $this->assertArrayHasKey( '/wp/v2/block-navigation-areas/(?P[\\w-]+)', $routes ); - } - - public function test_context_param() { - wp_set_current_user( static::$admin_id ); - $request = new WP_REST_Request( WpOrg\Requests\Requests::OPTIONS, '/wp/v2/block-navigation-areas' ); - $response = rest_get_server()->dispatch( $request ); - $this->assertSame( 200, $response->get_status() ); - $data = $response->get_data(); - - $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] ); - $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] ); - } - - public function test_get_item() { - wp_set_current_user( static::$admin_id ); - $navigation_area = array_rand( get_navigation_areas(), 1 ); - - $this->assertIsString( $navigation_area ); - $this->assertNotEmpty( $navigation_area ); - - $route = sprintf( '/wp/v2/block-navigation-areas/%s', urlencode( $navigation_area ) ); - $request = new WP_REST_Request( 'GET', $route ); - $response = rest_get_server()->dispatch( $request ); - $this->assertSame( 200, $response->get_status() ); - $data = $response->get_data(); - $this->assertIsArray( $data ); - $this->assertArrayHasKey( 'name', $data ); - $this->assertSame( $navigation_area, $data['name'] ); - } - - public function test_create_item() { - // We cannot create new navigation areas using the current block navigation areas API, - // so the test should be marked as passed. - $this->markTestSkipped(); - } - - public function test_update_item() { - wp_set_current_user( static::$admin_id ); - $navigation_area = array_rand( get_navigation_areas(), 1 ); - $route = sprintf( '/wp/v2/block-navigation-areas/%s', urlencode( $navigation_area ) ); - $request = new WP_REST_Request( WpOrg\Requests\Requests::POST, $route ); - - $updated_navigation_area = array( - 'name' => $navigation_area, - 'description' => 'Test Description', - ); - - $request->set_param( 'navigation', $updated_navigation_area ); - $response = rest_get_server()->dispatch( $request ); - $this->assertSame( 200, $response->get_status() ); - $new_mapping = get_option( static::OPTION, array() ); - $this->assertSame( $new_mapping[ $navigation_area ], $updated_navigation_area ); - } - - public function test_delete_item() { - // We cannot delete navigation areas using the current block navigation areas API, - // so the test should be marked as passed. - $this->markTestSkipped(); - } - - public function test_prepare_item() { - // The current block navigation areas API doesn't implement any custom prepare_item logic - // so there is nothing to test. - $this->markTestSkipped(); - } - - public function test_get_item_schema() { - // The current block navigation areas API doesn't implement any custom item schema - // so there is nothing to test. - $this->markTestSkipped(); - } -} - diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index 3c6f4906af686..9265197ebdc85 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -10612,93 +10612,6 @@ mockedApiResponse.Schema = { } } ] - }, - "/wp/v2/block-navigation-areas": { - "namespace": "wp/v2", - "methods": [ - "GET" - ], - "endpoints": [ - { - "methods": [ - "GET" - ], - "args": { - "context": { - "description": "Scope under which the request is made; determines fields present in response.", - "type": "string", - "enum": [ - "view", - "embed", - "edit" - ], - "default": "view", - "required": false - } - } - } - ], - "_links": { - "self": [ - { - "href": "http://example.org/index.php?rest_route=/wp/v2/block-navigation-areas" - } - ] - } - }, - "/wp/v2/block-navigation-areas/(?P[\\w-]+)": { - "namespace": "wp/v2", - "methods": [ - "GET", - "POST", - "PUT", - "PATCH" - ], - "endpoints": [ - { - "methods": [ - "GET" - ], - "allow_batch": { - "v1": true - }, - "args": { - "area": { - "description": "An alphanumeric identifier for the navigation area.", - "type": "string", - "required": false - }, - "context": { - "description": "Scope under which the request is made; determines fields present in response.", - "type": "string", - "enum": [ - "view", - "embed", - "edit" - ], - "default": "view", - "required": false - } - } - }, - { - "methods": [ - "POST", - "PUT", - "PATCH" - ], - "allow_batch": { - "v1": true - }, - "args": { - "area": { - "description": "An alphanumeric identifier for the navigation area.", - "type": "string", - "required": false - } - } - } - ] } }, "site_logo": 0, diff --git a/tools/webpack/blocks.js b/tools/webpack/blocks.js index 7aa2b291cb7f4..bbdf8f1d4c27e 100644 --- a/tools/webpack/blocks.js +++ b/tools/webpack/blocks.js @@ -32,7 +32,6 @@ module.exports = function( env = { environment: 'production', watch: false, buil 'latest-posts', 'loginout', 'navigation', - 'navigation-area', 'navigation-link', 'navigation-submenu', 'page-list',