WordPress.org

Make WordPress Core

Ticket #34010: 34010.3.diff

File 34010.3.diff, 2.8 KB (added by swissspidy, 5 years ago)
  • src/wp-includes/post.php

    diff --git src/wp-includes/post.php src/wp-includes/post.php
    index 6360735..a984e6a 100644
    function post_type_supports( $post_type, $feature ) { 
    16391639}
    16401640
    16411641/**
     1642 * Get a list of post type names that support a specific feature.
     1643 *
     1644 * @since 4.5.0
     1645 *
     1646 * @global array $_wp_post_type_features
     1647 *
     1648 * @param array|string $args     Single feature or an array of features the post types should support.
     1649 * @param string       $operator Optional. The logical operation to perform. 'or' means
     1650 *                               only one element from the array needs to match; 'and'
     1651 *                               means all elements must match; 'not' means no elements may
     1652 *                               match. Default 'and'.
     1653 * @return array A list of post type names.
     1654 */
     1655function get_post_types_by_support( $args, $operator = 'and' ) {
     1656        global $_wp_post_type_features;
     1657
     1658        $features = array_fill_keys( (array) $args, true );
     1659
     1660        return array_keys( wp_filter_object_list( $_wp_post_type_features, $features, $operator ) );
     1661}
     1662
     1663/**
    16421664 * Update the post type for the post ID.
    16431665 *
    16441666 * 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 9d19a84..7343ccd 100644
    class Tests_Post_Types extends WP_UnitTestCase { 
    379379
    380380                $this->assertFalse( post_type_exists( 'foo' ) );
    381381        }
     382
     383        /**
     384         * @ticket 34010
     385         */
     386        public function test_get_post_types_by_support_single_feature() {
     387                $this->assertEqualSets( array(
     388                        'post',
     389                        'page',
     390                        'attachment',
     391                        'nav_menu_item',
     392                ), get_post_types_by_support( 'title' ) );
     393        }
     394
     395        /**
     396         * @ticket 34010
     397         */
     398        public function test_get_post_types_by_support_multiple_features() {
     399                $this->assertEqualSets( array( 'post', 'page' ), get_post_types_by_support( array( 'thumbnail', 'author' ) ) );
     400        }
     401
     402        /**
     403         * @ticket 34010
     404         */
     405        public function test_get_post_types_by_support_or_operator() {
     406                $this->assertEqualSets( array( 'post', 'page' ), get_post_types_by_support( array( 'post-formats', 'page-attributes' ), 'or' ) );
     407        }
     408
     409        /**
     410         * @ticket 34010
     411         */
     412        public function test_get_post_types_by_support_not_operator() {
     413                $this->assertEqualSets( array( 'attachment', 'revision', 'nav_menu_item' ), get_post_types_by_support( array( 'thumbnail' ), 'not' ) );
     414        }
     415
     416        /**
     417         * @ticket 34010
     418         */
     419        public function test_get_post_types_by_support_excluding_features() {
     420                $this->assertEqualSets( array(), get_post_types_by_support( array( 'post-formats', 'page-attributes' ) ) );
     421        }
     422
     423        /**
     424         * @ticket 34010
     425         */
     426        public function test_get_post_types_by_support_non_existant_feature() {
     427                $this->assertEqualSets( array(), get_post_types_by_support( 'somefeature' ) );
     428        }
    382429}