Make WordPress Core


Ignore:
Timestamp:
11/16/2021 05:07:43 PM (2 years ago)
Author:
spacedmonkey
Message:

REST API: Remove experimental block menu item types.

The menu items REST API controller was added in [52079]. This included functionality to add a "block" menu item type. This functionality is experimental and not currently used in WordPress core, so should be removed.

Props noisysocks.
See #40878.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/wpRestMenuItemsController.php

    r52079 r52184  
    609609
    610610    /**
    611      * Tests that a block menu item can be created.
    612      *
    613      * @ticket 40878
    614      * @covers ::create_item
    615      */
    616     public function test_create_item_block() {
    617         wp_set_current_user( self::$admin_id );
    618         $request = new WP_REST_Request( 'POST', '/wp/v2/menu-items' );
    619         $request->add_header( 'content-type', 'application/x-www-form-urlencoded' );
    620         $params = $this->set_menu_item_data(
    621             array(
    622                 'type'    => 'block',
    623                 'content' => '<!-- wp:paragraph --><p>Block content</p><!-- /wp:paragraph -->',
    624             )
    625         );
    626         $request->set_body_params( $params );
    627         $response = rest_get_server()->dispatch( $request );
    628 
    629         $this->check_create_menu_item_response( $response );
    630     }
    631 
    632     /**
    633      * Tests that a block menu item can be created.
    634      *
    635      * @ticket 40878
    636      * @covers ::create_item
    637      */
    638     public function test_create_item_invalid_block_content() {
    639         wp_set_current_user( self::$admin_id );
    640         $request = new WP_REST_Request( 'POST', '/wp/v2/menu-items' );
    641         $request->add_header( 'content-type', 'application/x-www-form-urlencoded' );
    642         $params = $this->set_menu_item_data(
    643             array(
    644                 'type' => 'block',
    645             )
    646         );
    647         $request->set_body_params( $params );
    648         $response = rest_get_server()->dispatch( $request );
    649         $this->assertErrorResponse( 'rest_content_required', $response, 400 );
    650     }
    651 
    652     /**
    653611     * @ticket 40878
    654612     * @covers ::update_item
     
    684642     * @covers ::update_item
    685643     */
    686     public function test_update_item_preserves_type() {
    687         wp_set_current_user( self::$admin_id );
    688 
    689         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/menu-items/%d', $this->menu_item_id ) );
    690         $request->add_header( 'content-type', 'application/x-www-form-urlencoded' );
    691         $params = array(
    692             'status'  => 'draft',
    693             'type'    => 'block',
    694             'title'   => 'TEST',
    695             'content' => '<!-- wp:paragraph --><p>Block content</p><!-- /wp:paragraph -->',
    696         );
    697         $request->set_body_params( $params );
    698         $response = rest_get_server()->dispatch( $request );
    699         $this->check_update_menu_item_response( $response );
    700         $new_data = $response->get_data();
    701         $this->assertSame( 'block', $new_data['type'] );
    702 
    703         $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/menu-items/%d', $this->menu_item_id ) );
    704         $request->add_header( 'content-type', 'application/x-www-form-urlencoded' );
    705         $params = array(
    706             'status'  => 'draft',
    707             'title'   => 'TEST2',
    708             'content' => '<!-- wp:paragraph --><p>Block content</p><!-- /wp:paragraph -->',
    709         );
    710         $request->set_body_params( $params );
    711         $response = rest_get_server()->dispatch( $request );
    712         $this->check_update_menu_item_response( $response );
    713         $new_data = $response->get_data();
    714 
    715         // The type shouldn't change just because it was missing from request args.
    716         $this->assertSame( 'block', $new_data['type'] );
    717     }
    718 
    719     /**
    720      * @ticket 40878
    721      * @covers ::update_item
    722      */
    723644    public function test_update_item_clean_xfn() {
    724645        wp_set_current_user( self::$admin_id );
     
    826747        $data       = $response->get_data();
    827748        $properties = $data['schema']['properties'];
    828         $this->assertSame( 19, count( $properties ) );
     749        $this->assertSame( 18, count( $properties ) );
    829750        $this->assertArrayHasKey( 'type_label', $properties );
    830751        $this->assertArrayHasKey( 'attr_title', $properties );
    831752        $this->assertArrayHasKey( 'classes', $properties );
    832753        $this->assertArrayHasKey( 'description', $properties );
    833         $this->assertArrayHasKey( 'content', $properties );
    834754        $this->assertArrayHasKey( 'id', $properties );
    835755        $this->assertArrayHasKey( 'url', $properties );
     
    958878        }
    959879
    960         // Check content.
    961         if ( 'block' === $data['type'] ) {
    962             $menu_item_content = get_post_meta( $post->ID, '_menu_item_content', true );
    963             $this->assertSame( apply_filters( 'the_content', $menu_item_content ), $data['content']['rendered'] );
    964             if ( 'edit' === $context ) {
    965                 $this->assertSame( $menu_item_content, $data['content']['raw'] );
    966             } else {
    967                 $this->assertFalse( isset( $data['title']['raw'] ) );
    968             }
    969             $this->assertSame( 1, $data['content']['block_version'] );
    970         } else {
    971             $this->assertEmpty( $data['content']['rendered'] );
    972         }
    973 
    974880        // post_parent.
    975881        $this->assertArrayHasKey( 'parent', $data );
Note: See TracChangeset for help on using the changeset viewer.