Opened 5 years ago
Closed 5 years ago
#49801 closed defect (bug) (fixed)
Remove incorrect test_post_thumbnails_types_true() test
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.5 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Themes | Keywords: | |
Focuses: | Cc: |
Description
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.
In 47548: