Make WordPress Core

Ticket #38582: 38582.diff

File 38582.diff, 7.3 KB (added by jnylen0, 9 years ago)
  • src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

    diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
    index 52c84e1..2749b12 100644
    a b class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { 
    419419                        'readonly'        => true,
    420420                );
    421421
     422                unset( $schema['properties']['password'] );
     423
    422424                return $schema;
    423425        }
    424426
  • src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
    index a9d8f3c..ad7c4e0 100644
    a b class WP_REST_Posts_Controller extends WP_REST_Controller { 
    19481948                                'type'        => 'boolean',
    19491949                                'context'     => array( 'view', 'edit' ),
    19501950                        );
    1951 
    1952                         $schema['properties']['password'] = array(
    1953                                 'description' => __( 'A password to protect access to the content and excerpt.' ),
    1954                                 'type'        => 'string',
    1955                                 'context'     => array( 'edit' ),
    1956                         );
    19571951                }
    19581952
     1953                $schema['properties']['password'] = array(
     1954                        'description' => __( 'A password to protect access to the content and excerpt.' ),
     1955                        'type'        => 'string',
     1956                        'context'     => array( 'edit' ),
     1957                );
     1958
    19591959                if ( 'page' === $this->post_type ) {
    19601960                        $schema['properties']['template'] = array(
    19611961                                'description' => __( 'The theme file to use to display the object.' ),
  • tests/phpunit/tests/rest-api/rest-pages-controller.php

    diff --git a/tests/phpunit/tests/rest-api/rest-pages-controller.php b/tests/phpunit/tests/rest-api/rest-pages-controller.php
    index 29f050f..2ce9afe 100644
    a b class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te 
    358358                $this->assertEquals( 0, $new_data['menu_order'] );
    359359        }
    360360
     361        public function test_get_page_with_password() {
     362                $page_id = $this->factory->post->create( array(
     363                        'post_type'     => 'page',
     364                        'post_password' => '$inthebananastand',
     365                ) );
     366
     367                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/pages/%d', $page_id ) );
     368                $response = $this->server->dispatch( $request );
     369
     370                $data = $response->get_data();
     371                $this->assertEquals( '', $data['content']['rendered'] );
     372                $this->assertTrue( $data['content']['protected'] );
     373                $this->assertEquals( '', $data['excerpt']['rendered'] );
     374                $this->assertTrue( $data['excerpt']['protected'] );
     375        }
     376
     377        public function test_get_page_with_password_using_password() {
     378                $page_id = $this->factory->post->create( array(
     379                        'post_type'     => 'page',
     380                        'post_password' => '$inthebananastand',
     381                        'post_content'  => 'Some secret content.',
     382                        'post_excerpt'  => 'Some secret excerpt.',
     383                ) );
     384
     385                $page = get_post( $page_id );
     386                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/pages/%d', $page_id ) );
     387                $request->set_param( 'password', '$inthebananastand' );
     388                $response = $this->server->dispatch( $request );
     389
     390                $data = $response->get_data();
     391                $this->assertEquals( wpautop( $page->post_content ), $data['content']['rendered'] );
     392                $this->assertTrue( $data['content']['protected'] );
     393                $this->assertEquals( wpautop( $page->post_excerpt ), $data['excerpt']['rendered'] );
     394                $this->assertTrue( $data['excerpt']['protected'] );
     395        }
     396
     397        public function test_get_page_with_password_using_incorrect_password() {
     398                $page_id = $this->factory->post->create( array(
     399                        'post_type'     => 'page',
     400                        'post_password' => '$inthebananastand',
     401                ) );
     402
     403                $page = get_post( $page_id );
     404                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/pages/%d', $page_id ) );
     405                $request->set_param( 'password', 'wrongpassword' );
     406                $response = $this->server->dispatch( $request );
     407
     408                $this->assertErrorResponse( 'rest_post_incorrect_password', $response, 403 );
     409        }
     410
     411        public function test_get_page_with_password_without_permission() {
     412                $page_id = $this->factory->post->create( array(
     413                        'post_type'     => 'page',
     414                        'post_password' => '$inthebananastand',
     415                        'post_content'  => 'Some secret content.',
     416                        'post_excerpt'  => 'Some secret excerpt.',
     417                ) );
     418                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/pages/%d', $page_id ) );
     419                $response = $this->server->dispatch( $request );
     420                $data = $response->get_data();
     421                $this->assertEquals( '', $data['content']['rendered'] );
     422                $this->assertTrue( $data['content']['protected'] );
     423                $this->assertEquals( '', $data['excerpt']['rendered'] );
     424                $this->assertTrue( $data['excerpt']['protected'] );
     425        }
     426
    361427        public function test_get_item_schema() {
    362428                $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/pages' );
    363429                $response = $this->server->dispatch( $request );
    364430                $data = $response->get_data();
    365431                $properties = $data['schema']['properties'];
    366                 $this->assertEquals( 21, count( $properties ) );
     432                $this->assertEquals( 22, count( $properties ) );
    367433                $this->assertArrayHasKey( 'author', $properties );
    368434                $this->assertArrayHasKey( 'comment_status', $properties );
    369435                $this->assertArrayHasKey( 'content', $properties );
    class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te 
    379445                $this->assertArrayHasKey( 'modified', $properties );
    380446                $this->assertArrayHasKey( 'modified_gmt', $properties );
    381447                $this->assertArrayHasKey( 'parent', $properties );
     448                $this->assertArrayHasKey( 'password', $properties );
    382449                $this->assertArrayHasKey( 'ping_status', $properties );
    383450                $this->assertArrayHasKey( 'slug', $properties );
    384451                $this->assertArrayHasKey( 'status', $properties );
  • tests/phpunit/tests/rest-api/rest-posts-controller.php

    diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php
    index 3365f77..1a8545b 100644
    a b class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 
    770770                $this->check_get_post_response( $response, 'view' );
    771771
    772772                $data = $response->get_data();
     773                $this->assertEquals( '', $data['content']['rendered'] );
    773774                $this->assertTrue( $data['content']['protected'] );
     775                $this->assertEquals( '', $data['excerpt']['rendered'] );
    774776                $this->assertTrue( $data['excerpt']['protected'] );
    775777        }
    776778
    class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 
    790792
    791793                $data = $response->get_data();
    792794                $this->assertEquals( wpautop( $post->post_content ), $data['content']['rendered'] );
     795                $this->assertTrue( $data['content']['protected'] );
    793796                $this->assertEquals( wpautop( $post->post_excerpt ), $data['excerpt']['rendered'] );
     797                $this->assertTrue( $data['excerpt']['protected'] );
    794798        }
    795799
    796800        public function test_get_post_with_password_using_incorrect_password() {
    class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 
    817821                $data = $response->get_data();
    818822                $this->check_get_post_response( $response, 'view' );
    819823                $this->assertEquals( '', $data['content']['rendered'] );
     824                $this->assertTrue( $data['content']['protected'] );
    820825                $this->assertEquals( '', $data['excerpt']['rendered'] );
    821 
     826                $this->assertTrue( $data['excerpt']['protected'] );
    822827        }
    823828
    824829        public function test_get_item_read_permission_custom_post_status() {