Make WordPress Core

Opened 14 months ago

Last modified 14 months ago

#58163 new enhancement

Media Tests for Attachments and Images

Reported by: howdy_mcgee's profile Howdy_McGee Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.3
Component: Media Keywords: has-unit-tests has-patch
Focuses: Cc:


The attached patch adds PHPUnit Tests to the following functions:

  • wp_get_attachment_url()
  • wp_get_attachment_metadata()
  • image_downsize()
  • get_image_tag()
  • image_get_intermediate_size()
  • wp_get_attachment_image_src()
  • wp_get_attachment_image()

The tests are straight-forward and ensures that they are working as expected.

Attachments (1)

attachment-tests.diff (3.6 KB) - added by Howdy_McGee 14 months ago.
Unit Tests

Download all attachments as: .zip

Change History (6)

14 months ago

Unit Tests

#1 @mukesh27
14 months ago

Hi @Howdy_McGee, Thanks for the ticket and patch. Can you please open a PR against the repo so it will be easier to check the exiting tests and newly added tests in different PHP versions?

Also Quick review for the patch. Add ticket number in tests which you have added.

This ticket was mentioned in PR #4349 on WordPress/wordpress-develop by @kebbet.

14 months ago

I could not see an active github user account for Howdy_McGee, so I created a PR for them.

#3 @kebbet
14 months ago

A total novice at tests, but test_get_image_tag_empty_src is failing. Is the test written corectly? Can get_image_tag have an empty src attribute?

#4 @Howdy_McGee
14 months ago

@kebbet Thank you for creating a PR and testing the patch!

Looking at the `get_image_tag()` source, it looks like it does return an image tag with an empty src attribute. Whether it should do that is an entirely different question.

I've run these tests on PHP 5.6, 7.4, and 8.0 and haven't logged any issues. Could you share the specific errors that your system is logging and the PHP version you're using?

#5 @kebbet
14 months ago

The linked Pull Request at GitHub runs the test suit on commit, so linking to the latest test results, failures on PHP 8.1 and PHP 8.2.

There was 1 error:

1) Tests_Media::test_get_image_tag_empty_src
ltrim(): Passing null to parameter #1 ($string) of type string is deprecated

Note: See TracTickets for help on using tickets.