Make WordPress Core

Ticket #34010: 34010.2.diff

File 34010.2.diff, 1.9 KB (added by swissspidy, 8 years ago)
  • src/wp-includes/post.php

    diff --git src/wp-includes/post.php src/wp-includes/post.php
    index 59506f8..2ff3133 100644
    function post_type_supports( $post_type, $feature ) { 
    15521552}
    15531553
    15541554/**
     1555 * Get a list of post type names that support a specific feature.
     1556 *
     1557 * @since 4.5.0
     1558 *
     1559 * @param array|string $args Single feature or an array of features the post types should support.
     1560 * @return array A list of post type names.
     1561 */
     1562function get_post_types_by_support( $args ) {
     1563        global $_wp_post_type_features;
     1564
     1565        $features = array_fill_keys( (array) $args, true );
     1566
     1567        return array_keys( wp_filter_object_list( $_wp_post_type_features, $features ) );
     1568}
     1569
     1570/**
    15551571 * Update the post type for the post ID.
    15561572 *
    15571573 * The page or post cache will be cleaned for the post ID.
  • tests/phpunit/tests/post/types.php

    diff --git tests/phpunit/tests/post/types.php tests/phpunit/tests/post/types.php
    index 02d4590..d8154d6 100644
    class Tests_Post_Types extends WP_UnitTestCase { 
    159159
    160160                _unregister_post_type( 'foo' );
    161161        }
     162
     163        /**
     164         * @ticket 34010
     165         */
     166        public function test_get_post_types_by_support_single_feature() {
     167                $this->assertSame( array(
     168                        'post',
     169                        'page',
     170                        'attachment',
     171                        'nav_menu_item',
     172                ), get_post_types_by_support( 'title' ) );
     173        }
     174
     175        /**
     176         * @ticket 34010
     177         */
     178        public function test_get_post_types_by_support_multiple_features() {
     179                $this->assertSame( array( 'post', 'page' ), get_post_types_by_support( array( 'thumbnail', 'author' ) ) );
     180        }
     181
     182        /**
     183         * @ticket 34010
     184         */
     185        public function test_get_post_types_by_support_excluding_features() {
     186                $this->assertSame( array(), get_post_types_by_support( array( 'post-formats', 'page-attributes' ) ) );
     187        }
     188
     189        /**
     190         * @ticket 34010
     191         */
     192        public function test_get_post_types_by_support_non_existant_feature() {
     193                $this->assertSame( array(), get_post_types_by_support( 'somefeature' ) );
     194        }
    162195}