Make WordPress Core

Ticket #35985: 35985.diff

File 35985.diff, 4.4 KB (added by DrewAPicture, 11 years ago)
  • tests/phpunit/tests/post/types.php

     
    44 * @group post
    55 */
    66class Tests_Post_Types extends WP_UnitTestCase {
     7
     8        /**
     9         * Post type.
     10         *
     11         * @since 4.5.0
     12         * @var string
     13         */
     14        public $post_type;
     15
     16        /**
     17         * Post type arguments.
     18         *
     19         * @since 4.5.0
     20         * @var stdClass
     21         */
     22        public $post_type_args;
     23
     24        /**
     25         * Set up.
     26         *
     27         * @since 4.5.0
     28         */
     29        function setUp() {
     30                parent::setUp();
     31
     32                $this->post_type = rand_str( 20 );
     33        }
     34
    735        function test_register_post_type() {
    836                $this->assertNull( get_post_type_object( 'foo' ) );
    937                register_post_type( 'foo' );
    … …  
    3967                $this->assertInstanceOf( 'WP_Error', register_post_type( '' ) );
    4068        }
    4169
     70        /**
     71         * @ticket 35985
     72         * @covers register_post_type()
     73         */
     74        function test_register_post_type_exclude_from_search_should_default_to_opposite_value_of_public() {
     75                /*
     76                 * 'public' default is false
     77                 * 'exclude_from_search' default is null (opposite 'public')
     78                 */
     79                $this->register_post_type();
     80
     81                $this->assertNotEquals( $this->post_type_args->public, $this->post_type_args->exclude_from_search );
     82        }
     83
     84        /**
     85         * @ticket 35985
     86         * @covers register_post_type()
     87         */
     88        function test_register_post_type_publicly_queryable_should_default_to_value_of_public() {
     89                /*
     90                 * 'public' default is false
     91                 * 'publicly_queryable' default is null ('public')
     92                 */
     93                $this->register_post_type();
     94
     95                $this->assertEquals( $this->post_type_args->public, $this->post_type_args->publicly_queryable );
     96        }
     97
     98        /**
     99         * @ticket 35985
     100         * @covers register_post_type()
     101         */
     102        function test_register_post_type_show_ui_should_default_to_value_of_public() {
     103                /*
     104                 * 'public' default is false
     105                 * 'show_ui' default is null ('public')
     106                 */
     107                $this->register_post_type();
     108
     109                $this->assertEquals( $this->post_type_args->public, $this->post_type_args->show_ui );
     110        }
     111
     112        /**
     113         * @ticket 35985
     114         * @covers register_post_type()
     115         */
     116        function test_register_post_type_show_in_menu_should_default_to_value_of_show_ui() {
     117                /*
     118                 * 'public' default is false
     119                 * 'show_ui' default is null ('public')
     120                 * 'show_in_menu default' is null ('show_ui' > 'public')
     121                 */
     122                $this->register_post_type();
     123
     124                // Should fall back to 'show_ui'.
     125                $this->assertEquals( $this->post_type_args->show_ui, $this->post_type_args->show_in_menu );
     126
     127                // Should fall back to 'show_ui', then 'public'.
     128                $this->assertEquals( $this->post_type_args->public, $this->post_type_args->show_in_menu );
     129        }
     130
     131        /**
     132         * @ticket 35985
     133         * @covers register_post_type()
     134         */
     135        function test_register_post_type_show_in_nav_menus_should_default_to_value_of_public() {
     136                /*
     137                 * 'public' default is false
     138                 * 'show_in_nav_menus' default is null ('public')
     139                 */
     140                $this->register_post_type();
     141
     142                $this->assertEquals( $this->post_type_args->public, $this->post_type_args->show_in_nav_menus );
     143        }
     144
     145        /**
     146         * @ticket 35985
     147         * @covers register_post_type()
     148         */
     149        function test_register_post_type_show_in_admin_bar_should_default_to_value_of_show_in_menu() {
     150                /*
     151                 * 'public' default is false
     152                 * 'show_in_menu' default is null ('show_ui' > 'public')
     153                 * 'show_in_admin_bar' default is null ('show_in_menu' > 'show_ui' > 'public')
     154                 */
     155                $this->register_post_type();
     156
     157                // Should fall back to 'show_in_menu'.
     158                $this->assertEquals( $this->post_type_args->show_in_menu, $this->post_type_args->show_in_admin_bar );
     159
     160                // Should fall back to 'show_ui'.
     161                $this->assertEquals( $this->post_type_args->show_ui, $this->post_type_args->show_in_admin_bar );
     162
     163                // Should fall back to 'public'.
     164                $this->assertEquals( $this->post_type_args->public, $this->post_type_args->show_in_admin_bar );
     165        }
     166
    42167        function test_register_taxonomy_for_object_type() {
    43168                global $wp_taxonomies;
    44169
    … …  
    428553        public function test_get_post_types_by_support_non_existant_feature() {
    429554                $this->assertEqualSets( array(), get_post_types_by_support( 'somefeature' ) );
    430555        }
     556
     557        /**
     558         * Serves as a helper to register a post type for tests.
     559         *
     560         * Uses `$this->post_type` initialized in setUp().
     561         *
     562         * @since 4.5.0
     563         *
     564         * @param array $args register_post_type() arguments.
     565         */
     566        public function register_post_type( $args = array() ) {
     567                register_post_type( $this->post_type, $args );
     568
     569                $this->post_type_args = get_post_type_object( $this->post_type );
     570        }
    431571}