Skip to content

Tests: Extend wp_get_default_extension_for_mime_type() coverage - #15279

Closed
shail-mehta wants to merge 3 commits into
WordPress:trunkfrom
shail-mehta:tests/wp-get-default-extension-for-mime-type-65819
Closed

shail-mehta wants to merge 3 commits into
WordPress:trunkfrom
shail-mehta:tests/wp-get-default-extension-for-mime-type-65819

Conversation

@shail-mehta

@shail-mehta shail-mehta commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Trac ticket: #65819

What

Extends the existing Tests_Functions::test_wp_get_default_extension_for_mime_type() coverage with PDF and MP3 mime-to-extension mappings.

Test-only; no production code changes.

Why

JPEG, PNG, and unknown mime types were already covered. PDF and MP3 first-extension rows were missing and fit the #65819 cleanup track without a second class.

How

Update tests/phpunit/tests/functions.php:

  • Assert application/pdf → pdf
  • Assert audio/mpeg → mp3
  • Add @covers ::wp_get_default_extension_for_mime_type

Testing Instructions

  1. npm run test:php -- --filter test_wp_get_default_extension_for_mime_type
  2. npm run test:php -- --filter test_wp_get_default_extension_for_mime_type -c tests/phpunit/multisite.xml
  3. npm run test:php -- --filter test_wp_get_default_extension_for_mime_type --order-by=random
  4. npm run test:php -- --group functions

Use of AI Tools

  • Cursor

Add unit tests for known mime-to-extension mapping and unknown mime types.\n\nSee #65819.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for this test-only addition covering default extensions for known and unknown MIME types.

No open issues 🎉

What changed in this PR

Adds dedicated PHPUnit coverage for wp_get_default_extension_for_mime_type() as part of the #65819 test cleanup effort. No production code changes.

Changes:

  • Adds a test class with an explicit @covers annotation.
  • Checks the first mapped extension for JPEG, PNG, PDF, and MP3 MIME types.
  • Verifies that an unknown MIME type returns false.
File Description
tests/​phpunit/​tests/​functions/​wpGetDefaultExtensionForMimeType.php Adds data-driven tests for known MIME types and a test for unknown MIME types.

Review effort: Balanced

@shail-mehta
shail-mehta marked this pull request as ready for review October 31, 2026 17:27
@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props shailu25, lancewillett.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extend the existing Tests_Functions::test_wp_get_default_extension_for_mime_type() at tests/phpunit/tests/functions.php:2269–2277 instead. It already covers JPEG's first-extension choice, PNG, and unknown MIME types. PDF/MP3 are new literal rows, but do not require duplicating those existing scenarios in a second class.

Existing coverage.

This is a request to keep the coverage lean, not a reported runtime regression.

AI review · gpt-6

Add PDF and MP3 first-extension assertions to the existing helper test and drop the dedicated class.

See #65819.
@shail-mehta shail-mehta changed the title Tests: Add unit coverage for wp_get_default_extension_for_mime_type() Tests: Extend wp_get_default_extension_for_mime_type() coverage Nov 1, 2026
@shail-mehta
shail-mehta requested a balanced review from Copilot November 1, 2026 05:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are identified for the test-only MIME-to-extension coverage update.

No open issues 🎉

Review effort: Balanced

@shail-mehta

Copy link
Copy Markdown
Member Author

Thanks for the review!

Addressed in 4378927

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The revised patch addresses the earlier review requests.

Validated with the related helper patches on current trunk, randomized seed 1101: single-site 773 tests / 1,831 assertions; multisite 764 / 1,822. No failures or errors. The two existing PHPUnit warning-expectation deprecations and one skip were unchanged from the baseline.

Current-head CI and Copilot review checked.

AI review · gpt-6

wporg-sync pushed a commit that referenced this pull request Nov 1, 2026
Add literal extension-to-type and MIME-to-extension expectations to the existing tests for `wp_ext2type()` and `wp_get_default_extension_for_mime_type()`.

Developed in: #15278, #15279

Props shailu25.
See #65819.


git-svn-id: https://develop.svn.wordpress.org/trunk@65164 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 1, 2026
Add literal extension-to-type and MIME-to-extension expectations to the existing tests for `wp_ext2type()` and `wp_get_default_extension_for_mime_type()`.

Developed in: WordPress/wordpress-develop#15278, WordPress/wordpress-develop#15279

Props shailu25.
See #65819.

Built from https://develop.svn.wordpress.org/trunk@65164


git-svn-id: http://core.svn.wordpress.org/trunk@64313 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@lancewillett

Copy link
Copy Markdown
Member

@shail-mehta
shail-mehta deleted the tests/wp-get-default-extension-for-mime-type-65819 branch November 2, 2026 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants