Changeset 43720
- Timestamp:
- 10/11/2018 10:24:51 PM (6 years ago)
- Location:
- branches/5.0
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r43716 r43720 1573 1573 $terms = get_the_terms( $post, $taxonomy->name ); 1574 1574 $data[ $base ] = $terms ? array_values( wp_list_pluck( $terms, 'term_id' ) ) : array(); 1575 } 1576 } 1577 1578 $post_type_obj = get_post_type_object( $post->post_type ); 1579 if ( is_post_type_viewable( $post_type_obj ) && $post_type_obj->public ) { 1580 1581 if ( ! function_exists( 'get_sample_permalink' ) ) { 1582 require_once ABSPATH . '/wp-admin/includes/post.php'; 1583 } 1584 1585 $sample_permalink = get_sample_permalink( $post->ID, $post->post_title, '' ); 1586 1587 if ( in_array( 'permalink_template', $fields, true ) ) { 1588 $data['permalink_template'] = $sample_permalink[0]; 1589 } 1590 if ( in_array( 'generated_slug', $fields, true ) ) { 1591 $data['generated_slug'] = $sample_permalink[1]; 1575 1592 } 1576 1593 } … … 1908 1925 1909 1926 $post_type_obj = get_post_type_object( $this->post_type ); 1927 if ( is_post_type_viewable( $post_type_obj ) && $post_type_obj->public ) { 1928 $schema['properties']['permalink_template'] = array( 1929 'description' => __( 'Permalink template for the object.' ), 1930 'type' => 'string', 1931 'context' => array( 'edit' ), 1932 'readonly' => true, 1933 ); 1934 1935 $schema['properties']['generated_slug'] = array( 1936 'description' => __( 'Slug automatically generated from the object title.' ), 1937 'type' => 'string', 1938 'context' => array( 'edit' ), 1939 'readonly' => true, 1940 ); 1941 } 1910 1942 1911 1943 if ( $post_type_obj->hierarchical ) { -
branches/5.0/tests/phpunit/includes/testcase-rest-controller.php
r39177 r43720 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 } -
branches/5.0/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r43681 r43720 1115 1115 $data = $response->get_data(); 1116 1116 $properties = $data['schema']['properties']; 1117 $this->assertEquals( 2 4, count( $properties ) );1117 $this->assertEquals( 26, count( $properties ) ); 1118 1118 $this->assertArrayHasKey( 'author', $properties ); 1119 1119 $this->assertArrayHasKey( 'alt_text', $properties ); … … 1127 1127 $this->assertArrayHasKey( 'date', $properties ); 1128 1128 $this->assertArrayHasKey( 'date_gmt', $properties ); 1129 $this->assertArrayHasKey( 'generated_slug', $properties ); 1129 1130 $this->assertArrayHasKey( 'guid', $properties ); 1130 1131 $this->assertArrayHasKey( 'id', $properties ); … … 1138 1139 $this->assertArrayHasKey( 'post', $properties ); 1139 1140 $this->assertArrayHasKey( 'ping_status', $properties ); 1141 $this->assertArrayHasKey( 'permalink_template', $properties ); 1140 1142 $this->assertArrayHasKey( 'status', $properties ); 1141 1143 $this->assertArrayHasKey( 'slug', $properties ); -
branches/5.0/tests/phpunit/tests/rest-api/rest-pages-controller.php
r43445 r43720 526 526 $data = $response->get_data(); 527 527 $properties = $data['schema']['properties']; 528 $this->assertEquals( 2 2, count( $properties ) );528 $this->assertEquals( 24, count( $properties ) ); 529 529 $this->assertArrayHasKey( 'author', $properties ); 530 530 $this->assertArrayHasKey( 'comment_status', $properties ); … … 532 532 $this->assertArrayHasKey( 'date', $properties ); 533 533 $this->assertArrayHasKey( 'date_gmt', $properties ); 534 $this->assertArrayHasKey( 'generated_slug', $properties ); 534 535 $this->assertArrayHasKey( 'guid', $properties ); 535 536 $this->assertArrayHasKey( 'excerpt', $properties ); … … 543 544 $this->assertArrayHasKey( 'parent', $properties ); 544 545 $this->assertArrayHasKey( 'password', $properties ); 546 $this->assertArrayHasKey( 'permalink_template', $properties ); 545 547 $this->assertArrayHasKey( 'ping_status', $properties ); 546 548 $this->assertArrayHasKey( 'slug', $properties ); -
branches/5.0/tests/phpunit/tests/rest-api/rest-posts-controller.php
r43694 r43720 3095 3095 $data = $response->get_data(); 3096 3096 $properties = $data['schema']['properties']; 3097 $this->assertEquals( 2 4, count( $properties ) );3097 $this->assertEquals( 26, count( $properties ) ); 3098 3098 $this->assertArrayHasKey( 'author', $properties ); 3099 3099 $this->assertArrayHasKey( 'comment_status', $properties ); … … 3103 3103 $this->assertArrayHasKey( 'excerpt', $properties ); 3104 3104 $this->assertArrayHasKey( 'featured_media', $properties ); 3105 $this->assertArrayHasKey( 'generated_slug', $properties ); 3105 3106 $this->assertArrayHasKey( 'guid', $properties ); 3106 3107 $this->assertArrayHasKey( 'format', $properties ); … … 3111 3112 $this->assertArrayHasKey( 'modified_gmt', $properties ); 3112 3113 $this->assertArrayHasKey( 'password', $properties ); 3114 $this->assertArrayHasKey( 'permalink_template', $properties ); 3113 3115 $this->assertArrayHasKey( 'ping_status', $properties ); 3114 3116 $this->assertArrayHasKey( 'slug', $properties ); … … 3180 3182 'featured_media', 3181 3183 'format', 3184 'generated_slug', 3182 3185 'guid', 3183 3186 'id', … … 3187 3190 'modified_gmt', 3188 3191 'password', 3192 'permalink_template', 3189 3193 'ping_status', 3190 3194 'slug', … … 3685 3689 } 3686 3690 3691 public function test_generated_permalink_template_generated_slug_for_non_viewable_posts() { 3692 register_post_type( 3693 'private-post', 3694 array( 3695 'label' => 'Private Posts', 3696 'supports' => array( 'title', 'editor', 'author' ), 3697 'show_in_rest' => true, 3698 'publicly_queryable' => false, 3699 'public' => true, 3700 'rest_base' => 'private-post', 3701 ) 3702 ); 3703 create_initial_rest_routes(); 3704 3705 wp_set_current_user( self::$editor_id ); 3706 3707 $post_id = $this->factory->post->create( 3708 array( 3709 'post_title' => 'Permalink Template', 3710 'post_type' => 'private-post', 3711 'post_status' => 'draft', 3712 ) 3713 ); 3714 3715 // Neither 'permalink_template' and 'generated_slug' are expected for this post type. 3716 $request = new WP_REST_Request( 'GET', '/wp/v2/private-post/' . $post_id ); 3717 $request->set_param( 'context', 'edit' ); 3718 $response = rest_get_server()->dispatch( $request ); 3719 $data = $response->get_data(); 3720 $this->assertEquals( 200, $response->get_status() ); 3721 $this->assertArrayNotHasKey( 'permalink_template', $data ); 3722 $this->assertArrayNotHasKey( 'generated_slug', $data ); 3723 } 3724 3725 public function test_generated_permalink_template_generated_slug_for_posts() { 3726 $this->set_permalink_structure( '/%postname%/' ); 3727 $expected_permalink_template = trailingslashit( home_url( '/%postname%/' ) ); 3728 3729 wp_set_current_user( self::$editor_id ); 3730 3731 $post_id = $this->factory->post->create( 3732 array( 3733 'post_title' => 'Permalink Template', 3734 'post_type' => 'post', 3735 'post_status' => 'draft', 3736 ) 3737 ); 3738 3739 // Both 'permalink_template' and 'generated_slug' are expected for context=edit. 3740 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id ); 3741 $request->set_param( 'context', 'edit' ); 3742 $response = rest_get_server()->dispatch( $request ); 3743 $data = $response->get_data(); 3744 $this->assertEquals( 200, $response->get_status() ); 3745 $this->assertEquals( $expected_permalink_template, $data['permalink_template'] ); 3746 $this->assertEquals( 'permalink-template', $data['generated_slug'] ); 3747 3748 // Neither 'permalink_template' and 'generated_slug' are expected for context=view. 3749 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id ); 3750 $request->set_param( 'context', 'view' ); 3751 $response = rest_get_server()->dispatch( $request ); 3752 $data = $response->get_data(); 3753 $this->assertEquals( 200, $response->get_status() ); 3754 $this->assertArrayNotHasKey( 'permalink_template', $data ); 3755 $this->assertArrayNotHasKey( 'generated_slug', $data ); 3756 3757 } 3758 3687 3759 public function tearDown() { 3760 _unregister_post_type( 'private-post' ); 3688 3761 _unregister_post_type( 'youseeeme' ); 3689 3762 if ( isset( $this->attachment_id ) ) {
Note: See TracChangeset
for help on using the changeset viewer.