WordPress.org

Make WordPress Core

Changeset 35334


Ignore:
Timestamp:
10/21/2015 04:54:53 PM (4 years ago)
Author:
obenland
Message:

Tests: Use most specific function for document titles.

Adds tests specific to _wp_render_title_tag().

See #31078.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/general/document-title.php

    r35329 r35334  
    88 */
    99class Tests_General_DocumentTitle extends WP_UnitTestCase {
     10
     11    public $blog_name;
    1012
    1113    function setUp() {
     
    3436        ) );
    3537
     38        $this->blog_name = get_option( 'blogname' );
     39
    3640        setup_postdata( get_post( $this->post_id ) );
    3741    }
     
    4650    }
    4751
     52    function test__wp_render_title_tag() {
     53        $this->go_to( '/' );
     54
     55        $this->expectOutputString( sprintf( "<title>%s &#8211; %s</title>\n", $this->blog_name, get_option( 'blogdescription' ) ) );
     56        _wp_render_title_tag();
     57    }
     58
     59    function test__wp_render_title_no_theme_support() {
     60        $this->go_to( '/' );
     61
     62        remove_theme_support( 'title-tag' );
     63
     64        $this->expectOutputString( '' );
     65        _wp_render_title_tag();
     66    }
     67
    4868    function test_short_circuiting_title() {
    4969        $this->go_to( '/' );
     
    5171        add_filter( 'pre_get_document_title', array( $this, '_short_circuit_title' ) );
    5272
    53         $this->expectOutputString( "<title>A Wild Title</title>\n" );
    54         _wp_render_title_tag();
     73        $this->assertEquals( 'A Wild Title', wp_get_document_title() );
    5574    }
    5675
     
    6685        $this->go_to( '/' );
    6786
    68         $this->expectOutputString( "<title>front-page &#8211; " . get_option( 'blogname' ) . "</title>\n" );
    69         _wp_render_title_tag();
     87        $this->assertEquals( sprintf( 'front-page &#8211; %s', $this->blog_name ), wp_get_document_title() );
    7088
    7189        update_option( 'show_on_front', 'posts' );
     
    7795        add_filter( 'document_title_parts', array( $this, '_home_title_parts' ) );
    7896
    79         $this->expectOutputString( "<title>" . get_option( 'blogname' ) . " &#8211; Just another WordPress site</title>\n" );
    80         _wp_render_title_tag();
     97        $this->assertEquals( sprintf( '%s &#8211; Just another WordPress site', $this->blog_name ), wp_get_document_title() );
    8198    }
    8299
     
    94111        add_filter( 'document_title_parts', array( $this, '_paged_title_parts' ) );
    95112
    96         $this->expectOutputString( "<title>" . get_option( 'blogname' ) . " &#8211; Page 4 &#8211; Just another WordPress site</title>\n" );
    97         _wp_render_title_tag();
     113        $this->assertEquals( sprintf( '%s &#8211; Page 4 &#8211; Just another WordPress site', $this->blog_name ), wp_get_document_title() );
    98114    }
    99115
     
    112128        add_filter( 'document_title_parts', array( $this, '_singular_title_parts' ) );
    113129
    114         $this->expectOutputString( "<title>test_title &#8211; " . get_option( 'blogname' ) . "</title>\n" );
    115         _wp_render_title_tag();
     130        $this->assertEquals( sprintf( 'test_title &#8211; %s', $this->blog_name ), wp_get_document_title() );
    116131    }
    117132
     
    127142        $this->go_to( '?cat=' . $this->category_id );
    128143
    129         $this->expectOutputString( "<title>test_category &#8211; " . get_option( 'blogname' ) . "</title>\n" );
    130         _wp_render_title_tag();
     144        $this->assertEquals( sprintf( 'test_category &#8211; %s', $this->blog_name ), wp_get_document_title() );
    131145    }
    132146
     
    134148        $this->go_to( '?s=test_title' );
    135149
    136         $this->expectOutputString( "<title>Search Results for &#8220;test_title&#8221; &#8211; " . get_option( 'blogname' ) . "</title>\n" );
    137         _wp_render_title_tag();
     150        $this->assertEquals( sprintf( 'Search Results for &#8220;test_title&#8221; &#8211; %s', $this->blog_name ), wp_get_document_title() );
    138151    }
    139152
     
    141154        $this->go_to( '?author=' . $this->author_id );
    142155
    143         $this->expectOutputString( "<title>test_author &#8211; " . get_option( 'blogname' ) . "</title>\n" );
    144         _wp_render_title_tag();
     156        $this->assertEquals( sprintf( 'test_author &#8211; %s', $this->blog_name ), wp_get_document_title() );
    145157    }
    146158
     
    160172        $this->go_to( '?post_type=cpt' );
    161173
    162         $this->expectOutputString( "<title>test_cpt &#8211; " . get_option( 'blogname' ) . "</title>\n" );
    163         _wp_render_title_tag();
     174        $this->assertEquals( sprintf( 'test_cpt &#8211; %s', $this->blog_name ), wp_get_document_title() );
    164175    }
    165176
     
    167178        $this->go_to( '?year=2015' );
    168179
    169         $this->expectOutputString( "<title>2015 &#8211; " . get_option( 'blogname' ) . "</title>\n" );
    170         _wp_render_title_tag();
     180        $this->assertEquals( sprintf( '2015 &#8211; %s', $this->blog_name ), wp_get_document_title() );
    171181    }
    172182
     
    174184        $this->go_to( '?monthnum=09' );
    175185
    176         $this->expectOutputString( "<title>September 2015 &#8211; " . get_option( 'blogname' ) . "</title>\n" );
    177         _wp_render_title_tag();
     186        $this->assertEquals( sprintf( 'September 2015 &#8211; %s', $this->blog_name ), wp_get_document_title() );
    178187    }
    179188
     
    181190        $this->go_to( '?day=22' );
    182191
    183         $this->expectOutputString( "<title>September 22, 2015 &#8211; " . get_option( 'blogname' ) . "</title>\n" );
    184         _wp_render_title_tag();
     192        $this->assertEquals( sprintf( 'September 22, 2015 &#8211; %s', $this->blog_name ), wp_get_document_title() );
    185193    }
    186194
     
    188196        $this->go_to( '?m=404' );
    189197
    190         $this->expectOutputString( "<title>Page not found &#8211; " . get_option( 'blogname' ) . "</title>\n" );
    191         _wp_render_title_tag();
     198        $this->assertEquals( sprintf( 'Page not found &#8211; %s', $this->blog_name ), wp_get_document_title() );
    192199    }
    193200
     
    197204        add_filter( 'title_tag_parts', array( $this, '_paged_post_title_parts' ) );
    198205
    199         $this->expectOutputString( "<title>test_title &#8211; Page 4 &#8211; " . get_option( 'blogname' ) . "</title>\n" );
    200         _wp_render_title_tag();
     206        $this->assertEquals( sprintf( 'test_title &#8211; Page 4 &#8211; %s', $this->blog_name ), wp_get_document_title() );
    201207    }
    202208
     
    215221        add_filter( 'document_title_parts', array( $this, '_rearrange_title_parts' ) );
    216222
    217         $this->expectOutputString( "<title>" . get_option( 'blogname' ) . " &#8211; test_title</title>\n" );
    218         _wp_render_title_tag();
     223        $this->assertEquals( sprintf( '%s &#8211; test_title', $this->blog_name ), wp_get_document_title() );
    219224    }
    220225
     
    233238        add_filter( 'document_title_separator', array( $this, '_change_title_separator' ) );
    234239
    235         $this->expectOutputString( "<title>test_title %% " . get_option( 'blogname' ) . "</title>\n" );
    236         _wp_render_title_tag();
     240        $this->assertEquals( sprintf( 'test_title %%%% %s', $this->blog_name ), wp_get_document_title() );
    237241    }
    238242
Note: See TracChangeset for help on using the changeset viewer.