WordPress.org

Make WordPress Core

Opened 4 months ago

Closed 4 months ago

#49801 closed defect (bug) (fixed)

Remove incorrect test_post_thumbnails_types_true() test

Reported by: SergeyBiryukov Owned by: SergeyBiryukov
Milestone: 5.5 Priority: normal
Severity: normal Version:
Component: Themes Keywords:
Focuses: Cc:

Description

Some history on add_theme_support( 'post-thumbnails' ):

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.

Change History (1)

#1 @SergeyBiryukov
4 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 47548:

Tests: Remove test_post_thumbnails_types_true().

The test incorrectly describes the behavior of current_theme_supports( 'post-thumbnails' ) and only passes by accident.

Follow-up to [30148].

Fixes #49801.

Note: See TracTickets for help on using tickets.