Ticket #38582: 38582.diff
File 38582.diff, 7.3 KB (added by , 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 { 419 419 'readonly' => true, 420 420 ); 421 421 422 unset( $schema['properties']['password'] ); 423 422 424 return $schema; 423 425 } 424 426 -
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 { 1948 1948 'type' => 'boolean', 1949 1949 'context' => array( 'view', 'edit' ), 1950 1950 ); 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 );1957 1951 } 1958 1952 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 1959 1959 if ( 'page' === $this->post_type ) { 1960 1960 $schema['properties']['template'] = array( 1961 1961 '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 358 358 $this->assertEquals( 0, $new_data['menu_order'] ); 359 359 } 360 360 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 361 427 public function test_get_item_schema() { 362 428 $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/pages' ); 363 429 $response = $this->server->dispatch( $request ); 364 430 $data = $response->get_data(); 365 431 $properties = $data['schema']['properties']; 366 $this->assertEquals( 2 1, count( $properties ) );432 $this->assertEquals( 22, count( $properties ) ); 367 433 $this->assertArrayHasKey( 'author', $properties ); 368 434 $this->assertArrayHasKey( 'comment_status', $properties ); 369 435 $this->assertArrayHasKey( 'content', $properties ); … … class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te 379 445 $this->assertArrayHasKey( 'modified', $properties ); 380 446 $this->assertArrayHasKey( 'modified_gmt', $properties ); 381 447 $this->assertArrayHasKey( 'parent', $properties ); 448 $this->assertArrayHasKey( 'password', $properties ); 382 449 $this->assertArrayHasKey( 'ping_status', $properties ); 383 450 $this->assertArrayHasKey( 'slug', $properties ); 384 451 $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 770 770 $this->check_get_post_response( $response, 'view' ); 771 771 772 772 $data = $response->get_data(); 773 $this->assertEquals( '', $data['content']['rendered'] ); 773 774 $this->assertTrue( $data['content']['protected'] ); 775 $this->assertEquals( '', $data['excerpt']['rendered'] ); 774 776 $this->assertTrue( $data['excerpt']['protected'] ); 775 777 } 776 778 … … class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 790 792 791 793 $data = $response->get_data(); 792 794 $this->assertEquals( wpautop( $post->post_content ), $data['content']['rendered'] ); 795 $this->assertTrue( $data['content']['protected'] ); 793 796 $this->assertEquals( wpautop( $post->post_excerpt ), $data['excerpt']['rendered'] ); 797 $this->assertTrue( $data['excerpt']['protected'] ); 794 798 } 795 799 796 800 public function test_get_post_with_password_using_incorrect_password() { … … class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 817 821 $data = $response->get_data(); 818 822 $this->check_get_post_response( $response, 'view' ); 819 823 $this->assertEquals( '', $data['content']['rendered'] ); 824 $this->assertTrue( $data['content']['protected'] ); 820 825 $this->assertEquals( '', $data['excerpt']['rendered'] ); 821 826 $this->assertTrue( $data['excerpt']['protected'] ); 822 827 } 823 828 824 829 public function test_get_item_read_permission_custom_post_status() {