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
This commit is contained in:
Konstantin Obenland 2015-10-21 16:54:53 +00:00
parent f492a81d70
commit 52204f7b27
1 changed files with 36 additions and 32 deletions

View File

@ -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( "<title>%s &#8211; %s</title>\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( "<title>A Wild Title</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( "<title>front-page &#8211; " . get_option( 'blogname' ) . "</title>\n" );
_wp_render_title_tag();
$this->assertEquals( sprintf( 'front-page &#8211; %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( "<title>" . get_option( 'blogname' ) . " &#8211; Just another WordPress site</title>\n" );
_wp_render_title_tag();
$this->assertEquals( sprintf( '%s &#8211; 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( "<title>" . get_option( 'blogname' ) . " &#8211; Page 4 &#8211; Just another WordPress site</title>\n" );
_wp_render_title_tag();
$this->assertEquals( sprintf( '%s &#8211; Page 4 &#8211; 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( "<title>test_title &#8211; " . get_option( 'blogname' ) . "</title>\n" );
_wp_render_title_tag();
$this->assertEquals( sprintf( 'test_title &#8211; %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( "<title>test_category &#8211; " . get_option( 'blogname' ) . "</title>\n" );
_wp_render_title_tag();
$this->assertEquals( sprintf( 'test_category &#8211; %s', $this->blog_name ), wp_get_document_title() );
}
function test_search_title() {
$this->go_to( '?s=test_title' );
$this->expectOutputString( "<title>Search Results for &#8220;test_title&#8221; &#8211; " . get_option( 'blogname' ) . "</title>\n" );
_wp_render_title_tag();
$this->assertEquals( sprintf( 'Search Results for &#8220;test_title&#8221; &#8211; %s', $this->blog_name ), wp_get_document_title() );
}
function test_author_title() {
$this->go_to( '?author=' . $this->author_id );
$this->expectOutputString( "<title>test_author &#8211; " . get_option( 'blogname' ) . "</title>\n" );
_wp_render_title_tag();
$this->assertEquals( sprintf( 'test_author &#8211; %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( "<title>test_cpt &#8211; " . get_option( 'blogname' ) . "</title>\n" );
_wp_render_title_tag();
$this->assertEquals( sprintf( 'test_cpt &#8211; %s', $this->blog_name ), wp_get_document_title() );
}
function test_year_title() {
$this->go_to( '?year=2015' );
$this->expectOutputString( "<title>2015 &#8211; " . get_option( 'blogname' ) . "</title>\n" );
_wp_render_title_tag();
$this->assertEquals( sprintf( '2015 &#8211; %s', $this->blog_name ), wp_get_document_title() );
}
function test_month_title() {
$this->go_to( '?monthnum=09' );
$this->expectOutputString( "<title>September 2015 &#8211; " . get_option( 'blogname' ) . "</title>\n" );
_wp_render_title_tag();
$this->assertEquals( sprintf( 'September 2015 &#8211; %s', $this->blog_name ), wp_get_document_title() );
}
function test_day_title() {
$this->go_to( '?day=22' );
$this->expectOutputString( "<title>September 22, 2015 &#8211; " . get_option( 'blogname' ) . "</title>\n" );
_wp_render_title_tag();
$this->assertEquals( sprintf( 'September 22, 2015 &#8211; %s', $this->blog_name ), wp_get_document_title() );
}
function test_404_title() {
$this->go_to( '?m=404' );
$this->expectOutputString( "<title>Page not found &#8211; " . get_option( 'blogname' ) . "</title>\n" );
_wp_render_title_tag();
$this->assertEquals( sprintf( 'Page not found &#8211; %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( "<title>test_title &#8211; Page 4 &#8211; " . get_option( 'blogname' ) . "</title>\n" );
_wp_render_title_tag();
$this->assertEquals( sprintf( 'test_title &#8211; Page 4 &#8211; %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( "<title>" . get_option( 'blogname' ) . " &#8211; test_title</title>\n" );
_wp_render_title_tag();
$this->assertEquals( sprintf( '%s &#8211; 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( "<title>test_title %% " . get_option( 'blogname' ) . "</title>\n" );
_wp_render_title_tag();
$this->assertEquals( sprintf( 'test_title %%%% %s', $this->blog_name ), wp_get_document_title() );
}
function _change_title_separator( $sep ) {