diff --git a/includes/handler/class-status.php b/includes/handler/class-status.php index 9f43dc4..a97c496 100644 --- a/includes/handler/class-status.php +++ b/includes/handler/class-status.php @@ -263,10 +263,11 @@ public function prepare_post_data( $post_id, $status_text, $in_reply_to_id, $med if ( $post_id ) { $post_data['ID'] = $post_id; } + $app = Mastodon_App::get_current_app(); $post_data['post_content'] = $status_text; $post_data['post_status'] = 'public' === $visibility ? 'publish' : 'private'; - $post_data['post_type'] = 'post'; + $post_data['post_type'] = $app->get_create_post_type(); $post_data['post_title'] = ''; if ( 'standard' === $post_format ) { @@ -277,7 +278,7 @@ public function prepare_post_data( $post_id, $status_text, $in_reply_to_id, $med } } - if ( ! Mastodon_App::get_current_app()->get_disable_blocks() ) { + if ( ! $app->get_disable_blocks() ) { $post_data['post_content'] = $this->convert_to_blocks( $post_data['post_content'] ); } diff --git a/tests/test-statuses-endpoint.php b/tests/test-statuses-endpoint.php index 2fce27b..90b55ca 100644 --- a/tests/test-statuses-endpoint.php +++ b/tests/test-statuses-endpoint.php @@ -79,6 +79,7 @@ public function submit_status_data_provider() { 'basic_status' => array( 'status' => 'test', 'new_format' => 'status', + 'new_post_type' => 'post', 'disable_blocks' => true, 'expected_title' => '', 'expected_content' => 'test', @@ -86,6 +87,7 @@ public function submit_status_data_provider() { 'basic_status_blocks' => array( 'status' => 'test', 'new_format' => 'status', + 'new_post_type' => 'post', 'disable_blocks' => false, 'expected_title' => '', 'expected_content' => "\n

test

\n", @@ -93,6 +95,7 @@ public function submit_status_data_provider() { 'basic_standard' => array( 'status' => 'test', 'new_format' => 'standard', + 'new_post_type' => 'post', 'disable_blocks' => true, 'expected_title' => '', 'expected_content' => 'test', @@ -100,13 +103,23 @@ public function submit_status_data_provider() { 'basic_standard_blocks' => array( 'status' => 'test', 'new_format' => 'standard', + 'new_post_type' => 'post', 'disable_blocks' => false, 'expected_title' => '', 'expected_content' => "\n

test

\n", ), + 'basic_cpt' => array( + 'status' => 'test', + 'new_format' => 'standard', + 'new_post_type' => 'my_custom_post_type', + 'disable_blocks' => true, + 'expected_title' => '', + 'expected_content' => 'test', + ), 'multiline_status' => array( 'status' => 'headline' . PHP_EOL . 'post_content', 'new_format' => 'status', + 'new_post_type' => 'post', 'disable_blocks' => true, 'expected_title' => '', 'expected_content' => 'headline' . PHP_EOL . 'post_content', @@ -114,6 +127,7 @@ public function submit_status_data_provider() { 'multiline_status_blocks' => array( 'status' => 'headline' . PHP_EOL . 'post_content', 'new_format' => 'status', + 'new_post_type' => 'post', 'disable_blocks' => false, 'expected_title' => '', 'expected_content' => "\n

headline

\n\n\n\n

post_content

\n", @@ -121,6 +135,7 @@ public function submit_status_data_provider() { 'multiline_standard' => array( 'status' => 'headline' . PHP_EOL . 'post_content', 'new_format' => 'standard', + 'new_post_type' => 'post', 'disable_blocks' => true, 'expected_title' => 'headline', 'expected_content' => 'post_content', @@ -128,6 +143,7 @@ public function submit_status_data_provider() { 'multiline_standard_blocks' => array( 'status' => 'headline' . PHP_EOL . 'post_content', 'new_format' => 'standard', + 'new_post_type' => 'post', 'disable_blocks' => false, 'expected_title' => 'headline', 'expected_content' => "\n

post_content

\n", @@ -141,13 +157,15 @@ public function submit_status_data_provider() { * @dataProvider submit_status_data_provider * @param string $status The status to submit. * @param string $new_format The new post format. + * @param string $new_post_type The new post type. * @param bool $disable_blocks Whether to disable blocks. * @param string $expected_title The expected post title. * @param string $expected_content The expected post content. * @return void */ - public function test_submit_status( $status, $new_format, $disable_blocks, $expected_title, $expected_content ) { + public function test_submit_status( $status, $new_format, $new_post_type, $disable_blocks, $expected_title, $expected_content ) { $this->app->set_post_formats( $new_format ); + $this->app->set_create_post_type( $new_post_type ); $this->app->set_disable_blocks( $disable_blocks ); $request = $this->api_request( 'POST', '/api/v1/statuses' ); @@ -161,6 +179,7 @@ public function test_submit_status( $status, $new_format, $disable_blocks, $expe $p = get_post( $data->id ); $this->assertEquals( $p->post_title, $expected_title ); $this->assertEquals( $p->post_content, $expected_content ); + $this->assertEquals( $p->post_type, $new_post_type ); } public function test_submit_status_reply() {