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:
parent
f492a81d70
commit
52204f7b27
@ -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 – %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 – " . get_option( 'blogname' ) . "</title>\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( "<title>" . get_option( 'blogname' ) . " – Just another WordPress site</title>\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( "<title>" . get_option( 'blogname' ) . " – Page 4 – Just another WordPress site</title>\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( "<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 _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 – " . get_option( 'blogname' ) . "</title>\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( "<title>Search Results for “test_title” – " . get_option( 'blogname' ) . "</title>\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( "<title>test_author – " . get_option( 'blogname' ) . "</title>\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( "<title>test_cpt – " . get_option( 'blogname' ) . "</title>\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( "<title>2015 – " . get_option( 'blogname' ) . "</title>\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( "<title>September 2015 – " . get_option( 'blogname' ) . "</title>\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( "<title>September 22, 2015 – " . get_option( 'blogname' ) . "</title>\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( "<title>Page not found – " . get_option( 'blogname' ) . "</title>\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( "<title>test_title – Page 4 – " . get_option( 'blogname' ) . "</title>\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( "<title>" . get_option( 'blogname' ) . " – test_title</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( "<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 ) {
|
||||
|
Loading…
Reference in New Issue
Block a user