| 3995 | public function test_permalink_template_and_autogenerated_slug_for_edit_posts() { |
| 3996 | |
| 3997 | wp_set_current_user( self::$editor_id ); |
| 3998 | |
| 3999 | $permalink_structure = '%postname%'; |
| 4000 | $expected_permalink_template = trailingslashit( home_url( $permalink_structure ) ); |
| 4001 | $this->set_permalink_structure( "/$permalink_structure/" ); |
| 4002 | |
| 4003 | $post_id = $this->factory->post->create( |
| 4004 | array( |
| 4005 | 'post_title' => 'Permalink Template' |
| 4006 | ) |
| 4007 | ); |
| 4008 | |
| 4009 | $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); |
| 4010 | $request->set_param( 'context', 'edit' ); |
| 4011 | $response = rest_get_server()->dispatch( $request ); |
| 4012 | $this->check_get_post_response( $response, 'edit' ); |
| 4013 | $read_data = $response->get_data(); |
| 4014 | |
| 4015 | $this->assertArrayHasKey( 'permalink_template', $read_data ); |
| 4016 | $this->assertArrayHasKey( 'generated_slug', $read_data ); |
| 4017 | $this->assertEquals( $expected_permalink_template, $read_data['permalink_template'] ); |
| 4018 | $this->assertEquals( 'permalink-template', $read_data['generated_slug'] ); |
| 4019 | |
| 4020 | $request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/posts/%d', $post_id ) ); |
| 4021 | $params = array( |
| 4022 | 'title' => 'Permalink Template Slug', |
| 4023 | ); |
| 4024 | $request->set_body_params( $params ); |
| 4025 | $response = rest_get_server()->dispatch( $request ); |
| 4026 | $updated_data = $response->get_data(); |
| 4027 | |
| 4028 | $this->assertArrayHasKey( 'permalink_template', $updated_data ); |
| 4029 | $this->assertArrayHasKey( 'generated_slug', $updated_data ); |
| 4030 | $this->assertArrayHasKey( 'slug', $updated_data ); |
| 4031 | $this->assertEquals( $expected_permalink_template, $updated_data['permalink_template'] ); |
| 4032 | $this->assertEquals( 'permalink-template-slug', $updated_data['generated_slug'] ); |
| 4033 | $this->assertEquals( 'permalink-template', $updated_data['slug'] ); |
| 4034 | |
| 4035 | $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); |
| 4036 | $response = rest_get_server()->dispatch( $request ); |
| 4037 | $this->check_get_post_response( $response, 'view' ); |
| 4038 | $read_data = $response->get_data(); |
| 4039 | |
| 4040 | $this->assertArrayNotHasKey( 'permalink_template', $read_data ); |
| 4041 | $this->assertArrayNotHasKey( 'generated_slug', $read_data ); |
| 4042 | } |
| 4043 | |