- Timestamp:
- 12/12/2018 02:11:22 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/5.0 merged: 43720
- Property svn:mergeinfo changed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r43979 r43980 1588 1588 } 1589 1589 1590 $post_type_obj = get_post_type_object( $post->post_type ); 1591 if ( is_post_type_viewable( $post_type_obj ) && $post_type_obj->public ) { 1592 1593 if ( ! function_exists( 'get_sample_permalink' ) ) { 1594 require_once ABSPATH . '/wp-admin/includes/post.php'; 1595 } 1596 1597 $sample_permalink = get_sample_permalink( $post->ID, $post->post_title, '' ); 1598 1599 if ( in_array( 'permalink_template', $fields, true ) ) { 1600 $data['permalink_template'] = $sample_permalink[0]; 1601 } 1602 if ( in_array( 'generated_slug', $fields, true ) ) { 1603 $data['generated_slug'] = $sample_permalink[1]; 1604 } 1605 } 1606 1590 1607 $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; 1591 1608 $data = $this->add_additional_fields_to_object( $data, $request ); … … 1919 1936 1920 1937 $post_type_obj = get_post_type_object( $this->post_type ); 1938 if ( is_post_type_viewable( $post_type_obj ) && $post_type_obj->public ) { 1939 $schema['properties']['permalink_template'] = array( 1940 'description' => __( 'Permalink template for the object.' ), 1941 'type' => 'string', 1942 'context' => array( 'edit' ), 1943 'readonly' => true, 1944 ); 1945 1946 $schema['properties']['generated_slug'] = array( 1947 'description' => __( 'Slug automatically generated from the object title.' ), 1948 'type' => 'string', 1949 'context' => array( 'edit' ), 1950 'readonly' => true, 1951 ); 1952 } 1921 1953 1922 1954 if ( $post_type_obj->hierarchical ) { -
trunk/tests/phpunit/includes/testcase-rest-controller.php
r42724 r43980 41 41 42 42 public function filter_rest_url_for_leading_slash( $url, $path ) { 43 if ( is_multisite() ) {43 if ( is_multisite() || get_option( 'permalink_structure' ) ) { 44 44 return $url; 45 45 } -
trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r43973 r43980 1296 1296 $data = $response->get_data(); 1297 1297 $properties = $data['schema']['properties']; 1298 $this->assertEquals( 2 4, count( $properties ) );1298 $this->assertEquals( 26, count( $properties ) ); 1299 1299 $this->assertArrayHasKey( 'author', $properties ); 1300 1300 $this->assertArrayHasKey( 'alt_text', $properties ); … … 1308 1308 $this->assertArrayHasKey( 'date', $properties ); 1309 1309 $this->assertArrayHasKey( 'date_gmt', $properties ); 1310 $this->assertArrayHasKey( 'generated_slug', $properties ); 1310 1311 $this->assertArrayHasKey( 'guid', $properties ); 1311 1312 $this->assertArrayHasKey( 'id', $properties ); … … 1319 1320 $this->assertArrayHasKey( 'post', $properties ); 1320 1321 $this->assertArrayHasKey( 'ping_status', $properties ); 1322 $this->assertArrayHasKey( 'permalink_template', $properties ); 1321 1323 $this->assertArrayHasKey( 'status', $properties ); 1322 1324 $this->assertArrayHasKey( 'slug', $properties ); -
trunk/tests/phpunit/tests/rest-api/rest-pages-controller.php
r43571 r43980 679 679 $data = $response->get_data(); 680 680 $properties = $data['schema']['properties']; 681 $this->assertEquals( 2 2, count( $properties ) );681 $this->assertEquals( 24, count( $properties ) ); 682 682 $this->assertArrayHasKey( 'author', $properties ); 683 683 $this->assertArrayHasKey( 'comment_status', $properties ); … … 685 685 $this->assertArrayHasKey( 'date', $properties ); 686 686 $this->assertArrayHasKey( 'date_gmt', $properties ); 687 $this->assertArrayHasKey( 'generated_slug', $properties ); 687 688 $this->assertArrayHasKey( 'guid', $properties ); 688 689 $this->assertArrayHasKey( 'excerpt', $properties ); … … 696 697 $this->assertArrayHasKey( 'parent', $properties ); 697 698 $this->assertArrayHasKey( 'password', $properties ); 699 $this->assertArrayHasKey( 'permalink_template', $properties ); 698 700 $this->assertArrayHasKey( 'ping_status', $properties ); 699 701 $this->assertArrayHasKey( 'slug', $properties ); -
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.