[wp-trac] [WordPress Trac] #49801: Remove incorrect test_post_thumbnails_types_true() test

WordPress Trac noreply at wordpress.org
Fri Apr 3 23:07:38 UTC 2020


#49801: Remove incorrect test_post_thumbnails_types_true() test
----------------------------+--------------------
 Reporter:  SergeyBiryukov  |      Owner:  (none)
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  5.5
Component:  Themes          |    Version:
 Severity:  normal          |   Keywords:
  Focuses:                  |
----------------------------+--------------------
 Some history on `add_theme_support( 'post-thumbnails' )`:
 * Introduced as `post-images` in [12350] / #11364.
 * Renamed to `post-thumbnails` in [12351].
 * Some unit tests added in [435/tests].
 * Some incorrect tests removed in [30148] / #18548.
 * Merging of supported post types added in [37308] / #22080.

 In hindsight, some tests added in [435/tests] were incorrect, as the
 `types` argument was never supported:
 {{{
 add_theme_support( 'post-thumbnails', array( 'types' => array( 'post',
 'page' ) ) );
 }}}
 This is the correct syntax instead:
 {{{
 add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );
 }}}

 Some tests were removed in [30148] / #18548.
 `test_post_thumbnails_types_true()` was left as is at the time, because it
 passed. The test ensures that adding `post-thumbnails` support for `array(
 'types' => true )` results in thumbnails being supported for any post
 type:
 {{{
 add_theme_support( 'post-thumbnails', array( 'types' => true ) );
 $this->assertTrue( current_theme_supports( 'post-thumbnails' ) );
 $this->assertTrue( current_theme_supports( 'post-thumbnails', rand_str() )
 );
 }}}
 However, that is an incorrect assumption. Thumbnail support for any type
 is only achieved by omitting the array altogether. This is already tested
 in `test_post_thumbnails_mixed_args()` a few lines above:
 {{{
 add_theme_support( 'post-thumbnails' );
 $this->assertTrue( current_theme_supports( 'post-thumbnails', 'book' ) );
 }}}
 and does not need an additional test.

 `test_post_thumbnails_types_true()` boils down to this check in
 `current_theme_supports()`:
 {{{
 in_array( rand_str(), array( 'types' => true ) )
 }}}
 It only passes by accident due to fact that this always returns true
 without a strict type check.

 Discovered while working on switching to strict `in_array()` checks across
 core in #49542.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49801>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list