Skip to content

Tests: Add unit test coverage for the_time() - #14447

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

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

Conversation

@rejaulalomkhan

Copy link
Copy Markdown

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

Test scenarios covered:

  • Displaying post time in default format matching get_option( 'time_format' ).
  • Respecting various custom date/time formats (H:i:s, g:i a, Y-m-d H:i, l, H, i) via @dataProvider.
  • Respecting changes to the time_format option when no format argument is supplied.
  • Outputting nothing when no global $post exists.
  • The the_time filter hook arguments verification (receives $get_the_time and $format).
  • Customizing displayed output via the the_time filter hook.
  • Respecting the underlying get_the_time filter hook.

Verification:

  • Single-site PHPUnit: OK (12 tests, 15 assertions)
  • Multisite PHPUnit: OK (12 tests, 15 assertions)
  • Randomized order PHPUnit: OK (12 tests, 15 assertions)
  • Full date test group: OK (363 tests, 1286 assertions)
  • PHPCS (WordPress-Core): Clean (0 errors, 0 warnings)
  • Mutation testing: Verified intentional 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 time formatting, custom format strings via data provider, the time_format option, missing global post fallback, and the the_time and get_the_time filter hooks.

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 focused tests match existing behavior and test isolation mechanisms, with no unresolved findings.

No open issues 🎉

What changed in this PR

Adds unit coverage for WordPress’s the_time() template function without changing production code.

Changes:

  • Tests default, custom, and option-based time formats.
  • Checks empty output when no global post exists.
  • Verifies filter arguments and filtered output.
File Description
tests/​phpunit/​tests/​date/​theTime.php Adds fixtures and tests for formatting, missing posts, and filters.

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, configured-format, and filter cases protect the display contract. Optional cleanup: remove the computed-default expectation; the literal time-format option case already covers omitted-format behavior.

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

@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit that referenced this pull request Oct 19, 2026
Verify echoed post times, explicit and configured formats, missing posts, and display and retrieval filters.

Developed in: #14447

Props rejaulalomkhan.
See #65819.


git-svn-id: https://develop.svn.wordpress.org/trunk@64541 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 19, 2026
Verify echoed post times, explicit and configured formats, missing posts, and display and retrieval filters.

Developed in: WordPress/wordpress-develop#14447

Props rejaulalomkhan.
See #65819.

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


git-svn-id: http://core.svn.wordpress.org/trunk@63691 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