Changeset 36768
- Timestamp:
- 02/28/2016 10:58:45 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/types.php
r36652 r36768 5 5 */ 6 6 class 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 * Set up. 18 * 19 * @since 4.5.0 20 */ 21 function setUp() { 22 parent::setUp(); 23 24 $this->post_type = rand_str( 20 ); 25 } 26 7 27 function test_register_post_type() { 8 28 $this->assertNull( get_post_type_object( 'foo' ) ); … … 38 58 // post type too short 39 59 $this->assertInstanceOf( 'WP_Error', register_post_type( '' ) ); 60 } 61 62 /** 63 * @ticket 35985 64 * @covers register_post_type() 65 */ 66 function test_register_post_type_exclude_from_search_should_default_to_opposite_value_of_public() { 67 /* 68 * 'public' Default is false 69 * 'exclude_from_search' Default is null (opposite 'public') 70 */ 71 $args = $this->register_post_type( array( 'public' => $public = false ) ); 72 73 $this->assertNotEquals( $public, $args->exclude_from_search ); 74 } 75 76 /** 77 * @ticket 35985 78 * @covers register_post_type() 79 */ 80 function test_register_post_type_publicly_queryable_should_default_to_value_of_public() { 81 /* 82 * 'public' Default is false 83 * 'publicly_queryable' Default is null ('public') 84 */ 85 $args = $this->register_post_type( array( 'public' => $public = false ) ); 86 87 $this->assertSame( $public, $args->publicly_queryable ); 88 } 89 90 /** 91 * @ticket 35985 92 * @covers register_post_type() 93 */ 94 function test_register_post_type_show_ui_should_default_to_value_of_public() { 95 /* 96 * 'public' Default is false 97 * 'show_ui' Default is null ('public') 98 */ 99 $args = $this->register_post_type( array( 'public' => $public = false ) ); 100 101 $this->assertSame( $public, $args->show_ui ); 102 } 103 104 /** 105 * @ticket 35985 106 * @covers register_post_type() 107 */ 108 function test_register_post_type_show_in_menu_should_default_to_value_of_show_ui() { 109 /* 110 * 'public' Default is false 111 * 'show_ui' Default is null ('public') 112 * 'show_in_menu Default is null ('show_ui' > 'public') 113 */ 114 $args = $this->register_post_type( array( 'public' => $public = false ) ); 115 116 // Should fall back to 'show_ui'. 117 $this->assertSame( $args->show_ui, $args->show_in_menu ); 118 119 // Should fall back to 'show_ui', then 'public'. 120 $this->assertSame( $public, $args->show_in_menu ); 121 } 122 123 /** 124 * @ticket 35985 125 * @covers register_post_type() 126 */ 127 function test_register_post_type_show_in_nav_menus_should_default_to_value_of_public() { 128 /* 129 * 'public' Default is false 130 * 'show_in_nav_menus' Default is null ('public') 131 */ 132 $args = $this->register_post_type( array( 'public' => $public = false ) ); 133 134 $this->assertSame( $public, $args->show_in_nav_menus ); 135 } 136 137 /** 138 * @ticket 35985 139 * @covers register_post_type() 140 */ 141 function test_register_post_type_show_in_admin_bar_should_default_to_value_of_show_in_menu() { 142 /* 143 * 'public' Default is false 144 * 'show_in_menu' Default is null ('show_ui' > 'public') 145 * 'show_in_admin_bar' Default is null ('show_in_menu' > 'show_ui' > 'public') 146 */ 147 $args = $this->register_post_type( array( 'public' => $public = false ) ); 148 149 // Should fall back to 'show_in_menu'. 150 $this->assertSame( $args->show_in_menu, $args->show_in_admin_bar ); 151 152 // Should fall back to 'show_ui'. 153 $this->assertSame( $args->show_ui, $args->show_in_admin_bar ); 154 155 // Should fall back to 'public'. 156 $this->assertSame( $public, $args->show_in_admin_bar ); 40 157 } 41 158 … … 429 546 $this->assertEqualSets( array(), get_post_types_by_support( 'somefeature' ) ); 430 547 } 548 549 /** 550 * Serves as a helper to register a post type for tests. 551 * 552 * Uses `$this->post_type` initialized in setUp(). 553 * 554 * @since 4.5.0 555 * 556 * @param array $args register_post_type() arguments. 557 * @return stdClass Post type object for `$this->post_type`. 558 */ 559 public function register_post_type( $args = array() ) { 560 register_post_type( $this->post_type, $args ); 561 return get_post_type_object( $this->post_type ); 562 } 431 563 }
Note: See TracChangeset
for help on using the changeset viewer.