Changeset 42343 for trunk/tests/phpunit/tests/template.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/template.php
r40559 r42343 15 15 16 16 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 17 self::$page_on_front = $factory->post->create_and_get( array( 18 'post_type' => 'page', 19 'post_name' => 'page-on-front-😀', 20 ) ); 21 22 self::$page_for_posts = $factory->post->create_and_get( array( 23 'post_type' => 'page', 24 'post_name' => 'page-for-posts-😀', 25 ) ); 26 27 self::$page = $factory->post->create_and_get( array( 28 'post_type' => 'page', 29 'post_name' => 'page-name-😀', 30 ) ); 17 self::$page_on_front = $factory->post->create_and_get( 18 array( 19 'post_type' => 'page', 20 'post_name' => 'page-on-front-😀', 21 ) 22 ); 23 24 self::$page_for_posts = $factory->post->create_and_get( 25 array( 26 'post_type' => 'page', 27 'post_name' => 'page-for-posts-😀', 28 ) 29 ); 30 31 self::$page = $factory->post->create_and_get( 32 array( 33 'post_type' => 'page', 34 'post_name' => 'page-name-😀', 35 ) 36 ); 31 37 add_post_meta( self::$page->ID, '_wp_page_template', 'templates/page.php' ); 32 38 33 self::$post = $factory->post->create_and_get( array( 34 'post_type' => 'post', 35 'post_name' => 'post-name-😀', 36 'post_date' => '1984-02-25 12:34:56', 37 ) ); 39 self::$post = $factory->post->create_and_get( 40 array( 41 'post_type' => 'post', 42 'post_name' => 'post-name-😀', 43 'post_date' => '1984-02-25 12:34:56', 44 ) 45 ); 38 46 set_post_format( self::$post, 'quote' ); 39 47 add_post_meta( self::$post->ID, '_wp_page_template', 'templates/post.php' ); … … 42 50 public function setUp() { 43 51 parent::setUp(); 44 register_post_type( 'cpt', array( 45 'public' => true, 46 ) ); 47 register_taxonomy( 'taxo', 'post', array( 48 'public' => true, 49 'hierarchical' => true, 50 ) ); 52 register_post_type( 53 'cpt', array( 54 'public' => true, 55 ) 56 ); 57 register_taxonomy( 58 'taxo', 'post', array( 59 'public' => true, 60 'hierarchical' => true, 61 ) 62 ); 51 63 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 52 64 } … … 61 73 62 74 public function test_404_template_hierarchy() { 63 $url = add_query_arg( array( 64 'p' => '-1', 65 ), home_url() ); 66 67 $this->assertTemplateHierarchy( $url, array( 68 '404.php', 69 ) ); 75 $url = add_query_arg( 76 array( 77 'p' => '-1', 78 ), home_url() 79 ); 80 81 $this->assertTemplateHierarchy( 82 $url, array( 83 '404.php', 84 ) 85 ); 70 86 } 71 87 72 88 public function test_author_template_hierarchy() { 73 $author = self::factory()->user->create_and_get( array( 74 'user_nicename' => 'foo', 75 ) ); 76 77 $this->assertTemplateHierarchy( get_author_posts_url( $author->ID ), array( 78 'author-foo.php', 79 "author-{$author->ID}.php", 80 'author.php', 81 'archive.php', 82 ) ); 89 $author = self::factory()->user->create_and_get( 90 array( 91 'user_nicename' => 'foo', 92 ) 93 ); 94 95 $this->assertTemplateHierarchy( 96 get_author_posts_url( $author->ID ), array( 97 'author-foo.php', 98 "author-{$author->ID}.php", 99 'author.php', 100 'archive.php', 101 ) 102 ); 83 103 } 84 104 85 105 public function test_category_template_hierarchy() { 86 $term = self::factory()->term->create_and_get( array( 87 'taxonomy' => 'category', 88 'slug' => 'foo-😀', 89 ) ); 90 91 $this->assertTemplateHierarchy( get_term_link( $term ), array( 92 'category-foo-😀.php', 93 'category-foo-%f0%9f%98%80.php', 94 "category-{$term->term_id}.php", 95 'category.php', 96 'archive.php', 97 ) ); 106 $term = self::factory()->term->create_and_get( 107 array( 108 'taxonomy' => 'category', 109 'slug' => 'foo-😀', 110 ) 111 ); 112 113 $this->assertTemplateHierarchy( 114 get_term_link( $term ), array( 115 'category-foo-😀.php', 116 'category-foo-%f0%9f%98%80.php', 117 "category-{$term->term_id}.php", 118 'category.php', 119 'archive.php', 120 ) 121 ); 98 122 } 99 123 100 124 public function test_tag_template_hierarchy() { 101 $term = self::factory()->term->create_and_get( array( 102 'taxonomy' => 'post_tag', 103 'slug' => 'foo-😀', 104 ) ); 105 106 $this->assertTemplateHierarchy( get_term_link( $term ), array( 107 'tag-foo-😀.php', 108 'tag-foo-%f0%9f%98%80.php', 109 "tag-{$term->term_id}.php", 110 'tag.php', 111 'archive.php', 112 ) ); 125 $term = self::factory()->term->create_and_get( 126 array( 127 'taxonomy' => 'post_tag', 128 'slug' => 'foo-😀', 129 ) 130 ); 131 132 $this->assertTemplateHierarchy( 133 get_term_link( $term ), array( 134 'tag-foo-😀.php', 135 'tag-foo-%f0%9f%98%80.php', 136 "tag-{$term->term_id}.php", 137 'tag.php', 138 'archive.php', 139 ) 140 ); 113 141 } 114 142 115 143 public function test_taxonomy_template_hierarchy() { 116 $term = self::factory()->term->create_and_get( array( 117 'taxonomy' => 'taxo', 118 'slug' => 'foo-😀', 119 ) ); 120 121 $this->assertTemplateHierarchy( get_term_link( $term ), array( 122 'taxonomy-taxo-foo-😀.php', 123 'taxonomy-taxo-foo-%f0%9f%98%80.php', 124 'taxonomy-taxo.php', 125 'taxonomy.php', 126 'archive.php', 127 ) ); 144 $term = self::factory()->term->create_and_get( 145 array( 146 'taxonomy' => 'taxo', 147 'slug' => 'foo-😀', 148 ) 149 ); 150 151 $this->assertTemplateHierarchy( 152 get_term_link( $term ), array( 153 'taxonomy-taxo-foo-😀.php', 154 'taxonomy-taxo-foo-%f0%9f%98%80.php', 155 'taxonomy-taxo.php', 156 'taxonomy.php', 157 'archive.php', 158 ) 159 ); 128 160 } 129 161 130 162 public function test_date_template_hierarchy_for_year() { 131 $this->assertTemplateHierarchy( get_year_link( 1984 ), array( 132 'date.php', 133 'archive.php', 134 ) ); 163 $this->assertTemplateHierarchy( 164 get_year_link( 1984 ), array( 165 'date.php', 166 'archive.php', 167 ) 168 ); 135 169 } 136 170 137 171 public function test_date_template_hierarchy_for_month() { 138 $this->assertTemplateHierarchy( get_month_link( 1984, 2 ), array( 139 'date.php', 140 'archive.php', 141 ) ); 172 $this->assertTemplateHierarchy( 173 get_month_link( 1984, 2 ), array( 174 'date.php', 175 'archive.php', 176 ) 177 ); 142 178 } 143 179 144 180 public function test_date_template_hierarchy_for_day() { 145 $this->assertTemplateHierarchy( get_day_link( 1984, 2, 25 ), array( 146 'date.php', 147 'archive.php', 148 ) ); 181 $this->assertTemplateHierarchy( 182 get_day_link( 1984, 2, 25 ), array( 183 'date.php', 184 'archive.php', 185 ) 186 ); 149 187 } 150 188 151 189 public function test_search_template_hierarchy() { 152 $url = add_query_arg( array( 153 's' => 'foo', 154 ), home_url() ); 155 156 $this->assertTemplateHierarchy( $url, array( 157 'search.php', 158 ) ); 190 $url = add_query_arg( 191 array( 192 's' => 'foo', 193 ), home_url() 194 ); 195 196 $this->assertTemplateHierarchy( 197 $url, array( 198 'search.php', 199 ) 200 ); 159 201 } 160 202 161 203 public function test_front_page_template_hierarchy_with_posts_on_front() { 162 204 $this->assertEquals( 'posts', get_option( 'show_on_front' ) ); 163 $this->assertTemplateHierarchy( home_url(), array( 164 'front-page.php', 165 'home.php', 166 'index.php', 167 ) ); 205 $this->assertTemplateHierarchy( 206 home_url(), array( 207 'front-page.php', 208 'home.php', 209 'index.php', 210 ) 211 ); 168 212 } 169 213 … … 173 217 update_option( 'page_for_posts', self::$page_for_posts->ID ); 174 218 175 $this->assertTemplateHierarchy( home_url(), array( 176 'front-page.php', 177 'page-page-on-front-😀.php', 178 'page-page-on-front-%f0%9f%98%80.php', 179 'page-' . self::$page_on_front->ID . '.php', 180 'page.php', 181 'singular.php', 182 ) ); 219 $this->assertTemplateHierarchy( 220 home_url(), array( 221 'front-page.php', 222 'page-page-on-front-😀.php', 223 'page-page-on-front-%f0%9f%98%80.php', 224 'page-' . self::$page_on_front->ID . '.php', 225 'page.php', 226 'singular.php', 227 ) 228 ); 183 229 } 184 230 … … 188 234 update_option( 'page_for_posts', self::$page_for_posts->ID ); 189 235 190 $this->assertTemplateHierarchy( get_permalink( self::$page_for_posts ), array( 191 'home.php', 192 'index.php', 193 ) ); 236 $this->assertTemplateHierarchy( 237 get_permalink( self::$page_for_posts ), array( 238 'home.php', 239 'index.php', 240 ) 241 ); 194 242 } 195 243 196 244 public function test_page_template_hierarchy() { 197 $this->assertTemplateHierarchy( get_permalink( self::$page ), array( 198 'templates/page.php', 199 'page-page-name-😀.php', 200 'page-page-name-%f0%9f%98%80.php', 201 'page-' . self::$page->ID . '.php', 202 'page.php', 203 'singular.php', 204 ) ); 245 $this->assertTemplateHierarchy( 246 get_permalink( self::$page ), array( 247 'templates/page.php', 248 'page-page-name-😀.php', 249 'page-page-name-%f0%9f%98%80.php', 250 'page-' . self::$page->ID . '.php', 251 'page.php', 252 'singular.php', 253 ) 254 ); 205 255 } 206 256 … … 209 259 */ 210 260 public function test_single_template_hierarchy_for_post() { 211 $this->assertTemplateHierarchy( get_permalink( self::$post ), array( 212 'templates/post.php', 213 'single-post-post-name-😀.php', 214 'single-post-post-name-%f0%9f%98%80.php', 215 'single-post.php', 216 'single.php', 217 'singular.php', 218 ) ); 261 $this->assertTemplateHierarchy( 262 get_permalink( self::$post ), array( 263 'templates/post.php', 264 'single-post-post-name-😀.php', 265 'single-post-post-name-%f0%9f%98%80.php', 266 'single-post.php', 267 'single.php', 268 'singular.php', 269 ) 270 ); 219 271 } 220 272 221 273 public function test_single_template_hierarchy_for_custom_post_type() { 222 $cpt = self::factory()->post->create_and_get( array( 223 'post_type' => 'cpt', 224 'post_name' => 'cpt-name-😀', 225 ) ); 226 227 $this->assertTemplateHierarchy( get_permalink( $cpt ), array( 228 'single-cpt-cpt-name-😀.php', 229 'single-cpt-cpt-name-%f0%9f%98%80.php', 230 'single-cpt.php', 231 'single.php', 232 'singular.php', 233 ) ); 274 $cpt = self::factory()->post->create_and_get( 275 array( 276 'post_type' => 'cpt', 277 'post_name' => 'cpt-name-😀', 278 ) 279 ); 280 281 $this->assertTemplateHierarchy( 282 get_permalink( $cpt ), array( 283 'single-cpt-cpt-name-😀.php', 284 'single-cpt-cpt-name-%f0%9f%98%80.php', 285 'single-cpt.php', 286 'single.php', 287 'singular.php', 288 ) 289 ); 234 290 } 235 291 … … 238 294 */ 239 295 public function test_single_template_hierarchy_for_custom_post_type_with_template() { 240 $cpt = self::factory()->post->create_and_get( array( 241 'post_type' => 'cpt', 242 'post_name' => 'cpt-name-😀', 243 ) ); 296 $cpt = self::factory()->post->create_and_get( 297 array( 298 'post_type' => 'cpt', 299 'post_name' => 'cpt-name-😀', 300 ) 301 ); 244 302 add_post_meta( $cpt->ID, '_wp_page_template', 'templates/cpt.php' ); 245 303 246 $this->assertTemplateHierarchy( get_permalink( $cpt ), array( 247 'templates/cpt.php', 248 'single-cpt-cpt-name-😀.php', 249 'single-cpt-cpt-name-%f0%9f%98%80.php', 250 'single-cpt.php', 251 'single.php', 252 'singular.php', 253 ) ); 304 $this->assertTemplateHierarchy( 305 get_permalink( $cpt ), array( 306 'templates/cpt.php', 307 'single-cpt-cpt-name-😀.php', 308 'single-cpt-cpt-name-%f0%9f%98%80.php', 309 'single-cpt.php', 310 'single.php', 311 'singular.php', 312 ) 313 ); 254 314 } 255 315 256 316 public function test_attachment_template_hierarchy() { 257 $attachment = self::factory()->attachment->create_and_get( array( 258 'post_name' => 'attachment-name-😀', 259 'file' => 'image.jpg', 260 'post_mime_type' => 'image/jpeg', 261 ) ); 262 $this->assertTemplateHierarchy( get_permalink( $attachment ), array( 263 'image-jpeg.php', 264 'jpeg.php', 265 'image.php', 266 'attachment.php', 267 'single-attachment-attachment-name-😀.php', 268 'single-attachment-attachment-name-%f0%9f%98%80.php', 269 'single-attachment.php', 270 'single.php', 271 'singular.php', 272 ) ); 317 $attachment = self::factory()->attachment->create_and_get( 318 array( 319 'post_name' => 'attachment-name-😀', 320 'file' => 'image.jpg', 321 'post_mime_type' => 'image/jpeg', 322 ) 323 ); 324 $this->assertTemplateHierarchy( 325 get_permalink( $attachment ), array( 326 'image-jpeg.php', 327 'jpeg.php', 328 'image.php', 329 'attachment.php', 330 'single-attachment-attachment-name-😀.php', 331 'single-attachment-attachment-name-%f0%9f%98%80.php', 332 'single-attachment.php', 333 'single.php', 334 'singular.php', 335 ) 336 ); 273 337 } 274 338 … … 277 341 */ 278 342 public function test_attachment_template_hierarchy_with_template() { 279 $attachment = self::factory()->attachment->create_and_get( array( 280 'post_name' => 'attachment-name-😀', 281 'file' => 'image.jpg', 282 'post_mime_type' => 'image/jpeg', 283 ) ); 343 $attachment = self::factory()->attachment->create_and_get( 344 array( 345 'post_name' => 'attachment-name-😀', 346 'file' => 'image.jpg', 347 'post_mime_type' => 'image/jpeg', 348 ) 349 ); 284 350 285 351 add_post_meta( $attachment, '_wp_page_template', 'templates/cpt.php' ); 286 352 287 $this->assertTemplateHierarchy( get_permalink( $attachment ), array( 288 'image-jpeg.php', 289 'jpeg.php', 290 'image.php', 291 'attachment.php', 292 'single-attachment-attachment-name-😀.php', 293 'single-attachment-attachment-name-%f0%9f%98%80.php', 294 'single-attachment.php', 295 'single.php', 296 'singular.php', 297 ) ); 353 $this->assertTemplateHierarchy( 354 get_permalink( $attachment ), array( 355 'image-jpeg.php', 356 'jpeg.php', 357 'image.php', 358 'attachment.php', 359 'single-attachment-attachment-name-😀.php', 360 'single-attachment-attachment-name-%f0%9f%98%80.php', 361 'single-attachment.php', 362 'single.php', 363 'singular.php', 364 ) 365 ); 298 366 } 299 367 300 368 public function test_embed_template_hierarchy_for_post() { 301 $this->assertTemplateHierarchy( get_post_embed_url( self::$post ), array( 302 'embed-post-quote.php', 303 'embed-post.php', 304 'embed.php', 305 'templates/post.php', 306 'single-post-post-name-😀.php', 307 'single-post-post-name-%f0%9f%98%80.php', 308 'single-post.php', 309 'single.php', 310 'singular.php', 311 ) ); 369 $this->assertTemplateHierarchy( 370 get_post_embed_url( self::$post ), array( 371 'embed-post-quote.php', 372 'embed-post.php', 373 'embed.php', 374 'templates/post.php', 375 'single-post-post-name-😀.php', 376 'single-post-post-name-%f0%9f%98%80.php', 377 'single-post.php', 378 'single.php', 379 'singular.php', 380 ) 381 ); 312 382 } 313 383 314 384 public function test_embed_template_hierarchy_for_page() { 315 $this->assertTemplateHierarchy( get_post_embed_url( self::$page ), array( 316 'embed-page.php', 317 'embed.php', 318 'templates/page.php', 319 'page-page-name-😀.php', 320 'page-page-name-%f0%9f%98%80.php', 321 'page-' . self::$page->ID . '.php', 322 'page.php', 323 'singular.php', 324 ) ); 385 $this->assertTemplateHierarchy( 386 get_post_embed_url( self::$page ), array( 387 'embed-page.php', 388 'embed.php', 389 'templates/page.php', 390 'page-page-name-😀.php', 391 'page-page-name-%f0%9f%98%80.php', 392 'page-' . self::$page->ID . '.php', 393 'page.php', 394 'singular.php', 395 ) 396 ); 325 397 } 326 398 … … 364 436 remove_filter( "{$filter}_template_hierarchy", array( $this, 'log_template_hierarchy' ) ); 365 437 } 366 367 438 } 368 $hierarchy = $this->hierarchy;439 $hierarchy = $this->hierarchy; 369 440 $this->hierarchy = array(); 370 441 return $hierarchy;
Note: See TracChangeset
for help on using the changeset viewer.