Skip to content

REST API: Add unit tests for attachment fields copied when editing an image. - #14893

Open
irozum wants to merge 1 commit into
WordPress:trunkfrom
irozum:task/50675-edit-image-copy-fields-tests
Open

irozum wants to merge 1 commit into
WordPress:trunkfrom
irozum:task/50675-edit-image-copy-fields-tests

Conversation

@irozum

@irozum irozum commented Oct 26, 2026

Copy link
Copy Markdown

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

Summary

What: Adds PHPUnit coverage for WP_REST_Attachments_Controller::edit_media_item() copying data from the original attachment to the edited one. This is a test-only change; it touches no src/ files and adds no production behaviour.

Context: Follow-up to [48510], which added this behaviour. Nothing in trunk covers the fallback path: the existing test_edit_image_updates_attachment_fields() (#64035) only passes every field explicitly in the request.

Cases covered:

  • Request omits all fields: the new attachment inherits title, caption, description and alt text from the original.
  • Original has no alt text: no empty _wp_attachment_image_alt meta row is created on the new attachment.
  • Request supplies only title and alt_text: those win, while the omitted caption and description are still inherited (mixed precedence).

Verification: Each test was confirmed to fail when the matching code in edit_media_item() was temporarily broken (fallbacks removed, alt fallback removed, empty-alt guard removed, ??= changed to =, alt ternary swapped), then restored.

Out of scope: The EXIF image_meta merge from the same changeset; it depends on GD/Imagick EXIF output and could be a follow-up.

Use of AI Tools

This PR was prepared with Claude Code (Claude Sonnet 5.5), which wrote the tests and ran the verification above.

This pull request is for code review only. Please keep all discussion in the Trac ticket.

@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 irozum.

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