Skip to content

Tests: Cover post_type_archive_title() - #15319

Closed
devmuhib009 wants to merge 1 commit into
WordPress:trunkfrom
devmuhib009:tests/65819-cover-post-type-archive-title
Closed

devmuhib009 wants to merge 1 commit into
WordPress:trunkfrom
devmuhib009:tests/65819-cover-post-type-archive-title

Conversation

@devmuhib009

Copy link
Copy Markdown
Member

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

This PR adds unit tests for post_type_archive_title() covering:

  • Returning null when queried outside a post type archive
  • Displaying the post type title on an archive
  • Returning the post type title when $display is false
  • Prepending custom $prefix to the title
  • Filtering via the post_type_archive_title filter hook

@github-actions

github-actions Bot commented Nov 1, 2026

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 devmuhib.

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

No active review issues are recorded for this test-only addition covering post_type_archive_title() behavior.

No open issues 🎉

What changed in this PR

Adds unit tests for post_type_archive_title() to WordPress’s general template test suite, addressing Trac ticket #65819. No production code changes are included.

Changes:

  • Verifies null is returned outside a post type archive.
  • Covers title display, returning the title with $display = false, and custom prefixes.
  • Checks that the filter receives the title and post type and can modify the result.
File Description
tests/​phpunit/​tests/​general/​postTypeArchiveTitle.php Adds a custom post type fixture and five tests for archive title behavior.

Review effort: Balanced

@huzaifaalmesbah huzaifaalmesbah 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.

I left a few small notes inline.

AI Review: Opus 5.5

public function test_post_type_archive_title_returns_when_display_is_false() {
$this->go_to( '/?post_type=' . self::POST_TYPE );

$this->assertSame( 'Custom Books', post_type_archive_title( '', false ) );

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.

This one looks like a small coverage gap: the prefix is only tested when displaying, so a lost prefix in return $prefix . $title goes unnoticed. Could you add $this->assertSame( 'Archive: Custom Books', post_type_archive_title( 'Archive: ', false ) );?

2
);

$this->assertSame( 'Filtered: Custom Books (wptests_pt)', post_type_archive_title( '', false ) );

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.

Another small gap: the is_array( $post_type ) branch isn't reached yet. A query string won't get there, because is_post_type_archive() is false for an array, but set_query_var( 'post_type', array( self::POST_TYPE, 'post' ) ) after go_to() does. Could you add a test for it?

@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.

Reviewed the changed code against the implementation and existing coverage; no blocking issue found.

Validated with the related behavioral coverage patches on current trunk: 35 tests / 43 assertions in each of single-site and multisite, randomized seed 1101. No failures, errors, warnings, or skips.

Current-head CI and Copilot review checked.

AI review · gpt-6

wporg-sync pushed a commit that referenced this pull request Nov 1, 2026
Cover body-opening output, post type descriptions, archive descriptions and titles, and post type archive titles. Verify relevant display filters and return behavior.

Developed in: #15240, #15241, #15242, #15315, #15319

Props devmuhib, huzaifaalmesbah.
See #65819.


git-svn-id: https://develop.svn.wordpress.org/trunk@65171 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 1, 2026
Cover body-opening output, post type descriptions, archive descriptions and titles, and post type archive titles. Verify relevant display filters and return behavior.

Developed in: WordPress/wordpress-develop#15240, WordPress/wordpress-develop#15241, WordPress/wordpress-develop#15242, WordPress/wordpress-develop#15315, WordPress/wordpress-develop#15319

Props devmuhib, huzaifaalmesbah.
See #65819.

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


git-svn-id: http://core.svn.wordpress.org/trunk@64320 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@lancewillett

Copy link
Copy Markdown
Member

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.

4 participants