Skip to content

Commit c3d189a

Browse files
committed
Add assertion for Auto Draft being title for CPT with title support
1 parent ff6e541 commit c3d189a

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

tests/phpunit/tests/admin/includesPost.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,22 +1341,31 @@ public function test_user_get_refreshed_metabox_nonce() {
13411341
}
13421342

13431343
/**
1344-
* Ensures default title empty when a CPT lacks title support.
1344+
* Ensures default title empty when a CPT lacks title support, and that it is present when it does.
13451345
*
13461346
* @ticket 45516
13471347
*
13481348
* @covers ::get_default_post_to_edit
13491349
*/
1350-
public function test_no_title_supported_when_title_not_supported() {
1350+
public function test_title_support_and_auto_draft_post_title() {
1351+
register_post_type(
1352+
'yes_title',
1353+
array(
1354+
'supports' => array( 'title', 'editor' ),
1355+
)
1356+
);
13511357
register_post_type(
13521358
'no_title',
13531359
array(
13541360
'supports' => array( 'editor' ),
13551361
)
13561362
);
13571363

1358-
$default_post = get_default_post_to_edit( 'no_title', true );
1359-
$post = get_post( $default_post->ID );
1360-
$this->assertSame( '', $post->post_title, 'Expected post_title to be an empty string.' );
1364+
// The ID is obtained because get_default_post_to_edit() will force the post_title to be overridden on the returned WP_Post object.
1365+
$default_no_title_post_id = get_default_post_to_edit( 'no_title', true )->ID;
1366+
$default_yes_title_post_id = get_default_post_to_edit( 'yes_title', true )->ID;
1367+
1368+
$this->assertSame( '', get_post( $default_no_title_post_id )->post_title, 'Expected post_title to be an empty string.' );
1369+
$this->assertSame( __( 'Auto Draft' ), get_post( $default_yes_title_post_id )->post_title, 'Expected post_title to be the default title.' );
13611370
}
13621371
}

0 commit comments

Comments
 (0)