Skip to content

Tests: Cover wp_post_mime_type_where(). - #14710

Open
ekamran wants to merge 1 commit into
WordPress:trunkfrom
ekamran:shifteq/test-wp-post-mime-type-where
Open

ekamran wants to merge 1 commit into
WordPress:trunkfrom
ekamran:shifteq/test-wp-post-mime-type-where

Conversation

@ekamran

@ekamran ekamran commented Oct 22, 2026 •

Copy link
Copy Markdown

Adds unit tests for wp_post_mime_type_where() in tests/phpunit/tests/post/wpPostMimeTypeWhere.php. The function builds the SQL clause for post_mime_type queries in WP_Query and wp_count_attachments(), and had no dedicated tests.

Trac ticket: https://core.trac.wordpress.org/ticket/65819

What the tests cover

  • A type alone or with a wildcard subtype (image, image/*, image/, image/**) gives LIKE 'image/%', and a full type gives =.
  • Subtypes keep +, . and - (image/svg+xml, application/vnd.ms-excel).
  • Whitespace is removed, and a comma-separated string gives the same clause as an array.
  • Characters that are not allowed in a mime type, such as quotes and spaces, are removed before the value is placed in the SQL.
  • '', '%' and '%/%' return no clause, also when they follow another type, and so does an empty array.
  • The table alias prefixes the column.

Test-only change.

Testing

npm run test:php -- --filter Tests_Post_WpPostMimeTypeWhere

All 19 test cases pass. Breaking the function in five ways (dropping + from subtypes, removing the wildcard check, keeping quotes in the type, ignoring the table alias, replacing only a single *) makes 1 to 4 of them fail each time.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code and Codex
Used for: Choosing the function, writing the tests, checking them against the function's real output, and auditing the tests and this description. I reviewed the tests and the results, and I take responsibility for the contribution.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Add coverage for full and wildcard mime types, the comma-separated and
array forms, removal of characters that are not allowed in a mime type,
the values that return no clause, and the table alias.

See #65819.
@github-actions

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 ekamran.

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.

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.

1 participant