Skip to content

Tests: Resolve gallery attachment IDs after fixture setup - #14832

Closed
benitoalba wants to merge 1 commit into
WordPress:trunkfrom
benitoalba:benitoalba/66211-gallery-test-fixture
Closed

benitoalba wants to merge 1 commit into
WordPress:trunkfrom
benitoalba:benitoalba/66211-gallery-test-fixture

Conversation

@benitoalba

Copy link
Copy Markdown

shortcode_provider() runs before wpSetUpBeforeClass(), so the gallery datasets contain [gallery ids=" "] instead of the attachment ID. The allowed gallery case still succeeds, but adding a second attachment shows that its response can include unrelated media.

Return %d placeholders from the provider and fill them in when the test runs, after fixture setup. Add an unrelated attachment and check that the allowed gallery includes the intended caption and excludes the other one. All three datasets keep their existing success and rejection expectations.

This follows the optional follow-up on #14443. The fixture issue predates the conversion to a static provider.

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

Testing

Tested on PHP 8.3.36 with PHPUnit 9.6.36 and MariaDB:

  • With the original ID handling, the strengthened gallery case fails because the response contains the unrelated caption. With the fix, all 3 cases pass with 6 assertions on single site and multisite.
  • The full AJAX directory passes in randomized order (seed 66211): 190 tests and 1,113 assertions on single site; 202 tests and 805 assertions on multisite. Each run skips one test.
  • WordPress coding standards, PHP compatibility, and git diff --check pass.
php vendor/bin/phpunit --group ajax --test-suffix .php --order-by=random --random-order-seed=66211 tests/phpunit/tests/ajax/
php vendor/bin/phpunit -c tests/phpunit/multisite.xml --group ajax --test-suffix .php --order-by=random --random-order-seed=66211 tests/phpunit/tests/ajax/
php vendor/bin/phpcs tests/phpunit/tests/ajax/wpAjaxParseMediaShortcode.php
php vendor/bin/phpcs --standard=phpcompat.xml.dist tests/phpunit/tests/ajax/wpAjaxParseMediaShortcode.php

Use of AI Tools

AI assistance: Yes. OpenAI Codex researched the follow-up, wrote the change and assertions, ran local validation, and drafted this description.


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.

@benitoalba
benitoalba marked this pull request as ready for review October 25, 2026 19:32
@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 benitoalba.

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.

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

The focused test-only changes correct fixture timing and strengthen regression coverage without changing production behavior or rejection expectations.

No open issues 🎉

What changed in this PR

This test-only follow-up to #14443 fixes gallery attachment IDs being read before fixtures are initialized and strengthens coverage of the AJAX media-shortcode response.

Changes:

  • Resolve %d placeholders during test execution, after fixture setup.
  • Add an unrelated attachment and verify that only the intended caption appears.
  • Preserve all three datasets’ existing success and rejection expectations.
File Description
tests/​phpunit/​tests/​ajax/​wpAjaxParseMediaShortcode.php Defer attachment ID substitution and add assertions against unrelated gallery content.

Review effort: Balanced

wporg-sync pushed a commit that referenced this pull request Oct 26, 2026
Resolve the gallery shortcode's attachment ID during test execution instead of in the data provider, which runs before fixture setup. Add an unrelated attachment and assert that the response includes only the intended caption.

Preserve the existing success and rejection expectations for all three shortcode cases.

Developed in: #14832

Props benitoalba.
See #66211.


git-svn-id: https://develop.svn.wordpress.org/trunk@64747 602fd350-edb4-49c9-b593-d223f7449a82
@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 26, 2026
Resolve the gallery shortcode's attachment ID during test execution instead of in the data provider, which runs before fixture setup. Add an unrelated attachment and assert that the response includes only the intended caption.

Preserve the existing success and rejection expectations for all three shortcode cases.

Developed in: WordPress/wordpress-develop#14832

Props benitoalba.
See #66211.

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


git-svn-id: http://core.svn.wordpress.org/trunk@63897 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@benitoalba
benitoalba deleted the benitoalba/66211-gallery-test-fixture branch October 26, 2026 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants