Ticket #31078: 31078.10.diff
File 31078.10.diff, 6.8 KB (added by , 9 years ago) |
---|
-
tests/phpunit/tests/general/document-title.php
8 8 */ 9 9 class Tests_General_DocumentTitle extends WP_UnitTestCase { 10 10 11 public $blog_name; 12 11 13 function setUp() { 12 14 parent::setUp(); 13 15 … … 33 35 'category' => $this->category_id, 34 36 ) ); 35 37 38 $this->blog_name = get_option( 'blogname' ); 39 36 40 setup_postdata( get_post( $this->post_id ) ); 37 41 } 38 42 … … 45 49 add_theme_support( 'title-tag' ); 46 50 } 47 51 52 function test__wp_render_title_tag() { 53 $this->go_to( '/' ); 54 55 $this->expectOutputString( sprintf( "<title>%s – %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 48 68 function test_short_circuiting_title() { 49 69 $this->go_to( '/' ); 50 70 51 71 add_filter( 'pre_get_document_title', array( $this, '_short_circuit_title' ) ); 52 72 53 $this->expectOutputString( "<title>A Wild Title</title>\n" ); 54 _wp_render_title_tag(); 73 $this->assertEquals( 'A Wild Title', wp_get_document_title() ); 55 74 } 56 75 57 76 function _short_circuit_title( $title ) { … … 65 84 66 85 $this->go_to( '/' ); 67 86 68 $this->expectOutputString( "<title>front-page – " . get_option( 'blogname' ) . "</title>\n" ); 69 _wp_render_title_tag(); 87 $this->assertEquals( sprintf( 'front-page – %s', $this->blog_name ), wp_get_document_title() ); 70 88 71 89 update_option( 'show_on_front', 'posts' ); 72 90 } … … 76 94 77 95 add_filter( 'document_title_parts', array( $this, '_home_title_parts' ) ); 78 96 79 $this->expectOutputString( "<title>" . get_option( 'blogname' ) . " – Just another WordPress site</title>\n" ); 80 _wp_render_title_tag(); 97 $this->assertEquals( sprintf( '%s – Just another WordPress site', $this->blog_name ), wp_get_document_title() ); 81 98 } 82 99 83 100 function _home_title_parts( $parts ) { … … 93 110 94 111 add_filter( 'document_title_parts', array( $this, '_paged_title_parts' ) ); 95 112 96 $this->expectOutputString( "<title>" . get_option( 'blogname' ) . " – Page 4 – Just another WordPress site</title>\n" ); 97 _wp_render_title_tag(); 113 $this->assertEquals( sprintf( '%s – Page 4 – Just another WordPress site', $this->blog_name ), wp_get_document_title() ); 98 114 } 99 115 100 116 function _paged_title_parts( $parts ) { … … 111 127 112 128 add_filter( 'document_title_parts', array( $this, '_singular_title_parts' ) ); 113 129 114 $this->expectOutputString( "<title>test_title – " . get_option( 'blogname' ) . "</title>\n" ); 115 _wp_render_title_tag(); 130 $this->assertEquals( sprintf( 'test_title – %s', $this->blog_name ), wp_get_document_title() ); 116 131 } 117 132 118 133 function _singular_title_parts( $parts ) { … … 126 141 function test_category_title() { 127 142 $this->go_to( '?cat=' . $this->category_id ); 128 143 129 $this->expectOutputString( "<title>test_category – " . get_option( 'blogname' ) . "</title>\n" ); 130 _wp_render_title_tag(); 144 $this->assertEquals( sprintf( 'test_category – %s', $this->blog_name ), wp_get_document_title() ); 131 145 } 132 146 133 147 function test_search_title() { 134 148 $this->go_to( '?s=test_title' ); 135 149 136 $this->expectOutputString( "<title>Search Results for “test_title” – " . get_option( 'blogname' ) . "</title>\n" ); 137 _wp_render_title_tag(); 150 $this->assertEquals( sprintf( 'Search Results for “test_title” – %s', $this->blog_name ), wp_get_document_title() ); 138 151 } 139 152 140 153 function test_author_title() { 141 154 $this->go_to( '?author=' . $this->author_id ); 142 155 143 $this->expectOutputString( "<title>test_author – " . get_option( 'blogname' ) . "</title>\n" ); 144 _wp_render_title_tag(); 156 $this->assertEquals( sprintf( 'test_author – %s', $this->blog_name ), wp_get_document_title() ); 145 157 } 146 158 147 159 function test_post_type_archive_title() { … … 159 171 160 172 $this->go_to( '?post_type=cpt' ); 161 173 162 $this->expectOutputString( "<title>test_cpt – " . get_option( 'blogname' ) . "</title>\n" ); 163 _wp_render_title_tag(); 174 $this->assertEquals( sprintf( 'test_cpt – %s', $this->blog_name ), wp_get_document_title() ); 164 175 } 165 176 166 177 function test_year_title() { 167 178 $this->go_to( '?year=2015' ); 168 179 169 $this->expectOutputString( "<title>2015 – " . get_option( 'blogname' ) . "</title>\n" ); 170 _wp_render_title_tag(); 180 $this->assertEquals( sprintf( '2015 – %s', $this->blog_name ), wp_get_document_title() ); 171 181 } 172 182 173 183 function test_month_title() { 174 184 $this->go_to( '?monthnum=09' ); 175 185 176 $this->expectOutputString( "<title>September 2015 – " . get_option( 'blogname' ) . "</title>\n" ); 177 _wp_render_title_tag(); 186 $this->assertEquals( sprintf( 'September 2015 – %s', $this->blog_name ), wp_get_document_title() ); 178 187 } 179 188 180 189 function test_day_title() { 181 190 $this->go_to( '?day=22' ); 182 191 183 $this->expectOutputString( "<title>September 22, 2015 – " . get_option( 'blogname' ) . "</title>\n" ); 184 _wp_render_title_tag(); 192 $this->assertEquals( sprintf( 'September 22, 2015 – %s', $this->blog_name ), wp_get_document_title() ); 185 193 } 186 194 187 195 function test_404_title() { 188 196 $this->go_to( '?m=404' ); 189 197 190 $this->expectOutputString( "<title>Page not found – " . get_option( 'blogname' ) . "</title>\n" ); 191 _wp_render_title_tag(); 198 $this->assertEquals( sprintf( 'Page not found – %s', $this->blog_name ), wp_get_document_title() ); 192 199 } 193 200 194 201 function test_paged_post_title() { … … 196 203 197 204 add_filter( 'title_tag_parts', array( $this, '_paged_post_title_parts' ) ); 198 205 199 $this->expectOutputString( "<title>test_title – Page 4 – " . get_option( 'blogname' ) . "</title>\n" ); 200 _wp_render_title_tag(); 206 $this->assertEquals( sprintf( 'test_title – Page 4 – %s', $this->blog_name ), wp_get_document_title() ); 201 207 } 202 208 203 209 function _paged_post_title_parts( $parts ) { … … 214 220 215 221 add_filter( 'document_title_parts', array( $this, '_rearrange_title_parts' ) ); 216 222 217 $this->expectOutputString( "<title>" . get_option( 'blogname' ) . " – test_title</title>\n" ); 218 _wp_render_title_tag(); 223 $this->assertEquals( sprintf( '%s – test_title', $this->blog_name ), wp_get_document_title() ); 219 224 } 220 225 221 226 function _rearrange_title_parts( $parts ) { … … 232 237 233 238 add_filter( 'document_title_separator', array( $this, '_change_title_separator' ) ); 234 239 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() ); 237 241 } 238 242 239 243 function _change_title_separator( $sep ) {