diff --git a/tests/phpunit/tests/post/types.php b/tests/phpunit/tests/post/types.php index 9cf44c84fb..f216ec5680 100644 --- a/tests/phpunit/tests/post/types.php +++ b/tests/phpunit/tests/post/types.php @@ -4,6 +4,26 @@ * @group post */ class Tests_Post_Types extends WP_UnitTestCase { + + /** + * Post type. + * + * @since 4.5.0 + * @var string + */ + public $post_type; + + /** + * Set up. + * + * @since 4.5.0 + */ + function setUp() { + parent::setUp(); + + $this->post_type = rand_str( 20 ); + } + function test_register_post_type() { $this->assertNull( get_post_type_object( 'foo' ) ); register_post_type( 'foo' ); @@ -39,6 +59,103 @@ class Tests_Post_Types extends WP_UnitTestCase { $this->assertInstanceOf( 'WP_Error', register_post_type( '' ) ); } + /** + * @ticket 35985 + * @covers register_post_type() + */ + function test_register_post_type_exclude_from_search_should_default_to_opposite_value_of_public() { + /* + * 'public' Default is false + * 'exclude_from_search' Default is null (opposite 'public') + */ + $args = $this->register_post_type( array( 'public' => $public = false ) ); + + $this->assertNotEquals( $public, $args->exclude_from_search ); + } + + /** + * @ticket 35985 + * @covers register_post_type() + */ + function test_register_post_type_publicly_queryable_should_default_to_value_of_public() { + /* + * 'public' Default is false + * 'publicly_queryable' Default is null ('public') + */ + $args = $this->register_post_type( array( 'public' => $public = false ) ); + + $this->assertSame( $public, $args->publicly_queryable ); + } + + /** + * @ticket 35985 + * @covers register_post_type() + */ + function test_register_post_type_show_ui_should_default_to_value_of_public() { + /* + * 'public' Default is false + * 'show_ui' Default is null ('public') + */ + $args = $this->register_post_type( array( 'public' => $public = false ) ); + + $this->assertSame( $public, $args->show_ui ); + } + + /** + * @ticket 35985 + * @covers register_post_type() + */ + function test_register_post_type_show_in_menu_should_default_to_value_of_show_ui() { + /* + * 'public' Default is false + * 'show_ui' Default is null ('public') + * 'show_in_menu Default is null ('show_ui' > 'public') + */ + $args = $this->register_post_type( array( 'public' => $public = false ) ); + + // Should fall back to 'show_ui'. + $this->assertSame( $args->show_ui, $args->show_in_menu ); + + // Should fall back to 'show_ui', then 'public'. + $this->assertSame( $public, $args->show_in_menu ); + } + + /** + * @ticket 35985 + * @covers register_post_type() + */ + function test_register_post_type_show_in_nav_menus_should_default_to_value_of_public() { + /* + * 'public' Default is false + * 'show_in_nav_menus' Default is null ('public') + */ + $args = $this->register_post_type( array( 'public' => $public = false ) ); + + $this->assertSame( $public, $args->show_in_nav_menus ); + } + + /** + * @ticket 35985 + * @covers register_post_type() + */ + function test_register_post_type_show_in_admin_bar_should_default_to_value_of_show_in_menu() { + /* + * 'public' Default is false + * 'show_in_menu' Default is null ('show_ui' > 'public') + * 'show_in_admin_bar' Default is null ('show_in_menu' > 'show_ui' > 'public') + */ + $args = $this->register_post_type( array( 'public' => $public = false ) ); + + // Should fall back to 'show_in_menu'. + $this->assertSame( $args->show_in_menu, $args->show_in_admin_bar ); + + // Should fall back to 'show_ui'. + $this->assertSame( $args->show_ui, $args->show_in_admin_bar ); + + // Should fall back to 'public'. + $this->assertSame( $public, $args->show_in_admin_bar ); + } + function test_register_taxonomy_for_object_type() { global $wp_taxonomies; @@ -428,4 +545,19 @@ class Tests_Post_Types extends WP_UnitTestCase { public function test_get_post_types_by_support_non_existant_feature() { $this->assertEqualSets( array(), get_post_types_by_support( 'somefeature' ) ); } + + /** + * Serves as a helper to register a post type for tests. + * + * Uses `$this->post_type` initialized in setUp(). + * + * @since 4.5.0 + * + * @param array $args register_post_type() arguments. + * @return stdClass Post type object for `$this->post_type`. + */ + public function register_post_type( $args = array() ) { + register_post_type( $this->post_type, $args ); + return get_post_type_object( $this->post_type ); + } }