- Timestamp:
- 12/12/2018 02:11:22 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/5.0 merged: 43720
- Property svn:mergeinfo changed
-
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r43979 r43980 3480 3480 $data = $response->get_data(); 3481 3481 $properties = $data['schema']['properties']; 3482 $this->assertEquals( 2 4, count( $properties ) );3482 $this->assertEquals( 26, count( $properties ) ); 3483 3483 $this->assertArrayHasKey( 'author', $properties ); 3484 3484 $this->assertArrayHasKey( 'comment_status', $properties ); … … 3488 3488 $this->assertArrayHasKey( 'excerpt', $properties ); 3489 3489 $this->assertArrayHasKey( 'featured_media', $properties ); 3490 $this->assertArrayHasKey( 'generated_slug', $properties ); 3490 3491 $this->assertArrayHasKey( 'guid', $properties ); 3491 3492 $this->assertArrayHasKey( 'format', $properties ); … … 3496 3497 $this->assertArrayHasKey( 'modified_gmt', $properties ); 3497 3498 $this->assertArrayHasKey( 'password', $properties ); 3499 $this->assertArrayHasKey( 'permalink_template', $properties ); 3498 3500 $this->assertArrayHasKey( 'ping_status', $properties ); 3499 3501 $this->assertArrayHasKey( 'slug', $properties ); … … 3565 3567 'featured_media', 3566 3568 'format', 3569 'generated_slug', 3567 3570 'guid', 3568 3571 'id', … … 3572 3575 'modified_gmt', 3573 3576 'password', 3577 'permalink_template', 3574 3578 'ping_status', 3575 3579 'slug', … … 4087 4091 } 4088 4092 4093 public function test_generated_permalink_template_generated_slug_for_non_viewable_posts() { 4094 register_post_type( 4095 'private-post', 4096 array( 4097 'label' => 'Private Posts', 4098 'supports' => array( 'title', 'editor', 'author' ), 4099 'show_in_rest' => true, 4100 'publicly_queryable' => false, 4101 'public' => true, 4102 'rest_base' => 'private-post', 4103 ) 4104 ); 4105 create_initial_rest_routes(); 4106 4107 wp_set_current_user( self::$editor_id ); 4108 4109 $post_id = $this->factory->post->create( 4110 array( 4111 'post_title' => 'Permalink Template', 4112 'post_type' => 'private-post', 4113 'post_status' => 'draft', 4114 ) 4115 ); 4116 4117 // Neither 'permalink_template' and 'generated_slug' are expected for this post type. 4118 $request = new WP_REST_Request( 'GET', '/wp/v2/private-post/' . $post_id ); 4119 $request->set_param( 'context', 'edit' ); 4120 $response = rest_get_server()->dispatch( $request ); 4121 $data = $response->get_data(); 4122 $this->assertEquals( 200, $response->get_status() ); 4123 $this->assertArrayNotHasKey( 'permalink_template', $data ); 4124 $this->assertArrayNotHasKey( 'generated_slug', $data ); 4125 } 4126 4127 public function test_generated_permalink_template_generated_slug_for_posts() { 4128 $this->set_permalink_structure( '/%postname%/' ); 4129 $expected_permalink_template = trailingslashit( home_url( '/%postname%/' ) ); 4130 4131 wp_set_current_user( self::$editor_id ); 4132 4133 $post_id = $this->factory->post->create( 4134 array( 4135 'post_title' => 'Permalink Template', 4136 'post_type' => 'post', 4137 'post_status' => 'draft', 4138 ) 4139 ); 4140 4141 // Both 'permalink_template' and 'generated_slug' are expected for context=edit. 4142 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id ); 4143 $request->set_param( 'context', 'edit' ); 4144 $response = rest_get_server()->dispatch( $request ); 4145 $data = $response->get_data(); 4146 $this->assertEquals( 200, $response->get_status() ); 4147 $this->assertEquals( $expected_permalink_template, $data['permalink_template'] ); 4148 $this->assertEquals( 'permalink-template', $data['generated_slug'] ); 4149 4150 // Neither 'permalink_template' and 'generated_slug' are expected for context=view. 4151 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id ); 4152 $request->set_param( 'context', 'view' ); 4153 $response = rest_get_server()->dispatch( $request ); 4154 $data = $response->get_data(); 4155 $this->assertEquals( 200, $response->get_status() ); 4156 $this->assertArrayNotHasKey( 'permalink_template', $data ); 4157 $this->assertArrayNotHasKey( 'generated_slug', $data ); 4158 4159 } 4160 4089 4161 public function tearDown() { 4162 _unregister_post_type( 'private-post' ); 4090 4163 _unregister_post_type( 'youseeeme' ); 4091 4164 if ( isset( $this->attachment_id ) ) {
Note: See TracChangeset
for help on using the changeset viewer.