Skip to content

Commit

Permalink
Merge pull request #175 from akirk/fix-create-post-type
Browse files Browse the repository at this point in the history
Fix ignored create post type
  • Loading branch information
akirk authored Sep 26, 2024
2 parents 89a7c21 + 5629dda commit e0166a6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
5 changes: 3 additions & 2 deletions includes/handler/class-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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'] );
}

Expand Down
21 changes: 20 additions & 1 deletion tests/test-statuses-endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,55 +79,71 @@ 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',
),
'basic_status_blocks' => array(
'status' => 'test',
'new_format' => 'status',
'new_post_type' => 'post',
'disable_blocks' => false,
'expected_title' => '',
'expected_content' => "<!-- wp:paragraph -->\n<p>test</p>\n<!-- /wp:paragraph -->",
),
'basic_standard' => array(
'status' => 'test',
'new_format' => 'standard',
'new_post_type' => 'post',
'disable_blocks' => true,
'expected_title' => '',
'expected_content' => 'test',
),
'basic_standard_blocks' => array(
'status' => 'test',
'new_format' => 'standard',
'new_post_type' => 'post',
'disable_blocks' => false,
'expected_title' => '',
'expected_content' => "<!-- wp:paragraph -->\n<p>test</p>\n<!-- /wp:paragraph -->",
),
'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',
),
'multiline_status_blocks' => array(
'status' => 'headline' . PHP_EOL . 'post_content',
'new_format' => 'status',
'new_post_type' => 'post',
'disable_blocks' => false,
'expected_title' => '',
'expected_content' => "<!-- wp:paragraph -->\n<p>headline</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>post_content</p>\n<!-- /wp:paragraph -->",
),
'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',
),
'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' => "<!-- wp:paragraph -->\n<p>post_content</p>\n<!-- /wp:paragraph -->",
Expand All @@ -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' );
Expand All @@ -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() {
Expand Down

0 comments on commit e0166a6

Please sign in to comment.