Make WordPress Core


Ignore:
Timestamp:
11/18/2016 06:11:49 PM (7 years ago)
Author:
rachelbaker
Message:

REST API: Allow parent property to be explicitly set to 0 when creating or updating a Post.

Props lucasstark, danielbachhuber.
Fixes #38852.

File:
1 edited

Legend:

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

    r39105 r39289  
    370370        $new_data = $response->get_data();
    371371        $this->assertEquals( 0, $new_data['menu_order'] );
     372    }
     373
     374    public function test_update_page_parent_non_zero() {
     375        $page_id1 = $this->factory->post->create( array(
     376            'post_type' => 'page',
     377        ) );
     378        $page_id2 = $this->factory->post->create( array(
     379            'post_type' => 'page',
     380        ) );
     381        wp_set_current_user( self::$editor_id );
     382        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/pages/%d', $page_id2 ) );
     383        $request->set_body_params( array(
     384            'parent' => $page_id1,
     385        ) );
     386        $response = $this->server->dispatch( $request );
     387        $new_data = $response->get_data();
     388        $this->assertEquals( $page_id1, $new_data['parent'] );
     389    }
     390
     391    public function test_update_page_parent_zero() {
     392        $page_id1 = $this->factory->post->create( array(
     393            'post_type' => 'page',
     394        ) );
     395        $page_id2 = $this->factory->post->create( array(
     396            'post_type'    => 'page',
     397            'post_parent'  => $page_id1,
     398        ) );
     399        wp_set_current_user( self::$editor_id );
     400        $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/pages/%d', $page_id2 ) );
     401        $request->set_body_params( array(
     402            'parent' => 0,
     403        ) );
     404        $response = $this->server->dispatch( $request );
     405        $new_data = $response->get_data();
     406        $this->assertEquals( 0, $new_data['parent'] );
    372407    }
    373408
Note: See TracChangeset for help on using the changeset viewer.