From d3e78938c489df50557be5dba5d591bc104d698a Mon Sep 17 00:00:00 2001 From: Muhibul Haque Date: Sun, 1 Nov 2026 16:37:41 +0600 Subject: [PATCH] Tests: Cover post_type_archive_title(). See #65819. Props devmuhib009. --- .../tests/general/postTypeArchiveTitle.php | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 tests/phpunit/tests/general/postTypeArchiveTitle.php diff --git a/tests/phpunit/tests/general/postTypeArchiveTitle.php b/tests/phpunit/tests/general/postTypeArchiveTitle.php new file mode 100644 index 0000000000000..ae45852a2b517 --- /dev/null +++ b/tests/phpunit/tests/general/postTypeArchiveTitle.php @@ -0,0 +1,95 @@ + true, + 'has_archive' => true, + 'labels' => array( + 'name' => 'Custom Books', + ), + ) + ); + } + + /** + * Tests that post_type_archive_title() returns null when not on a post type archive. + * + * @ticket 65819 + */ + public function test_post_type_archive_title_returns_null_outside_archive() { + $this->go_to( '/' ); + + $this->assertNull( post_type_archive_title( '', false ) ); + } + + /** + * Tests that post_type_archive_title() displays the title on a post type archive. + * + * @ticket 65819 + */ + public function test_post_type_archive_title_should_display_on_archive() { + $this->go_to( '/?post_type=' . self::POST_TYPE ); + + $this->expectOutputString( 'Custom Books' ); + post_type_archive_title(); + } + + /** + * Tests that post_type_archive_title() returns the title when $display is false. + * + * @ticket 65819 + */ + 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 ) ); + } + + /** + * Tests that post_type_archive_title() prepends the prefix to the title. + * + * @ticket 65819 + */ + public function test_post_type_archive_title_prepends_prefix() { + $this->go_to( '/?post_type=' . self::POST_TYPE ); + + $this->expectOutputString( 'Archive: Custom Books' ); + post_type_archive_title( 'Archive: ' ); + } + + /** + * Tests that post_type_archive_title() respects the post_type_archive_title filter. + * + * @ticket 65819 + */ + public function test_post_type_archive_title_filter() { + $this->go_to( '/?post_type=' . self::POST_TYPE ); + + add_filter( + 'post_type_archive_title', + static function ( $title, $post_type ) { + return 'Filtered: ' . $title . ' (' . $post_type . ')'; + }, + 10, + 2 + ); + + $this->assertSame( 'Filtered: Custom Books (wptests_pt)', post_type_archive_title( '', false ) ); + } +}