WordPress.org

Make WordPress Core

Ticket #34010: 34010.4.diff

File 34010.4.diff, 3.3 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 70a7d73..efb7330 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..9cf44c8 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->assertContains( 'post', get_post_types_by_support( 'title' ) );
     388                $this->assertContains( 'page', get_post_types_by_support( 'title' ) );
     389                $this->assertContains( 'attachment', get_post_types_by_support( 'title' ) );
     390                $this->assertContains( 'nav_menu_item', get_post_types_by_support( 'title' ) );
     391        }
     392
     393        /**
     394         * @ticket 34010
     395         */
     396        public function test_get_post_types_by_support_multiple_features() {
     397                $this->assertContains( 'post', get_post_types_by_support( array( 'thumbnail', 'author' ) ) );
     398                $this->assertContains( 'page', get_post_types_by_support( array( 'thumbnail', 'author' ) ) );
     399        }
     400
     401        /**
     402         * @ticket 34010
     403         */
     404        public function test_get_post_types_by_support_or_operator() {
     405                $this->assertContains( 'post', get_post_types_by_support( array( 'post-formats', 'page-attributes' ), 'or' ) );
     406                $this->assertContains( '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->assertContains( 'attachment', get_post_types_by_support( array( 'thumbnail' ), 'not' ) );
     414                $this->assertContains( 'revision', get_post_types_by_support( array( 'thumbnail' ), 'not' ) );
     415                $this->assertContains( 'nav_menu_item', get_post_types_by_support( array( 'thumbnail' ), 'not' ) );
     416        }
     417
     418        /**
     419         * @ticket 34010
     420         */
     421        public function test_get_post_types_by_support_excluding_features() {
     422                $this->assertEqualSets( array(), get_post_types_by_support( array( 'post-formats', 'page-attributes' ) ) );
     423        }
     424
     425        /**
     426         * @ticket 34010
     427         */
     428        public function test_get_post_types_by_support_non_existant_feature() {
     429                $this->assertEqualSets( array(), get_post_types_by_support( 'somefeature' ) );
     430        }
    382431}