Make WordPress Core

Ticket #31078: 31078.10.diff

File 31078.10.diff, 6.8 KB (added by obenland, 9 years ago)
  • tests/phpunit/tests/general/document-title.php

     
    88 */
    99class Tests_General_DocumentTitle extends WP_UnitTestCase {
    1010
     11        public $blog_name;
     12
    1113        function setUp() {
    1214                parent::setUp();
    1315
     
    3335                        'category'     => $this->category_id,
    3436                ) );
    3537
     38                $this->blog_name = get_option( 'blogname' );
     39
    3640                setup_postdata( get_post( $this->post_id ) );
    3741        }
    3842
     
    4549                add_theme_support( 'title-tag' );
    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( '/' );
    5070
    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
    5776        function _short_circuit_title( $title ) {
     
    6584
    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' );
    7290        }
     
    7694
    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
    83100        function _home_title_parts( $parts ) {
     
    93110
    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
    100116        function _paged_title_parts( $parts ) {
     
    111127
    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
    118133        function _singular_title_parts( $parts ) {
     
    126141        function test_category_title() {
    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
    133147        function test_search_title() {
    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
    140153        function test_author_title() {
    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
    147159        function test_post_type_archive_title() {
     
    159171
    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
    166177        function test_year_title() {
    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
    173183        function test_month_title() {
    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
    180189        function test_day_title() {
    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
    187195        function test_404_title() {
    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
    194201        function test_paged_post_title() {
     
    196203
    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
    203209        function _paged_post_title_parts( $parts ) {
     
    214220
    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
    221226        function _rearrange_title_parts( $parts ) {
     
    232237
    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
    239243        function _change_title_separator( $sep ) {