Make WordPress Core

Opened 8 weeks ago

Last modified 8 weeks ago

#65931 new defect (bug)

Add tests for get_media_embedded_in_content()

Reported by: afercia Owned by:
Priority: normal Milestone: Awaiting Review
Component: Media Version:
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

Description

Related: #26674, #59791.

In #26674, tests are going to be added for get_tag_regex() although that function has no current use in Core.

get_media_embedded_in_content uses a regular expression that is very similar (basically the same one) to the one used in get_tag_regex(). The purpose of the function is similar as well, although a little more specialized.

All the more so, it would be good to have tests for get_media_embedded_in_content.

For history, get_tag_regex() was introduced in [23729] and I couldn't find any usage of the function in that commit. It was later used internally in get_media_embedded_in_content() and removed in [31574].

Today, get_media_embedded_in_content() uses its own regex.

Change History (1)

This ticket was mentioned in ​PR #13222 on ​WordPress/wordpress-develop by ​@khokansardar.


8 weeks ago
#1

  • Keywords has-patch has-unit-tests added

get_media_embedded_in_content() has two tests in tests/phpunit/tests/media.php, both covering the same happy path: well-formed markup, one element per type.

This adds tests/phpunit/tests/media/getMediaEmbeddedInContent.php for the paths they leave out — the default $types argument, an empty array of types, the media_embedded_in_content_allowed_types filter narrowing and extending the list, repeated elements of one type, both self-closing forms, and markup the pattern is not meant to match. Fixtures sit inside surrounding content, matching the shape asked for on the get_tag_regex() PR 13037.

The repeated-element case pins the lazy body match that get_tag_regex() lacks.

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

## Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: characterizing the function's current behaviour and writing the test cases. All changes were reviewed and validated by me.

Note: See TracTickets for help on using tickets.