Changeset 41267 for trunk/tests/phpunit/tests/post/thumbnails.php
- Timestamp:
- 08/18/2017 06:18:51 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/thumbnails.php
r39919 r41267 7 7 class Tests_Post_Thumbnail_Template extends WP_UnitTestCase { 8 8 protected static $post; 9 protected static $different_post; 9 10 protected static $attachment_id; 10 11 12 protected $current_size_filter_data = null; 13 protected $current_size_filter_result = null; 14 11 15 public static function wpSetUpBeforeClass( $factory ) { 12 self::$post = $factory->post->create_and_get(); 16 self::$post = $factory->post->create_and_get(); 17 self::$different_post = $factory->post->create_and_get(); 18 13 19 $file = DIR_TESTDATA . '/images/canola.jpg'; 14 20 self::$attachment_id = $factory->attachment->create_upload_object( $file, self::$post->ID, array( … … 336 342 $this->assertEmpty( $thumbnail_id ); 337 343 } 344 345 /** 346 * @ticket 39030 347 */ 348 function test_post_thumbnail_size_filter_simple() { 349 $this->current_size_filter_data = 'medium'; 350 351 add_filter( 'post_thumbnail_size', array( $this, 'filter_post_thumbnail_size' ), 10, 2 ); 352 353 // This filter is used to capture the $size result. 354 add_filter( 'post_thumbnail_html', array( $this, 'filter_set_post_thumbnail_size_result' ), 10, 4 ); 355 get_the_post_thumbnail( self::$post ); 356 357 $result = $this->current_size_filter_result; 358 359 $this->current_size_filter_data = null; 360 $this->current_size_filter_result = null; 361 362 $this->assertSame( 'medium', $result ); 363 } 364 365 /** 366 * @ticket 39030 367 * @dataProvider data_post_thumbnail_size_filter_complex 368 */ 369 function test_post_thumbnail_size_filter_complex( $which_post, $expected ) { 370 $this->current_size_filter_data = array( 371 self::$post->ID => 'medium', 372 self::$different_post->ID => 'thumbnail', 373 ); 374 375 $post = $which_post === 1 ? self::$different_post : self::$post; 376 377 add_filter( 'post_thumbnail_size', array( $this, 'filter_post_thumbnail_size' ), 10, 2 ); 378 379 // This filter is used to capture the $size result. 380 add_filter( 'post_thumbnail_html', array( $this, 'filter_set_post_thumbnail_size_result' ), 10, 4 ); 381 get_the_post_thumbnail( $post ); 382 383 $result = $this->current_size_filter_result; 384 385 $this->current_size_filter_data = null; 386 $this->current_size_filter_result = null; 387 388 $this->assertSame( $expected, $result ); 389 } 390 391 function data_post_thumbnail_size_filter_complex() { 392 return array( 393 array( 0, 'medium' ), 394 array( 1, 'thumbnail' ), 395 ); 396 } 397 398 function filter_post_thumbnail_size( $size, $post_id ) { 399 if ( is_array( $this->current_size_filter_data ) && isset( $this->current_size_filter_data[ $post_id ] ) ) { 400 return $this->current_size_filter_data[ $post_id ]; 401 } 402 403 if ( is_string( $this->current_size_filter_data ) ) { 404 return $this->current_size_filter_data; 405 } 406 407 return $size; 408 } 409 410 function filter_set_post_thumbnail_size_result( $html, $post_id, $post_thumbnail_id, $size ) { 411 $this->current_size_filter_result = $size; 412 413 return $html; 414 } 338 415 }
Note: See TracChangeset
for help on using the changeset viewer.