diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php index b198325f27cd8..91f77507d1728 100644 --- a/src/wp-admin/includes/dashboard.php +++ b/src/wp-admin/includes/dashboard.php @@ -603,6 +603,19 @@ function wp_dashboard_quick_press( $error_msg = false ) { + '; + } + ?> 'save-post' ) ); ?>
diff --git a/tests/e2e/specs/dashboard.test.js b/tests/e2e/specs/dashboard.test.js index 90459ac83ae6f..43eb09072d3dc 100644 --- a/tests/e2e/specs/dashboard.test.js +++ b/tests/e2e/specs/dashboard.test.js @@ -8,10 +8,16 @@ test.describe( 'Quick Draft', () => { await requestUtils.deleteAllPosts(); } ); - test( 'Allows draft to be created with Title and Content', async ( { + test( 'Allows draft to be created with Title and Content and check default post format', async ( { admin, - page + page, + requestUtils } ) => { + // First set the default post format to Quote. + await admin.visitAdminPage( 'options-writing.php' ); + await page.selectOption( '#default_post_format', 'quote' ); + await page.getByRole( 'button', { name: 'Save Changes' } ).click(); + await admin.visitAdminPage( '/' ); // Wait for Quick Draft title field to appear. @@ -37,6 +43,17 @@ test.describe( 'Quick Draft', () => { page.locator( '.drafts .draft-title' ).first().getByRole( 'link' ) ).toHaveText( 'Test Draft Title' ); + // Get the post ID from the URL of the first draft. + const draftLink = page.locator( '.drafts .draft-title' ).first().getByRole( 'link' ); + const draftUrl = await draftLink.getAttribute( 'href' ); + const draftId = draftUrl.match( /post=(\d+)/ )[ 1 ]; + + // Verify the post format is set to quote using the REST API. + const response = await requestUtils.rest( { + path: `/wp/v2/posts/${draftId}`, + } ); + expect( response.format ).toBe( 'quote' ); + // Check that new draft appears in Posts page await admin.visitAdminPage( '/edit.php' ); diff --git a/tests/phpunit/tests/admin/includesDashboard.php b/tests/phpunit/tests/admin/includesDashboard.php new file mode 100644 index 0000000000000..9753dc0b05ccb --- /dev/null +++ b/tests/phpunit/tests/admin/includesDashboard.php @@ -0,0 +1,62 @@ +user->create( array( 'role' => 'editor' ) ); + wp_set_current_user( $user_id ); + + add_theme_support( 'post-formats', array( 'aside', 'gallery', 'quote' ) ); + update_option( 'default_post_format', 'quote' ); + + set_current_screen( 'dashboard' ); + + ob_start(); + wp_dashboard_quick_press(); + $output = ob_get_clean(); + + $this->assertStringContainsString( 'name="post_format"', $output ); + $this->assertStringContainsString( 'value="quote"', $output ); + + // Clean up or there will be a collision with other tests. + delete_option( 'default_post_format' ); + remove_theme_support( 'post-formats' ); + } +}