From dc3617b398d0dfb0c7c0264ace3b480c00fda3a7 Mon Sep 17 00:00:00 2001 From: Muhibul Haque Date: Sun, 1 Nov 2026 16:32:26 +0600 Subject: [PATCH] Tests: Cover the_archive_title(). See #65819. Props devmuhib009. --- .../phpunit/tests/general/theArchiveTitle.php | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tests/phpunit/tests/general/theArchiveTitle.php diff --git a/tests/phpunit/tests/general/theArchiveTitle.php b/tests/phpunit/tests/general/theArchiveTitle.php new file mode 100644 index 0000000000000..ba5b4c6bc37c3 --- /dev/null +++ b/tests/phpunit/tests/general/theArchiveTitle.php @@ -0,0 +1,79 @@ +category->create( + array( + 'name' => 'News', + ) + ); + } + + /** + * Tests that the_archive_title() displays the title on a category archive. + * + * @ticket 65819 + */ + public function test_the_archive_title_should_display_on_category_archive() { + $this->go_to( get_category_link( self::$category_id ) ); + + $this->expectOutputString( 'Category: News' ); + the_archive_title(); + } + + /** + * Tests that the_archive_title() outputs before and after markup when provided. + * + * @ticket 65819 + */ + public function test_the_archive_title_should_output_before_and_after_markup() { + $this->go_to( get_category_link( self::$category_id ) ); + + $this->expectOutputString( '

Category: News

' ); + the_archive_title( '

', '

' ); + } + + /** + * Tests that the_archive_title() outputs the title without prefix when prefix is filtered to empty. + * + * @ticket 65819 + */ + public function test_the_archive_title_without_prefix() { + add_filter( 'get_the_archive_title_prefix', '__return_empty_string' ); + + $this->go_to( get_category_link( self::$category_id ) ); + + $this->expectOutputString( 'News' ); + the_archive_title(); + } + + /** + * Tests that the_archive_title() produces no output when the archive title is empty. + * + * @ticket 65819 + */ + public function test_the_archive_title_should_produce_no_output_when_title_is_empty() { + add_filter( 'get_the_archive_title', '__return_empty_string' ); + + $this->go_to( get_category_link( self::$category_id ) ); + + $this->expectOutputString( '' ); + the_archive_title( '

', '

' ); + } +}