Changeset 47122 for trunk/tests/phpunit/tests/post.php
- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post.php
r46969 r47122 40 40 } 41 41 42 // helper function: return the timestamp(s) of cron jobs for the specified hook and post 42 /** 43 * Helper function: return the timestamp(s) of cron jobs for the specified hook and post. 44 */ 43 45 function _next_schedule_for_post( $hook, $id ) { 44 46 return wp_next_scheduled( 'publish_future_post', array( 0 => intval( $id ) ) ); 45 47 } 46 48 47 // helper function, unsets current user globally 49 /** 50 * Helper function, unsets current user globally. 51 */ 48 52 function _unset_current_user() { 49 53 global $current_user, $user_ID; … … 53 57 } 54 58 55 // test simple valid behavior: insert and get a post 59 /** 60 * Test simple valid behavior: insert and get a post. 61 */ 56 62 function test_vb_insert_get_delete() { 57 63 register_post_type( 'cpt', array( 'taxonomies' => array( 'post_tag', 'ctax' ) ) ); … … 72 78 ); 73 79 74 // insert a post and make sure the ID is ok80 // Insert a post and make sure the ID is OK. 75 81 $id = wp_insert_post( $post ); 76 82 $this->assertTrue( is_numeric( $id ) ); 77 83 $this->assertTrue( $id > 0 ); 78 84 79 // fetch the post and make sure it matches85 // Fetch the post and make sure it matches. 80 86 $out = get_post( $id ); 81 87 … … 85 91 $this->assertEquals( $post['post_author'], $out->post_author ); 86 92 87 // test cache state93 // Test cache state. 88 94 $pcache = wp_cache_get( $id, 'posts' ); 89 95 $this->assertInstanceOf( 'stdClass', $pcache ); … … 112 118 } 113 119 120 /** 121 * Insert a post with a future date, and make sure the status and cron schedule are correct. 122 */ 114 123 function test_vb_insert_future() { 115 // insert a post with a future date, and make sure the status and cron schedule are correct116 117 124 $future_date = strtotime( '+1 day' ); 118 125 … … 125 132 ); 126 133 127 // insert a post and make sure the ID is ok134 // Insert a post and make sure the ID is OK. 128 135 $id = wp_insert_post( $post ); 129 136 $this->post_ids[] = $id; 130 #dmp(_get_cron_array());137 // dmp( _get_cron_array() ); 131 138 $this->assertTrue( is_numeric( $id ) ); 132 139 $this->assertTrue( $id > 0 ); 133 140 134 // fetch the post and make sure it matches141 // Fetch the post and make sure it matches. 135 142 $out = get_post( $id ); 136 143 … … 141 148 $this->assertEquals( $post['post_date'], $out->post_date ); 142 149 143 // there should be a publish_future_post hook scheduled on the future date150 // There should be a publish_future_post hook scheduled on the future date. 144 151 $this->assertEquals( $future_date, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 145 152 } 146 153 154 /** 155 * Insert a post with a future date, and make sure the status and cron schedule are correct. 156 */ 147 157 function test_vb_insert_future_over_dst() { 148 // insert a post with a future date, and make sure the status and cron schedule are correct 149 150 // Some magic days - one dst one not 158 // Some magic days - one DST one not. 151 159 $future_date_1 = strtotime( 'June 21st +1 year' ); 152 160 $future_date_2 = strtotime( 'Jan 11th +1 year' ); … … 160 168 ); 161 169 162 // insert a post and make sure the ID is ok170 // Insert a post and make sure the ID is OK. 163 171 $id = wp_insert_post( $post ); 164 172 $this->post_ids[] = $id; 165 173 166 // fetch the post and make sure has the correct date and status174 // Fetch the post and make sure has the correct date and status. 167 175 $out = get_post( $id ); 168 176 $this->assertEquals( 'future', $out->post_status ); 169 177 $this->assertEquals( $post['post_date'], $out->post_date ); 170 178 171 // check that there's a publish_future_post job scheduled at the right time179 // Check that there's a publish_future_post job scheduled at the right time. 172 180 $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 173 181 174 // now save it again with a date further in the future182 // Now save it again with a date further in the future. 175 183 176 184 $post['ID'] = $id; … … 179 187 wp_update_post( $post ); 180 188 181 // fetch the post again and make sure it has the new post_date189 // Fetch the post again and make sure it has the new post_date. 182 190 $out = get_post( $id ); 183 191 $this->assertEquals( 'future', $out->post_status ); 184 192 $this->assertEquals( $post['post_date'], $out->post_date ); 185 193 186 // and the correct date on the cron job194 // And the correct date on the cron job. 187 195 $this->assertEquals( $future_date_2, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 188 196 } 189 197 198 /** 199 * Future post bug: posts get published at the wrong time if you edit the timestamp. 200 * 201 * @ticket 4710 202 */ 190 203 function test_vb_insert_future_edit_bug() { 191 // future post bug: posts get published at the wrong time if you edit the timestamp192 // https://core.trac.wordpress.org/ticket/4710193 194 204 $future_date_1 = strtotime( '+1 day' ); 195 205 $future_date_2 = strtotime( '+2 day' ); … … 203 213 ); 204 214 205 // insert a post and make sure the ID is ok215 // Insert a post and make sure the ID is OK. 206 216 $id = wp_insert_post( $post ); 207 217 $this->post_ids[] = $id; 208 218 209 // fetch the post and make sure has the correct date and status219 // Fetch the post and make sure has the correct date and status. 210 220 $out = get_post( $id ); 211 221 $this->assertEquals( 'future', $out->post_status ); 212 222 $this->assertEquals( $post['post_date'], $out->post_date ); 213 223 214 // check that there's a publish_future_post job scheduled at the right time224 // Check that there's a publish_future_post job scheduled at the right time. 215 225 $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 216 226 217 // now save it again with a date further in the future227 // Now save it again with a date further in the future. 218 228 219 229 $post['ID'] = $id; … … 222 232 wp_update_post( $post ); 223 233 224 // fetch the post again and make sure it has the new post_date234 // Fetch the post again and make sure it has the new post_date. 225 235 $out = get_post( $id ); 226 236 $this->assertEquals( 'future', $out->post_status ); 227 237 $this->assertEquals( $post['post_date'], $out->post_date ); 228 238 229 // and the correct date on the cron job239 // And the correct date on the cron job. 230 240 $this->assertEquals( $future_date_2, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 231 241 } 232 242 243 /** 244 * Insert a draft post with a future date, and make sure no cron schedule is set. 245 */ 233 246 function test_vb_insert_future_draft() { 234 // insert a draft post with a future date, and make sure no cron schedule is set235 236 247 $future_date = strtotime( '+1 day' ); 237 248 … … 244 255 ); 245 256 246 // insert a post and make sure the ID is ok257 // Insert a post and make sure the ID is OK. 247 258 $id = wp_insert_post( $post ); 248 259 $this->post_ids[] = $id; 249 #dmp(_get_cron_array());260 // dmp( _get_cron_array() ); 250 261 $this->assertTrue( is_numeric( $id ) ); 251 262 $this->assertTrue( $id > 0 ); 252 263 253 // fetch the post and make sure it matches264 // Fetch the post and make sure it matches. 254 265 $out = get_post( $id ); 255 266 … … 260 271 $this->assertEquals( $post['post_date'], $out->post_date ); 261 272 262 // there should be a publish_future_post hook scheduled on the future date273 // There should be a publish_future_post hook scheduled on the future date. 263 274 $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 264 275 265 276 } 266 277 278 /** 279 * Insert a future post, then edit and change it to draft, and make sure cron gets it right. 280 */ 267 281 function test_vb_insert_future_change_to_draft() { 268 // insert a future post, then edit and change it to draft, and make sure cron gets it right269 282 $future_date_1 = strtotime( '+1 day' ); 270 283 … … 277 290 ); 278 291 279 // insert a post and make sure the ID is ok292 // Insert a post and make sure the ID is OK. 280 293 $id = wp_insert_post( $post ); 281 294 $this->post_ids[] = $id; 282 295 283 // fetch the post and make sure has the correct date and status296 // Fetch the post and make sure has the correct date and status. 284 297 $out = get_post( $id ); 285 298 $this->assertEquals( 'future', $out->post_status ); 286 299 $this->assertEquals( $post['post_date'], $out->post_date ); 287 300 288 // check that there's a publish_future_post job scheduled at the right time301 // Check that there's a publish_future_post job scheduled at the right time. 289 302 $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 290 303 291 // now save it again with status set to draft304 // Now save it again with status set to draft. 292 305 293 306 $post['ID'] = $id; … … 295 308 wp_update_post( $post ); 296 309 297 // fetch the post again and make sure it has the new post_date310 // Fetch the post again and make sure it has the new post_date. 298 311 $out = get_post( $id ); 299 312 $this->assertEquals( 'draft', $out->post_status ); 300 313 $this->assertEquals( $post['post_date'], $out->post_date ); 301 314 302 // and the correct date on the cron job315 // And the correct date on the cron job. 303 316 $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 304 317 } 305 318 319 /** 320 * Insert a future post, then edit and change the status, and make sure cron gets it right. 321 */ 306 322 function test_vb_insert_future_change_status() { 307 // insert a future post, then edit and change the status, and make sure cron gets it right308 323 $future_date_1 = strtotime( '+1 day' ); 309 324 … … 319 334 ); 320 335 321 // insert a post and make sure the ID is ok336 // Insert a post and make sure the ID is OK. 322 337 $id = wp_insert_post( $post ); 323 338 $this->post_ids[] = $id; 324 339 325 // fetch the post and make sure has the correct date and status340 // Fetch the post and make sure has the correct date and status. 326 341 $out = get_post( $id ); 327 342 $this->assertEquals( 'future', $out->post_status ); 328 343 $this->assertEquals( $post['post_date'], $out->post_date ); 329 344 330 // check that there's a publish_future_post job scheduled at the right time345 // Check that there's a publish_future_post job scheduled at the right time. 331 346 $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 332 347 333 // now save it again with status changed348 // Now save it again with status changed. 334 349 335 350 $post['ID'] = $id; … … 337 352 wp_update_post( $post ); 338 353 339 // fetch the post again and make sure it has the new post_date354 // Fetch the post again and make sure it has the new post_date. 340 355 $out = get_post( $id ); 341 356 $this->assertEquals( $status, $out->post_status ); 342 357 $this->assertEquals( $post['post_date'], $out->post_date ); 343 358 344 // and the correct date on the cron job359 // And the correct date on the cron job. 345 360 $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 346 361 } 347 362 } 348 363 364 /** 365 * Insert a draft post with a future date, and make sure no cron schedule is set. 366 */ 349 367 function test_vb_insert_future_private() { 350 // insert a draft post with a future date, and make sure no cron schedule is set351 352 368 $future_date = strtotime( '+1 day' ); 353 369 … … 360 376 ); 361 377 362 // insert a post and make sure the ID is ok378 // Insert a post and make sure the ID is OK. 363 379 $id = wp_insert_post( $post ); 364 380 $this->post_ids[] = $id; 365 #dmp(_get_cron_array());381 // dmp( _get_cron_array() ); 366 382 $this->assertTrue( is_numeric( $id ) ); 367 383 $this->assertTrue( $id > 0 ); 368 384 369 // fetch the post and make sure it matches385 // Fetch the post and make sure it matches. 370 386 $out = get_post( $id ); 371 387 … … 376 392 $this->assertEquals( $post['post_date'], $out->post_date ); 377 393 378 // there should be a publish_future_post hook scheduled on the future date394 // There should be a publish_future_post hook scheduled on the future date. 379 395 $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 380 396 } 381 397 382 398 /** 399 * Insert a post with an invalid date, make sure it fails. 400 * 383 401 * @ticket 17180 384 402 */ 385 403 function test_vb_insert_invalid_date() { 386 // insert a post with an invalid date, make sure it fails387 388 404 $post = array( 389 405 'post_author' => self::$editor_id, … … 394 410 ); 395 411 396 // Test both return paths with or without WP_Error 412 // Test both return paths with or without WP_Error. 397 413 $insert_post = wp_insert_post( $post, true ); 398 414 $this->assertWPError( $insert_post ); … … 403 419 } 404 420 421 /** 422 * Insert a future post, then edit and change it to private, and make sure cron gets it right. 423 */ 405 424 function test_vb_insert_future_change_to_private() { 406 // insert a future post, then edit and change it to private, and make sure cron gets it right407 425 $future_date_1 = strtotime( '+1 day' ); 408 426 … … 415 433 ); 416 434 417 // insert a post and make sure the ID is ok435 // Insert a post and make sure the ID is OK. 418 436 $id = wp_insert_post( $post ); 419 437 $this->post_ids[] = $id; 420 438 421 // fetch the post and make sure has the correct date and status439 // Fetch the post and make sure has the correct date and status. 422 440 $out = get_post( $id ); 423 441 $this->assertEquals( 'future', $out->post_status ); 424 442 $this->assertEquals( $post['post_date'], $out->post_date ); 425 443 426 // check that there's a publish_future_post job scheduled at the right time444 // Check that there's a publish_future_post job scheduled at the right time. 427 445 $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 428 446 429 // now save it again with status set to draft447 // Now save it again with status set to draft. 430 448 431 449 $post['ID'] = $id; … … 433 451 wp_update_post( $post ); 434 452 435 // fetch the post again and make sure it has the new post_date453 // Fetch the post again and make sure it has the new post_date. 436 454 $out = get_post( $id ); 437 455 $this->assertEquals( 'private', $out->post_status ); 438 456 $this->assertEquals( $post['post_date'], $out->post_date ); 439 457 440 // and the correct date on the cron job458 // And the correct date on the cron job. 441 459 $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 442 460 } … … 506 524 507 525 /** 526 * "When I delete a future post using wp_delete_post( $post->ID ) it does not update the cron correctly." 527 * 508 528 * @ticket 5364 509 529 */ 510 530 function test_delete_future_post_cron() { 511 // "When I delete a future post using wp_delete_post($post->ID) it does not update the cron correctly."512 531 $future_date = strtotime( '+1 day' ); 513 532 … … 520 539 ); 521 540 522 // insert a post and make sure the ID is ok541 // Insert a post and make sure the ID is OK. 523 542 $id = wp_insert_post( $post ); 524 543 $this->post_ids[] = $id; 525 544 526 // check that there's a publish_future_post job scheduled at the right time545 // Check that there's a publish_future_post job scheduled at the right time. 527 546 $this->assertEquals( $future_date, $this->_next_schedule_for_post( 'publish_future_post', $id ) ); 528 547 529 // now delete the post and make sure the cron entry is removed548 // Now delete the post and make sure the cron entry is removed. 530 549 wp_delete_post( $id ); 531 550 … … 534 553 535 554 /** 555 * Bug: permalink doesn't work if post title is empty. 556 * 557 * Might only fail if the post ID is greater than four characters. 558 * 536 559 * @ticket 5305 537 560 */ 538 561 function test_permalink_without_title() { 539 // bug: permalink doesn't work if post title is empty540 // might only fail if the post ID is greater than four characters541 542 562 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 543 563 … … 550 570 ); 551 571 552 // insert a post and make sure the ID is ok572 // Insert a post and make sure the ID is OK. 553 573 $id = wp_insert_post( $post ); 554 574 $this->post_ids[] = $id; … … 556 576 $plink = get_permalink( $id ); 557 577 558 // permalink should include the post ID at the end578 // Permalink should include the post ID at the end. 559 579 $this->assertEquals( get_option( 'siteurl' ) . '/2007/10/31/' . $id . '/', $plink ); 560 580 } … … 1107 1127 wp_set_current_user( self::$grammarian_id ); 1108 1128 1109 // Sanity Check.1129 // Sanity check. 1110 1130 $this->assertFalse( current_user_can( 'publish_posts' ) ); 1111 1131 $this->assertTrue( current_user_can( 'edit_others_posts' ) ); … … 1121 1141 stick_post( $post->ID ); 1122 1142 1123 // Sanity Check.1143 // Sanity check. 1124 1144 $this->assertTrue( is_sticky( $post->ID ) ); 1125 1145 … … 1152 1172 stick_post( $post->ID ); 1153 1173 1154 // Sanity Check.1174 // Sanity check. 1155 1175 $this->assertTrue( is_sticky( $post->ID ) ); 1156 1176 1157 1177 wp_set_current_user( self::$grammarian_id ); 1158 1178 1159 // Sanity Check.1179 // Sanity check. 1160 1180 $this->assertFalse( current_user_can( 'publish_posts' ) ); 1161 1181 $this->assertTrue( current_user_can( 'edit_others_posts' ) ); 1162 1182 $this->assertTrue( current_user_can( 'edit_published_posts' ) ); 1163 1183 1164 // Edit the post - The key 'sticky' is intentionally unset.1184 // Edit the post - the key 'sticky' is intentionally unset. 1165 1185 $data = array( 1166 1186 'post_ID' => $post->ID, … … 1170 1190 edit_post( $data ); 1171 1191 1172 // Make sure it's still sticky 1192 // Make sure it's still sticky. 1173 1193 $saved_post = get_post( $post->ID ); 1174 1194 $this->assertTrue( is_sticky( $saved_post->ID ) ); … … 1260 1280 ); 1261 1281 1262 // insert a post and make sure the ID is ok1282 // Insert a post and make sure the ID is OK. 1263 1283 $id = wp_insert_post( $post ); 1264 1284
Note: See TracChangeset
for help on using the changeset viewer.