Skip to content

Tests: Add unit test coverage for the_shortlink() - #14455

Closed
rejaulalomkhan wants to merge 1 commit into
WordPress:trunkfrom
rejaulalomkhan:tests/the-shortlink
Closed

rejaulalomkhan wants to merge 1 commit into
WordPress:trunkfrom
rejaulalomkhan:tests/the-shortlink

Conversation

@rejaulalomkhan

Copy link
Copy Markdown

Adds unit test coverage for the_shortlink() in src/wp-includes/link-template.php.

Test scenarios covered:

  • Displaying default shortlink anchor markup with This is the short link. text.
  • Respecting custom link text (Short URL, Unicode strings, HTML entities, HTML markup) via @dataProvider.
  • Outputting before and after HTML markup surrounding the anchor tag.
  • Outputting only before or only after markup.
  • Verifying the the_shortlink filter hook arguments (receives $link, $shortlink, $text, $title).
  • Passing the unused $title argument to the filter for backward compatibility.
  • Customizing displayed output via the the_shortlink filter hook.
  • Respecting custom shortlinks provided by the pre_get_shortlink filter hook.
  • Outputting nothing (including no before/after markup) when shortlink is empty.
  • Generating valid shortlinks when pretty permalinks are enabled (/?p={id}).

Verification:

  • Single-site PHPUnit: OK (13 tests, 18 assertions)
  • Multisite PHPUnit: OK (13 tests, 18 assertions)
  • Randomized order PHPUnit: OK (13 tests, 18 assertions)
  • PHPCS (WordPress-Core): Clean (0 errors, 0 warnings)
  • Mutation testing: Verified 12 test failures when the echo statement is omitted.

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


Use of AI Tools: Antigravity (Gemini 2.5) was used to assist in test case ideation, code scaffolding, and formatting to WordPress core standards. All assertions and test outcomes were verified locally through PHPUnit and PHPCS.

Adds comprehensive PHPUnit tests covering default link text, custom link text via data provider, before/after HTML markup wrappers, unused title argument pass-through to filter, the the_shortlink filter hook, pre_get_shortlink filter support, empty shortlink handling, and pretty permalinks.

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. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props rejaulalomkhan.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

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 tests match existing behavior, and the test framework handles cleanup of modified state.

No open issues 🎉

What changed in this PR

Adds PHPUnit coverage for the_shortlink() without changing production code.

Changes:

  • Tests default and custom link text, plus surrounding markup.
  • Checks filter arguments, output customization, and empty shortlinks.
  • Exercises output with pretty permalinks enabled.
File Description
tests/​phpunit/​tests/​link/​theShortlink.php Adds shortlink output and filter tests with shared fixtures.

Review effort: Balanced

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output checks cover anchor text, wrappers, filter arguments and replacement output, and empty-shortlink suppression. Optional follow-up: use a custom shortlink containing ?a=1&b=2 and assert a literal ?a=1&b=2 href to protect escaping at the output boundary.

Unit-tests audit and Copilot review found no blockers. PHPCS passed all ten files. The combined batch passed locally in randomized order: single-site 149 tests / 283 assertions (seed 65825), multisite 140 tests / 236 assertions (seed 65826). CI is green on the reviewed commit.

AI review · gpt-6

wporg-sync pushed a commit that referenced this pull request Oct 19, 2026
Verify echoed short links, link text, surrounding markup, empty output, and filter arguments and results.

Developed in: #14455

Props rejaulalomkhan.
See #65819.


git-svn-id: https://develop.svn.wordpress.org/trunk@64547 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 19, 2026
Verify echoed short links, link text, surrounding markup, empty output, and filter arguments and results.

Developed in: WordPress/wordpress-develop#14455

Props rejaulalomkhan.
See #65819.

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


git-svn-id: http://core.svn.wordpress.org/trunk@63697 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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.

3 participants