WordPress.org

Make WordPress Core

Ticket #36666: 36666.5.diff

File 36666.5.diff, 3.6 KB (added by flixos90, 4 years ago)

added unit tests

  • src/wp-includes/theme.php

     
    18311831 *
    18321832 * @since 3.0.0
    18331833 * @see add_theme_support()
    1834  * @param string $feature the feature being added
    1835  * @return bool|void Whether feature was removed.
     1834 * @param string $feature The feature being added.
     1835 * @param array $args Array of specific arguments to remove. Optional.
     1836 * @return bool|void Whether the feature was removed.
    18361837 */
    1837 function remove_theme_support( $feature ) {
     1838function remove_theme_support( $feature, $args = array() ) {
    18381839        // Blacklist: for internal registrations not used directly by themes.
    18391840        if ( in_array( $feature, array( 'editor-style', 'widgets', 'menus' ) ) )
    18401841                return false;
    18411842
    1842         return _remove_theme_support( $feature );
     1843        return _remove_theme_support( $feature, $args );
    18431844}
    18441845
    18451846/**
     
    18521853 * @global Custom_Image_Header $custom_image_header
    18531854 * @global Custom_Background   $custom_background
    18541855 *
    1855  * @param string $feature
     1856 * @param string $feature The feature being added.
     1857 * @param array $args Array of specific arguments to remove. Optional.
     1858 * @return bool|void Whether the feature was removed.
    18561859 */
    1857 function _remove_theme_support( $feature ) {
     1860function _remove_theme_support( $feature, $args = array() ) {
    18581861        global $_wp_theme_features;
    18591862
    18601863        switch ( $feature ) {
     
    18871890                        remove_action( 'admin_menu', array( $GLOBALS['custom_background'], 'init' ) );
    18881891                        unset( $GLOBALS['custom_background'] );
    18891892                        break;
     1893
     1894                case 'post-formats':
     1895                case 'post-thumbnails':
     1896                        if ( $args && is_bool( $_wp_theme_features[ $feature ] ) )
     1897                                return false;
     1898
     1899                // This also applies to 'post-formats' and 'post-thumbnails' if they haven't returned yet.
     1900                case 'html5' :
     1901                        if ( $args ) {
     1902                                $_wp_theme_features[ $feature ][0] = array_diff( $_wp_theme_features[ $feature ][0], $args );
     1903
     1904                                // Return only if there is still something in the feature array.
     1905                                if ( ! empty( $_wp_theme_features[ $feature ][0] ) )
     1906                                        return true;
     1907                        }
     1908                        break;
    18901909        }
    18911910
    18921911        unset( $_wp_theme_features[ $feature ] );
  • tests/phpunit/tests/theme/support.php

     
    9898                $this->assertFalse( current_theme_supports( 'html5', 'something-else' ) );
    9999        }
    100100
     101        function test_custom_header_uploads() {
     102                add_theme_support( 'custom-header' );
     103                $this->assertTrue( current_theme_supports( 'custom-header', 'uploads' ) );
     104                $this->assertNull( remove_theme_support( 'custom-header-uploads' ) );
     105                $this->assertFalse( current_theme_supports( 'custom-header', 'uploads' ) );
     106        }
     107
    101108        /**
     109         * @ticket 36666
     110         */
     111        function test_remove_subsets() {
     112                add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );
     113                $this->assertTrue( remove_theme_support( 'post-thumbnails', array( 'page' ) ) );
     114                $this->assertTrue( current_theme_supports( 'post-thumbnails', 'post' ) );
     115                $this->assertFalse( current_theme_supports( 'post-thumbnails', 'page' ) );
     116
     117                // The following code is supposed to fail since it is not possible to remove
     118                // a subset of theme support when it is set to true.
     119                add_theme_support( 'post-thumbnails' );
     120                $this->assertFalse( remove_theme_support( 'post-thumbnails', array( 'page' ) ) );
     121                $this->assertTrue( current_theme_supports( 'post-thumbnails', 'page' ) );
     122        }
     123
     124        /**
    102125         * @ticket 24932
    103126         *
    104127         * @expectedIncorrectUsage add_theme_support( 'html5' )