Changeset 42343 for trunk/tests/phpunit/tests/query/postStatus.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/query/postStatus.php (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/query/postStatus.php
r38398 r42343 16 16 self::$author_user_id = $factory->user->create( array( 'role' => 'author' ) ); 17 17 18 self::$editor_private_post = $factory->post->create( array( 'post_author' => self::$editor_user_id, 'post_status' => 'private' ) ); 19 self::$author_private_post = $factory->post->create( array( 'post_author' => self::$author_user_id, 'post_status' => 'private' ) ); 18 self::$editor_private_post = $factory->post->create( 19 array( 20 'post_author' => self::$editor_user_id, 21 'post_status' => 'private', 22 ) 23 ); 24 self::$author_private_post = $factory->post->create( 25 array( 26 'post_author' => self::$author_user_id, 27 'post_status' => 'private', 28 ) 29 ); 20 30 21 31 // Custom status with private=true. 22 32 register_post_status( 'privatefoo', array( 'private' => true ) ); 23 self::$editor_privatefoo_post = $factory->post->create( array( 'post_author' => self::$editor_user_id, 'post_status' => 'privatefoo' ) ); 24 self::$author_privatefoo_post = $factory->post->create( array( 'post_author' => self::$author_user_id, 'post_status' => 'privatefoo' ) ); 33 self::$editor_privatefoo_post = $factory->post->create( 34 array( 35 'post_author' => self::$editor_user_id, 36 'post_status' => 'privatefoo', 37 ) 38 ); 39 self::$author_privatefoo_post = $factory->post->create( 40 array( 41 'post_author' => self::$author_user_id, 42 'post_status' => 'privatefoo', 43 ) 44 ); 25 45 _unregister_post_status( 'privatefoo' ); 26 46 } … … 29 49 register_post_status( 'foo', array( 'exclude_from_search' => true ) ); 30 50 31 $q = new WP_Query( array( 32 'post_status' => array( 'any' ), 33 ) ); 51 $q = new WP_Query( 52 array( 53 'post_status' => array( 'any' ), 54 ) 55 ); 34 56 35 57 $this->assertContains( "post_status <> 'foo'", $q->request ); … … 39 61 register_post_status( 'foo', array( 'exclude_from_search' => false ) ); 40 62 41 $q = new WP_Query( array( 42 'post_status' => array( 'any' ), 43 ) ); 63 $q = new WP_Query( 64 array( 65 'post_status' => array( 'any' ), 66 ) 67 ); 44 68 45 69 $this->assertNotContains( "post_status <> 'foo'", $q->request ); … … 47 71 48 72 public function test_private_should_be_included_if_perm_is_false() { 49 $q = new WP_Query( array( 50 'post_status' => array( 'private' ), 51 'perm' => false, 52 ) ); 73 $q = new WP_Query( 74 array( 75 'post_status' => array( 'private' ), 76 'perm' => false, 77 ) 78 ); 53 79 54 80 $expected = array( … … 63 89 // Current user is 0. 64 90 65 $q = new WP_Query( array( 66 'post_status' => array( 'private' ), 67 'perm' => 'editable', 68 ) ); 91 $q = new WP_Query( 92 array( 93 'post_status' => array( 'private' ), 94 'perm' => 'editable', 95 ) 96 ); 69 97 70 98 $this->assertEmpty( $q->posts ); … … 74 102 wp_set_current_user( self::$author_user_id ); 75 103 76 $q = new WP_Query( array( 77 'post_status' => array( 'private' ), 78 'perm' => 'readable', 79 ) ); 104 $q = new WP_Query( 105 array( 106 'post_status' => array( 'private' ), 107 'perm' => 'readable', 108 ) 109 ); 80 110 81 111 $expected = array( … … 89 119 wp_set_current_user( self::$editor_user_id ); 90 120 91 $q = new WP_Query( array( 92 'post_status' => array( 'private' ), 93 'perm' => 'readable', 94 ) ); 121 $q = new WP_Query( 122 array( 123 'post_status' => array( 'private' ), 124 'perm' => 'readable', 125 ) 126 ); 95 127 96 128 $expected = array( … … 105 137 wp_set_current_user( self::$author_user_id ); 106 138 107 $q = new WP_Query( array( 108 'post_status' => array( 'private' ), 109 'perm' => 'editable', 110 ) ); 139 $q = new WP_Query( 140 array( 141 'post_status' => array( 'private' ), 142 'perm' => 'editable', 143 ) 144 ); 111 145 112 146 $expected = array( … … 120 154 wp_set_current_user( self::$editor_user_id ); 121 155 122 $q = new WP_Query( array( 123 'post_status' => array( 'private' ), 124 'perm' => 'editable', 125 ) ); 156 $q = new WP_Query( 157 array( 158 'post_status' => array( 'private' ), 159 'perm' => 'editable', 160 ) 161 ); 126 162 127 163 $expected = array( … … 136 172 register_post_status( 'foo', array( 'public' => true ) ); 137 173 138 $q = new WP_Query( array( 139 'posts_per_page' => 1, // Or the query will short-circuit. 140 ) ); 174 $q = new WP_Query( 175 array( 176 'posts_per_page' => 1, // Or the query will short-circuit. 177 ) 178 ); 141 179 142 180 foreach ( get_post_stati( array( 'public' => true ) ) as $status ) { … … 148 186 register_post_status( 'foo', array( 'protected' => true ) ); 149 187 150 $q = new WP_Query( array( 151 'posts_per_page' => 1, // Or the query will short-circuit. 152 ) ); 188 $q = new WP_Query( 189 array( 190 'posts_per_page' => 1, // Or the query will short-circuit. 191 ) 192 ); 153 193 154 194 $this->assertNotContains( "post_status = 'foo", $q->request ); … … 157 197 public function test_protected_should_be_included_when_in_the_admin() { 158 198 set_current_screen( 'dashboard' ); 159 register_post_status( 'foo', array( 'protected' => true, 'show_in_admin_all_list' => true ) ); 160 161 $q = new WP_Query( array( 162 'posts_per_page' => -1, // Or the query will short-circuit. 163 ) ); 199 register_post_status( 200 'foo', array( 201 'protected' => true, 202 'show_in_admin_all_list' => true, 203 ) 204 ); 205 206 $q = new WP_Query( 207 array( 208 'posts_per_page' => -1, // Or the query will short-circuit. 209 ) 210 ); 164 211 165 212 $this->assertContains( "post_status = 'foo", $q->request ); … … 172 219 register_post_status( 'privatefoo', array( 'private' => true ) ); 173 220 174 $q = new WP_Query( array( 175 'posts_per_page' => -1, 176 ) ); 221 $q = new WP_Query( 222 array( 223 'posts_per_page' => -1, 224 ) 225 ); 177 226 178 227 $this->assertContains( self::$author_privatefoo_post, wp_list_pluck( $q->posts, 'ID' ) ); … … 185 234 register_post_status( 'privatefoo', array( 'private' => true ) ); 186 235 187 $q = new WP_Query( array( 188 'posts_per_page' => 2, // Or the query will short-circuit. 189 ) ); 236 $q = new WP_Query( 237 array( 238 'posts_per_page' => 2, // Or the query will short-circuit. 239 ) 240 ); 190 241 191 242 $expected = array( … … 202 253 $p = self::factory()->post->create( array( 'post_status' => 'foo_ps' ) ); 203 254 204 $q = new WP_Query( array( 205 'p' => $p, 206 ) ); 255 $q = new WP_Query( 256 array( 257 'p' => $p, 258 ) 259 ); 207 260 208 261 $this->assertEmpty( $q->posts ); … … 211 264 public function test_single_post_with_nonpublic_and_protected_status_should_not_be_shown_for_user_who_cannot_edit_others_posts() { 212 265 register_post_type( 'foo_pt' ); 213 register_post_status( 'foo_ps', array( 'public' => false, 'protected' => true ) ); 214 $p = self::factory()->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$editor_user_id ) ); 266 register_post_status( 267 'foo_ps', array( 268 'public' => false, 269 'protected' => true, 270 ) 271 ); 272 $p = self::factory()->post->create( 273 array( 274 'post_status' => 'foo_ps', 275 'post_author' => self::$editor_user_id, 276 ) 277 ); 215 278 216 279 wp_set_current_user( self::$author_user_id ); 217 280 218 $q = new WP_Query( array( 219 'p' => $p, 220 ) ); 281 $q = new WP_Query( 282 array( 283 'p' => $p, 284 ) 285 ); 221 286 222 287 $this->assertEmpty( $q->posts ); … … 225 290 public function test_single_post_with_nonpublic_and_protected_status_should_be_shown_for_user_who_can_edit_others_posts() { 226 291 register_post_type( 'foo_pt' ); 227 register_post_status( 'foo_ps', array( 'public' => false, 'protected' => true ) ); 228 $p = self::factory()->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$author_user_id ) ); 229 230 wp_set_current_user( self::$editor_user_id ); 231 232 $q = new WP_Query( array( 233 'p' => $p, 234 ) ); 292 register_post_status( 293 'foo_ps', array( 294 'public' => false, 295 'protected' => true, 296 ) 297 ); 298 $p = self::factory()->post->create( 299 array( 300 'post_status' => 'foo_ps', 301 'post_author' => self::$author_user_id, 302 ) 303 ); 304 305 wp_set_current_user( self::$editor_user_id ); 306 307 $q = new WP_Query( 308 array( 309 'p' => $p, 310 ) 311 ); 235 312 236 313 $this->assertEquals( array( $p ), wp_list_pluck( $q->posts, 'ID' ) ); … … 239 316 public function test_single_post_with_nonpublic_and_private_status_should_not_be_shown_for_user_who_cannot_edit_others_posts() { 240 317 register_post_type( 'foo_pt' ); 241 register_post_status( 'foo_ps', array( 'public' => false, 'private' => true ) ); 242 $p = self::factory()->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$editor_user_id ) ); 318 register_post_status( 319 'foo_ps', array( 320 'public' => false, 321 'private' => true, 322 ) 323 ); 324 $p = self::factory()->post->create( 325 array( 326 'post_status' => 'foo_ps', 327 'post_author' => self::$editor_user_id, 328 ) 329 ); 243 330 244 331 wp_set_current_user( self::$author_user_id ); 245 332 246 $q = new WP_Query( array( 247 'p' => $p, 248 ) ); 333 $q = new WP_Query( 334 array( 335 'p' => $p, 336 ) 337 ); 249 338 250 339 $this->assertEmpty( $q->posts ); … … 253 342 public function test_single_post_with_nonpublic_and_private_status_should_be_shown_for_user_who_can_edit_others_posts() { 254 343 register_post_type( 'foo_pt' ); 255 register_post_status( 'foo_ps', array( 'public' => false, 'private' => true ) ); 256 $p = self::factory()->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$author_user_id ) ); 257 258 wp_set_current_user( self::$editor_user_id ); 259 260 $q = new WP_Query( array( 261 'p' => $p, 262 ) ); 344 register_post_status( 345 'foo_ps', array( 346 'public' => false, 347 'private' => true, 348 ) 349 ); 350 $p = self::factory()->post->create( 351 array( 352 'post_status' => 'foo_ps', 353 'post_author' => self::$author_user_id, 354 ) 355 ); 356 357 wp_set_current_user( self::$editor_user_id ); 358 359 $q = new WP_Query( 360 array( 361 'p' => $p, 362 ) 363 ); 263 364 264 365 $this->assertEquals( array( $p ), wp_list_pluck( $q->posts, 'ID' ) ); … … 268 369 register_post_type( 'foo_pt' ); 269 370 register_post_status( 'foo_ps', array( 'public' => false ) ); 270 $p = self::factory()->post->create( array( 'post_status' => 'foo_ps', 'post_author' => self::$author_user_id ) ); 271 272 wp_set_current_user( self::$editor_user_id ); 273 274 $q = new WP_Query( array( 275 'p' => $p, 276 ) ); 371 $p = self::factory()->post->create( 372 array( 373 'post_status' => 'foo_ps', 374 'post_author' => self::$author_user_id, 375 ) 376 ); 377 378 wp_set_current_user( self::$editor_user_id ); 379 380 $q = new WP_Query( 381 array( 382 'p' => $p, 383 ) 384 ); 277 385 278 386 $this->assertEmpty( $q->posts ); … … 286 394 $p2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 287 395 288 $q = new WP_Query( array( 289 'p' => $p1, 290 'post_status' => array( 'trash', 'publish' ), 291 ) ); 396 $q = new WP_Query( 397 array( 398 'p' => $p1, 399 'post_status' => array( 'trash', 'publish' ), 400 ) 401 ); 292 402 293 403 $this->assertContains( $p1, wp_list_pluck( $q->posts, 'ID' ) );
Note: See TracChangeset
for help on using the changeset viewer.