From 52204f7b279cc3c4d26f683f392045ec4a80f2a7 Mon Sep 17 00:00:00 2001 From: Konstantin Obenland Date: Wed, 21 Oct 2015 16:54:53 +0000 Subject: [PATCH] Tests: Use most specific function for document titles. Adds tests specific to `_wp_render_title_tag()`. See #31078. git-svn-id: https://develop.svn.wordpress.org/trunk@35334 602fd350-edb4-49c9-b593-d223f7449a82 --- .../phpunit/tests/general/document-title.php | 68 ++++++++++--------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/tests/phpunit/tests/general/document-title.php b/tests/phpunit/tests/general/document-title.php index 807ac777ae..19886a5c00 100644 --- a/tests/phpunit/tests/general/document-title.php +++ b/tests/phpunit/tests/general/document-title.php @@ -8,6 +8,8 @@ */ class Tests_General_DocumentTitle extends WP_UnitTestCase { + public $blog_name; + function setUp() { parent::setUp(); @@ -33,6 +35,8 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { 'category' => $this->category_id, ) ); + $this->blog_name = get_option( 'blogname' ); + setup_postdata( get_post( $this->post_id ) ); } @@ -45,13 +49,28 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { add_theme_support( 'title-tag' ); } + function test__wp_render_title_tag() { + $this->go_to( '/' ); + + $this->expectOutputString( sprintf( "%s – %s\n", $this->blog_name, get_option( 'blogdescription' ) ) ); + _wp_render_title_tag(); + } + + function test__wp_render_title_no_theme_support() { + $this->go_to( '/' ); + + remove_theme_support( 'title-tag' ); + + $this->expectOutputString( '' ); + _wp_render_title_tag(); + } + function test_short_circuiting_title() { $this->go_to( '/' ); add_filter( 'pre_get_document_title', array( $this, '_short_circuit_title' ) ); - $this->expectOutputString( "A Wild Title\n" ); - _wp_render_title_tag(); + $this->assertEquals( 'A Wild Title', wp_get_document_title() ); } function _short_circuit_title( $title ) { @@ -65,8 +84,7 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { $this->go_to( '/' ); - $this->expectOutputString( "front-page – " . get_option( 'blogname' ) . "\n" ); - _wp_render_title_tag(); + $this->assertEquals( sprintf( 'front-page – %s', $this->blog_name ), wp_get_document_title() ); update_option( 'show_on_front', 'posts' ); } @@ -76,8 +94,7 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { add_filter( 'document_title_parts', array( $this, '_home_title_parts' ) ); - $this->expectOutputString( "" . get_option( 'blogname' ) . " – Just another WordPress site\n" ); - _wp_render_title_tag(); + $this->assertEquals( sprintf( '%s – Just another WordPress site', $this->blog_name ), wp_get_document_title() ); } function _home_title_parts( $parts ) { @@ -93,8 +110,7 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { add_filter( 'document_title_parts', array( $this, '_paged_title_parts' ) ); - $this->expectOutputString( "" . get_option( 'blogname' ) . " – Page 4 – Just another WordPress site\n" ); - _wp_render_title_tag(); + $this->assertEquals( sprintf( '%s – Page 4 – Just another WordPress site', $this->blog_name ), wp_get_document_title() ); } function _paged_title_parts( $parts ) { @@ -111,8 +127,7 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { add_filter( 'document_title_parts', array( $this, '_singular_title_parts' ) ); - $this->expectOutputString( "test_title – " . get_option( 'blogname' ) . "\n" ); - _wp_render_title_tag(); + $this->assertEquals( sprintf( 'test_title – %s', $this->blog_name ), wp_get_document_title() ); } function _singular_title_parts( $parts ) { @@ -126,22 +141,19 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { function test_category_title() { $this->go_to( '?cat=' . $this->category_id ); - $this->expectOutputString( "test_category – " . get_option( 'blogname' ) . "\n" ); - _wp_render_title_tag(); + $this->assertEquals( sprintf( 'test_category – %s', $this->blog_name ), wp_get_document_title() ); } function test_search_title() { $this->go_to( '?s=test_title' ); - $this->expectOutputString( "Search Results for “test_title” – " . get_option( 'blogname' ) . "\n" ); - _wp_render_title_tag(); + $this->assertEquals( sprintf( 'Search Results for “test_title” – %s', $this->blog_name ), wp_get_document_title() ); } function test_author_title() { $this->go_to( '?author=' . $this->author_id ); - $this->expectOutputString( "test_author – " . get_option( 'blogname' ) . "\n" ); - _wp_render_title_tag(); + $this->assertEquals( sprintf( 'test_author – %s', $this->blog_name ), wp_get_document_title() ); } function test_post_type_archive_title() { @@ -159,36 +171,31 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { $this->go_to( '?post_type=cpt' ); - $this->expectOutputString( "test_cpt – " . get_option( 'blogname' ) . "\n" ); - _wp_render_title_tag(); + $this->assertEquals( sprintf( 'test_cpt – %s', $this->blog_name ), wp_get_document_title() ); } function test_year_title() { $this->go_to( '?year=2015' ); - $this->expectOutputString( "2015 – " . get_option( 'blogname' ) . "\n" ); - _wp_render_title_tag(); + $this->assertEquals( sprintf( '2015 – %s', $this->blog_name ), wp_get_document_title() ); } function test_month_title() { $this->go_to( '?monthnum=09' ); - $this->expectOutputString( "September 2015 – " . get_option( 'blogname' ) . "\n" ); - _wp_render_title_tag(); + $this->assertEquals( sprintf( 'September 2015 – %s', $this->blog_name ), wp_get_document_title() ); } function test_day_title() { $this->go_to( '?day=22' ); - $this->expectOutputString( "September 22, 2015 – " . get_option( 'blogname' ) . "\n" ); - _wp_render_title_tag(); + $this->assertEquals( sprintf( 'September 22, 2015 – %s', $this->blog_name ), wp_get_document_title() ); } function test_404_title() { $this->go_to( '?m=404' ); - $this->expectOutputString( "Page not found – " . get_option( 'blogname' ) . "\n" ); - _wp_render_title_tag(); + $this->assertEquals( sprintf( 'Page not found – %s', $this->blog_name ), wp_get_document_title() ); } function test_paged_post_title() { @@ -196,8 +203,7 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { add_filter( 'title_tag_parts', array( $this, '_paged_post_title_parts' ) ); - $this->expectOutputString( "test_title – Page 4 – " . get_option( 'blogname' ) . "\n" ); - _wp_render_title_tag(); + $this->assertEquals( sprintf( 'test_title – Page 4 – %s', $this->blog_name ), wp_get_document_title() ); } function _paged_post_title_parts( $parts ) { @@ -214,8 +220,7 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { add_filter( 'document_title_parts', array( $this, '_rearrange_title_parts' ) ); - $this->expectOutputString( "" . get_option( 'blogname' ) . " – test_title\n" ); - _wp_render_title_tag(); + $this->assertEquals( sprintf( '%s – test_title', $this->blog_name ), wp_get_document_title() ); } function _rearrange_title_parts( $parts ) { @@ -232,8 +237,7 @@ class Tests_General_DocumentTitle extends WP_UnitTestCase { add_filter( 'document_title_separator', array( $this, '_change_title_separator' ) ); - $this->expectOutputString( "test_title %% " . get_option( 'blogname' ) . "\n" ); - _wp_render_title_tag(); + $this->assertEquals( sprintf( 'test_title %%%% %s', $this->blog_name ), wp_get_document_title() ); } function _change_title_separator( $sep ) {