- Timestamp:
- 10/31/2016 03:52:08 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-pages-controller.php
r38975 r39047 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' ); … … 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 ); … … 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 );
Note: See TracChangeset
for help on using the changeset viewer.