Make WordPress Core


Ignore:
Timestamp:
02/23/2016 10:49:17 PM (10 years ago)
Author:
swissspidy
Message:

Posts: Introduce get_post_types_by_support().

Similar to get_post_types(), this new function returns a list of post type names that support a specific feature.

Props wpsmith, barryceelen, swissspidy.
Fixes #34010.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/types.php

    r36316 r36652  
    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}
Note: See TracChangeset for help on using the changeset viewer.