Changeset 53782
- Timestamp:
- 07/26/2022 01:53:19 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post.php
r53771 r53782 36 36 wp_set_current_user( self::$editor_id ); 37 37 _set_cron_array( array() ); 38 39 $this->post_ids = array();40 38 } 41 39 … … 43 41 * Helper function: return the timestamp(s) of cron jobs for the specified hook and post. 44 42 */ 45 private function next_schedule_for_post( $hook, $ id ) {46 return wp_next_scheduled( 'publish_future_post', array( 0 => (int) $ id ) );43 private function next_schedule_for_post( $hook, $post_id ) { 44 return wp_next_scheduled( 'publish_future_post', array( 0 => (int) $post_id ) ); 47 45 } 48 46 … … 59 57 /** 60 58 * Test simple valid behavior: insert and get a post. 61 */ 62 public function test_vb_insert_get_delete() { 63 register_post_type( 'cpt', array( 'taxonomies' => array( 'post_tag', 'ctax' ) ) ); 59 * 60 * @dataProvider data_vb_insert_get_delete 61 */ 62 public function test_vb_insert_get_delete( $post_type ) { 63 register_post_type( 64 'cpt', 65 array( 66 'taxonomies' => array( 'post_tag', 'ctax' ), 67 ) 68 ); 64 69 register_taxonomy( 'ctax', 'cpt' ); 70 71 $data = array( 72 'post_author' => self::$editor_id, 73 'post_status' => 'publish', 74 'post_content' => "{$post_type}_content", 75 'post_title' => "{$post_type}_title", 76 'tax_input' => array( 77 'post_tag' => 'tag1,tag2', 78 'ctax' => 'cterm1,cterm2', 79 ), 80 'post_type' => $post_type, 81 ); 82 83 // Insert a post and make sure the ID is OK. 84 $post_id = wp_insert_post( $data ); 85 $this->assertIsInt( $post_id ); 86 $this->assertGreaterThan( 0, $post_id ); 87 88 // Fetch the post and make sure it matches. 89 $post = get_post( $post_id ); 90 91 $this->assertSame( $data['post_content'], $post->post_content ); 92 $this->assertSame( $data['post_title'], $post->post_title ); 93 $this->assertSame( $data['post_status'], $post->post_status ); 94 $this->assertEquals( $data['post_author'], $post->post_author ); 95 96 // Test cache state. 97 $post_cache = wp_cache_get( $post_id, 'posts' ); 98 $this->assertInstanceOf( 'stdClass', $post_cache ); 99 $this->assertSame( $post_id, $post_cache->ID ); 100 101 update_object_term_cache( $post_id, $post_type ); 102 $term_cache = wp_cache_get( $post_id, 'post_tag_relationships' ); 103 $this->assertIsArray( $term_cache ); 104 $this->assertCount( 2, $term_cache ); 105 106 $term_cache = wp_cache_get( $post_id, 'ctax_relationships' ); 107 if ( 'cpt' === $post_type ) { 108 $this->assertIsArray( $term_cache ); 109 $this->assertCount( 2, $term_cache ); 110 } else { 111 $this->assertFalse( $term_cache ); 112 } 113 114 wp_delete_post( $post_id, true ); 115 116 $this->assertFalse( wp_cache_get( $post_id, 'posts' ) ); 117 $this->assertFalse( wp_cache_get( $post_id, 'post_tag_relationships' ) ); 118 $this->assertFalse( wp_cache_get( $post_id, 'ctax_relationships' ) ); 119 120 $GLOBALS['wp_taxonomies']['post_tag']->object_type = array( 'post' ); 121 } 122 123 public function data_vb_insert_get_delete() { 65 124 $post_types = array( 'post', 'cpt' ); 66 125 67 foreach ( $post_types as $post_type ) { 68 $post = array( 69 'post_author' => self::$editor_id, 70 'post_status' => 'publish', 71 'post_content' => "{$post_type}_content", 72 'post_title' => "{$post_type}_title", 73 'tax_input' => array( 74 'post_tag' => 'tag1,tag2', 75 'ctax' => 'cterm1,cterm2', 76 ), 77 'post_type' => $post_type, 78 ); 79 80 // Insert a post and make sure the ID is OK. 81 $id = wp_insert_post( $post ); 82 $this->assertIsNumeric( $id ); 83 $this->assertGreaterThan( 0, $id ); 84 85 // Fetch the post and make sure it matches. 86 $out = get_post( $id ); 87 88 $this->assertSame( $post['post_content'], $out->post_content ); 89 $this->assertSame( $post['post_title'], $out->post_title ); 90 $this->assertSame( $post['post_status'], $out->post_status ); 91 $this->assertEquals( $post['post_author'], $out->post_author ); 92 93 // Test cache state. 94 $pcache = wp_cache_get( $id, 'posts' ); 95 $this->assertInstanceOf( 'stdClass', $pcache ); 96 $this->assertSame( $id, $pcache->ID ); 97 98 update_object_term_cache( $id, $post_type ); 99 $tcache = wp_cache_get( $id, 'post_tag_relationships' ); 100 $this->assertIsArray( $tcache ); 101 $this->assertCount( 2, $tcache ); 102 103 $tcache = wp_cache_get( $id, 'ctax_relationships' ); 104 if ( 'cpt' === $post_type ) { 105 $this->assertIsArray( $tcache ); 106 $this->assertCount( 2, $tcache ); 107 } else { 108 $this->assertFalse( $tcache ); 109 } 110 111 wp_delete_post( $id, true ); 112 $this->assertFalse( wp_cache_get( $id, 'posts' ) ); 113 $this->assertFalse( wp_cache_get( $id, 'post_tag_relationships' ) ); 114 $this->assertFalse( wp_cache_get( $id, 'ctax_relationships' ) ); 115 } 116 117 $GLOBALS['wp_taxonomies']['post_tag']->object_type = array( 'post' ); 126 return $this->text_array_to_dataprovider( $post_types ); 118 127 } 119 128 … … 124 133 $future_date = strtotime( '+1 day' ); 125 134 126 $ post= array(135 $data = array( 127 136 'post_author' => self::$editor_id, 128 137 'post_status' => 'publish', … … 133 142 134 143 // Insert a post and make sure the ID is OK. 135 $id = wp_insert_post( $post ); 136 $this->post_ids[] = $id; 137 // dmp( _get_cron_array() ); 138 $this->assertIsNumeric( $id ); 139 $this->assertGreaterThan( 0, $id ); 144 $post_id = wp_insert_post( $data ); 145 $this->assertIsInt( $post_id ); 146 $this->assertGreaterThan( 0, $post_id ); 140 147 141 148 // Fetch the post and make sure it matches. 142 $ out = get_post( $id );143 144 $this->assertSame( $ post['post_content'], $out->post_content );145 $this->assertSame( $ post['post_title'], $out->post_title );146 $this->assertSame( 'future', $ out->post_status );147 $this->assertEquals( $ post['post_author'], $out->post_author );148 $this->assertSame( $ post['post_date'], $out->post_date );149 $post = get_post( $post_id ); 150 151 $this->assertSame( $data['post_content'], $post->post_content ); 152 $this->assertSame( $data['post_title'], $post->post_title ); 153 $this->assertSame( 'future', $post->post_status ); 154 $this->assertEquals( $data['post_author'], $post->post_author ); 155 $this->assertSame( $data['post_date'], $post->post_date ); 149 156 150 157 // There should be a publish_future_post hook scheduled on the future date. 151 $this->assertSame( $future_date, $this->next_schedule_for_post( 'publish_future_post', $ id ) );158 $this->assertSame( $future_date, $this->next_schedule_for_post( 'publish_future_post', $post_id ) ); 152 159 } 153 160 … … 160 167 $future_date_2 = strtotime( 'Jan 11th +1 year' ); 161 168 162 $ post= array(169 $data = array( 163 170 'post_author' => self::$editor_id, 164 171 'post_status' => 'publish', … … 169 176 170 177 // Insert a post and make sure the ID is OK. 171 $id = wp_insert_post( $post ); 172 $this->post_ids[] = $id; 178 $post_id = wp_insert_post( $data ); 173 179 174 180 // Fetch the post and make sure has the correct date and status. 175 $ out = get_post( $id );176 $this->assertSame( 'future', $ out->post_status );177 $this->assertSame( $ post['post_date'], $out->post_date );181 $post = get_post( $post_id ); 182 $this->assertSame( 'future', $post->post_status ); 183 $this->assertSame( $data['post_date'], $post->post_date ); 178 184 179 185 // Check that there's a publish_future_post job scheduled at the right time. 180 $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $ id ) );186 $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $post_id ) ); 181 187 182 188 // Now save it again with a date further in the future. 183 184 $post['ID'] = $id; 185 $post['post_date'] = date_format( date_create( "@{$future_date_2}" ), 'Y-m-d H:i:s' ); 186 $post['post_date_gmt'] = null; 187 wp_update_post( $post ); 189 $data['ID'] = $post_id; 190 $data['post_date'] = date_format( date_create( "@{$future_date_2}" ), 'Y-m-d H:i:s' ); 191 $data['post_date_gmt'] = null; 192 wp_update_post( $data ); 188 193 189 194 // Fetch the post again and make sure it has the new post_date. 190 $ out = get_post( $id );191 $this->assertSame( 'future', $ out->post_status );192 $this->assertSame( $ post['post_date'], $out->post_date );195 $post = get_post( $post_id ); 196 $this->assertSame( 'future', $post->post_status ); 197 $this->assertSame( $data['post_date'], $post->post_date ); 193 198 194 199 // And the correct date on the cron job. 195 $this->assertSame( $future_date_2, $this->next_schedule_for_post( 'publish_future_post', $ id ) );200 $this->assertSame( $future_date_2, $this->next_schedule_for_post( 'publish_future_post', $post_id ) ); 196 201 } 197 202 … … 205 210 $future_date_2 = strtotime( '+2 day' ); 206 211 207 $ post= array(212 $data = array( 208 213 'post_author' => self::$editor_id, 209 214 'post_status' => 'publish', … … 214 219 215 220 // Insert a post and make sure the ID is OK. 216 $id = wp_insert_post( $post ); 217 $this->post_ids[] = $id; 221 $post_id = wp_insert_post( $data ); 218 222 219 223 // Fetch the post and make sure has the correct date and status. 220 $ out = get_post( $id );221 $this->assertSame( 'future', $ out->post_status );222 $this->assertSame( $ post['post_date'], $out->post_date );224 $post = get_post( $post_id ); 225 $this->assertSame( 'future', $post->post_status ); 226 $this->assertSame( $data['post_date'], $post->post_date ); 223 227 224 228 // Check that there's a publish_future_post job scheduled at the right time. 225 $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $ id ) );229 $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $post_id ) ); 226 230 227 231 // Now save it again with a date further in the future. 228 229 $post['ID'] = $id; 230 $post['post_date'] = date_format( date_create( "@{$future_date_2}" ), 'Y-m-d H:i:s' ); 231 $post['post_date_gmt'] = null; 232 wp_update_post( $post ); 232 $data['ID'] = $post_id; 233 $data['post_date'] = date_format( date_create( "@{$future_date_2}" ), 'Y-m-d H:i:s' ); 234 $data['post_date_gmt'] = null; 235 wp_update_post( $data ); 233 236 234 237 // Fetch the post again and make sure it has the new post_date. 235 $ out = get_post( $id );236 $this->assertSame( 'future', $ out->post_status );237 $this->assertSame( $ post['post_date'], $out->post_date );238 $post = get_post( $post_id ); 239 $this->assertSame( 'future', $post->post_status ); 240 $this->assertSame( $data['post_date'], $post->post_date ); 238 241 239 242 // And the correct date on the cron job. 240 $this->assertSame( $future_date_2, $this->next_schedule_for_post( 'publish_future_post', $ id ) );243 $this->assertSame( $future_date_2, $this->next_schedule_for_post( 'publish_future_post', $post_id ) ); 241 244 } 242 245 … … 247 250 $future_date = strtotime( '+1 day' ); 248 251 249 $ post= array(252 $data = array( 250 253 'post_author' => self::$editor_id, 251 254 'post_status' => 'draft', … … 256 259 257 260 // Insert a post and make sure the ID is OK. 258 $id = wp_insert_post( $post ); 259 $this->post_ids[] = $id; 260 // dmp( _get_cron_array() ); 261 $this->assertIsNumeric( $id ); 262 $this->assertGreaterThan( 0, $id ); 261 $post_id = wp_insert_post( $data ); 262 $this->assertIsInt( $post_id ); 263 $this->assertGreaterThan( 0, $post_id ); 263 264 264 265 // Fetch the post and make sure it matches. 265 $ out = get_post( $id );266 267 $this->assertSame( $ post['post_content'], $out->post_content );268 $this->assertSame( $ post['post_title'], $out->post_title );269 $this->assertSame( 'draft', $ out->post_status );270 $this->assertEquals( $ post['post_author'], $out->post_author );271 $this->assertSame( $ post['post_date'], $out->post_date );266 $post = get_post( $post_id ); 267 268 $this->assertSame( $data['post_content'], $post->post_content ); 269 $this->assertSame( $data['post_title'], $post->post_title ); 270 $this->assertSame( 'draft', $post->post_status ); 271 $this->assertEquals( $data['post_author'], $post->post_author ); 272 $this->assertSame( $data['post_date'], $post->post_date ); 272 273 273 274 // There should be a publish_future_post hook scheduled on the future date. 274 $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $ id ) );275 $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $post_id ) ); 275 276 276 277 } … … 282 283 $future_date_1 = strtotime( '+1 day' ); 283 284 284 $ post= array(285 $data = array( 285 286 'post_author' => self::$editor_id, 286 287 'post_status' => 'publish', … … 291 292 292 293 // Insert a post and make sure the ID is OK. 293 $id = wp_insert_post( $post ); 294 $this->post_ids[] = $id; 294 $post_id = wp_insert_post( $data ); 295 295 296 296 // Fetch the post and make sure has the correct date and status. 297 $ out = get_post( $id );298 $this->assertSame( 'future', $ out->post_status );299 $this->assertSame( $ post['post_date'], $out->post_date );297 $post = get_post( $post_id ); 298 $this->assertSame( 'future', $post->post_status ); 299 $this->assertSame( $data['post_date'], $post->post_date ); 300 300 301 301 // Check that there's a publish_future_post job scheduled at the right time. 302 $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $ id ) );302 $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $post_id ) ); 303 303 304 304 // Now save it again with status set to draft. 305 306 $post['ID'] = $id; 307 $post['post_status'] = 'draft'; 308 wp_update_post( $post ); 305 $data['ID'] = $post_id; 306 $data['post_status'] = 'draft'; 307 wp_update_post( $data ); 309 308 310 309 // Fetch the post again and make sure it has the new post_date. 311 $ out = get_post( $id );312 $this->assertSame( 'draft', $ out->post_status );313 $this->assertSame( $ post['post_date'], $out->post_date );310 $post = get_post( $post_id ); 311 $this->assertSame( 'draft', $post->post_status ); 312 $this->assertSame( $data['post_date'], $post->post_date ); 314 313 315 314 // And the correct date on the cron job. 316 $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $ id ) );315 $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $post_id ) ); 317 316 } 318 317 319 318 /** 320 319 * Insert a future post, then edit and change the status, and make sure cron gets it right. 321 */ 322 public function test_vb_insert_future_change_status() { 320 * 321 * @dataProvider data_vb_insert_future_change_status 322 */ 323 public function test_vb_insert_future_change_status( $status ) { 323 324 $future_date_1 = strtotime( '+1 day' ); 324 325 325 $statuses = array( 'draft', 'static', 'object', 'attachment', 'inherit', 'pending' ); 326 327 foreach ( $statuses as $status ) { 328 $post = array( 329 'post_author' => self::$editor_id, 330 'post_status' => 'publish', 331 'post_content' => "{$status}_content", 332 'post_title' => "{$status}_title", 333 'post_date' => date_format( date_create( "@{$future_date_1}" ), 'Y-m-d H:i:s' ), 334 ); 335 336 // Insert a post and make sure the ID is OK. 337 $id = wp_insert_post( $post ); 338 $this->post_ids[] = $id; 339 340 // Fetch the post and make sure has the correct date and status. 341 $out = get_post( $id ); 342 $this->assertSame( 'future', $out->post_status ); 343 $this->assertSame( $post['post_date'], $out->post_date ); 344 345 // Check that there's a publish_future_post job scheduled at the right time. 346 $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $id ) ); 347 348 // Now save it again with status changed. 349 350 $post['ID'] = $id; 351 $post['post_status'] = $status; 352 wp_update_post( $post ); 353 354 // Fetch the post again and make sure it has the new post_date. 355 $out = get_post( $id ); 356 $this->assertSame( $status, $out->post_status ); 357 $this->assertSame( $post['post_date'], $out->post_date ); 358 359 // And the correct date on the cron job. 360 $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $id ) ); 361 } 326 $data = array( 327 'post_author' => self::$editor_id, 328 'post_status' => 'publish', 329 'post_content' => "{$status}_content", 330 'post_title' => "{$status}_title", 331 'post_date' => date_format( date_create( "@{$future_date_1}" ), 'Y-m-d H:i:s' ), 332 ); 333 334 // Insert a post and make sure the ID is OK. 335 $post_id = wp_insert_post( $data ); 336 337 // Fetch the post and make sure has the correct date and status. 338 $post = get_post( $post_id ); 339 $this->assertSame( 'future', $post->post_status ); 340 $this->assertSame( $data['post_date'], $post->post_date ); 341 342 // Check that there's a publish_future_post job scheduled at the right time. 343 $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $post_id ) ); 344 345 // Now save it again with status changed. 346 $data['ID'] = $post_id; 347 $data['post_status'] = $status; 348 wp_update_post( $data ); 349 350 // Fetch the post again and make sure it has the new post_date. 351 $post = get_post( $post_id ); 352 $this->assertSame( $status, $post->post_status ); 353 $this->assertSame( $data['post_date'], $post->post_date ); 354 355 // And the correct date on the cron job. 356 $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $post_id ) ); 357 } 358 359 public function data_vb_insert_future_change_status() { 360 $statuses = array( 361 'draft', 362 'static', 363 'object', 364 'attachment', 365 'inherit', 366 'pending', 367 ); 368 369 return $this->text_array_to_dataprovider( $statuses ); 362 370 } 363 371 … … 368 376 $future_date = strtotime( '+1 day' ); 369 377 370 $ post= array(378 $data = array( 371 379 'post_author' => self::$editor_id, 372 380 'post_status' => 'private', … … 377 385 378 386 // Insert a post and make sure the ID is OK. 379 $id = wp_insert_post( $post ); 380 $this->post_ids[] = $id; 381 // dmp( _get_cron_array() ); 382 $this->assertIsNumeric( $id ); 383 $this->assertGreaterThan( 0, $id ); 387 $post_id = wp_insert_post( $data ); 388 $this->assertIsInt( $post_id ); 389 $this->assertGreaterThan( 0, $post_id ); 384 390 385 391 // Fetch the post and make sure it matches. 386 $ out = get_post( $id );387 388 $this->assertSame( $ post['post_content'], $out->post_content );389 $this->assertSame( $ post['post_title'], $out->post_title );390 $this->assertSame( 'private', $ out->post_status );391 $this->assertEquals( $ post['post_author'], $out->post_author );392 $this->assertSame( $ post['post_date'], $out->post_date );392 $post = get_post( $post_id ); 393 394 $this->assertSame( $data['post_content'], $post->post_content ); 395 $this->assertSame( $data['post_title'], $post->post_title ); 396 $this->assertSame( 'private', $post->post_status ); 397 $this->assertEquals( $data['post_author'], $post->post_author ); 398 $this->assertSame( $data['post_date'], $post->post_date ); 393 399 394 400 // There should be a publish_future_post hook scheduled on the future date. 395 $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $ id ) );401 $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $post_id ) ); 396 402 } 397 403 … … 402 408 */ 403 409 public function test_vb_insert_invalid_date() { 404 $ post= array(410 $data = array( 405 411 'post_author' => self::$editor_id, 406 412 'post_status' => 'publish', … … 411 417 412 418 // Test both return paths with or without WP_Error. 413 $ insert_post = wp_insert_post( $post, true );414 $this->assertWPError( $ insert_post);415 $this->assertSame( 'invalid_date', $ insert_post->get_error_code() );416 417 $ insert_post = wp_insert_post( $post);418 $this->assertSame( 0, $ insert_post);419 $post_id = wp_insert_post( $data, true ); 420 $this->assertWPError( $post_id ); 421 $this->assertSame( 'invalid_date', $post_id->get_error_code() ); 422 423 $post_id = wp_insert_post( $data ); 424 $this->assertSame( 0, $post_id ); 419 425 } 420 426 … … 425 431 $future_date_1 = strtotime( '+1 day' ); 426 432 427 $ post= array(433 $data = array( 428 434 'post_author' => self::$editor_id, 429 435 'post_status' => 'publish', … … 434 440 435 441 // Insert a post and make sure the ID is OK. 436 $id = wp_insert_post( $post ); 437 $this->post_ids[] = $id; 442 $post_id = wp_insert_post( $data ); 438 443 439 444 // Fetch the post and make sure has the correct date and status. 440 $ out = get_post( $id );441 $this->assertSame( 'future', $ out->post_status );442 $this->assertSame( $ post['post_date'], $out->post_date );445 $post = get_post( $post_id ); 446 $this->assertSame( 'future', $post->post_status ); 447 $this->assertSame( $data['post_date'], $post->post_date ); 443 448 444 449 // Check that there's a publish_future_post job scheduled at the right time. 445 $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $ id ) );450 $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $post_id ) ); 446 451 447 452 // Now save it again with status set to draft. 448 449 $post['ID'] = $id; 450 $post['post_status'] = 'private'; 451 wp_update_post( $post ); 453 $data['ID'] = $post_id; 454 $data['post_status'] = 'private'; 455 wp_update_post( $data ); 452 456 453 457 // Fetch the post again and make sure it has the new post_date. 454 $ out = get_post( $id );455 $this->assertSame( 'private', $ out->post_status );456 $this->assertSame( $ post['post_date'], $out->post_date );458 $post = get_post( $post_id ); 459 $this->assertSame( 'private', $post->post_status ); 460 $this->assertSame( $data['post_date'], $post->post_date ); 457 461 458 462 // And the correct date on the cron job. 459 $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $ id ) );463 $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $post_id ) ); 460 464 } 461 465 … … 466 470 $this->set_permalink_structure( '/%postname%/' ); 467 471 468 $p = wp_insert_post(472 $post_id = wp_insert_post( 469 473 array( 470 474 'post_title' => '', … … 475 479 ); 476 480 477 $post = get_post( $p ); 478 479 $this->set_permalink_structure(); 480 481 $this->assertSame( "$p-2", $post->post_name ); 481 $post = get_post( $post_id ); 482 483 $this->assertSame( "$post_id-2", $post->post_name ); 482 484 } 483 485 … … 489 491 register_post_type( 'wptests_pt' ); 490 492 491 $p = wp_insert_post(493 $post_id = wp_insert_post( 492 494 array( 493 495 'post_title' => '', … … 497 499 ); 498 500 499 $post = get_post( $p );500 501 $this->assertStringContainsString( 'wptests_pt=' . $p , $post->guid );501 $post = get_post( $post_id ); 502 503 $this->assertStringContainsString( 'wptests_pt=' . $post_id, $post->guid ); 502 504 } 503 505 … … 515 517 ); 516 518 517 $this->assertIs Numeric( $post_id );519 $this->assertIsInt( $post_id ); 518 520 $this->assertGreaterThan( 0, $post_id ); 519 521 } … … 548 550 $future_date = strtotime( '+1 day' ); 549 551 550 $ post= array(552 $data = array( 551 553 'post_author' => self::$editor_id, 552 554 'post_status' => 'publish', … … 557 559 558 560 // Insert a post and make sure the ID is OK. 559 $id = wp_insert_post( $post ); 560 $this->post_ids[] = $id; 561 $post_id = wp_insert_post( $data ); 561 562 562 563 // Check that there's a publish_future_post job scheduled at the right time. 563 $this->assertSame( $future_date, $this->next_schedule_for_post( 'publish_future_post', $ id ) );564 $this->assertSame( $future_date, $this->next_schedule_for_post( 'publish_future_post', $post_id ) ); 564 565 565 566 // Now delete the post and make sure the cron entry is removed. 566 wp_delete_post( $ id );567 568 $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $ id ) );567 wp_delete_post( $post_id ); 568 569 $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $post_id ) ); 569 570 } 570 571 … … 579 580 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); 580 581 581 $ post= array(582 $data = array( 582 583 'post_author' => self::$editor_id, 583 584 'post_status' => 'publish', … … 588 589 589 590 // Insert a post and make sure the ID is OK. 590 $id = wp_insert_post( $post ); 591 $this->post_ids[] = $id; 592 593 $plink = get_permalink( $id ); 591 $post_id = wp_insert_post( $data ); 594 592 595 593 // Permalink should include the post ID at the end. 596 $this->assertSame( get_option( 'siteurl' ) . '/2007/10/31/' . $id . '/', $plink ); 594 $expected = get_option( 'siteurl' ) . '/2007/10/31/' . $post_id . '/'; 595 $this->assertSame( $expected, get_permalink( $post_id ) ); 597 596 } 598 597 599 598 public function test_wp_publish_post() { 600 $draft_id = self::factory()->post->create( array( 'post_status' => 'draft' ) ); 599 $draft_id = self::factory()->post->create( 600 array( 601 'post_status' => 'draft', 602 ) 603 ); 601 604 602 605 $post = get_post( $draft_id ); … … 604 607 605 608 wp_publish_post( $draft_id ); 609 606 610 $post = get_post( $draft_id ); 607 608 611 $this->assertSame( 'publish', $post->post_status ); 609 612 } … … 626 629 627 630 wp_publish_post( $post_id ); 628 $post = get_post( $post_id ); 629 631 632 $post = get_post( $post_id ); 630 633 $this->assertSame( 'publish', $post->post_status ); 631 634 $this->assertSame( $future_date, $post->post_date ); … … 654 657 kses_remove_filters(); 655 658 656 $post_id = wp_insert_post( array( 'post_title' => '<script>Test</script>' ) ); 659 $post_id = wp_insert_post( 660 array( 661 'post_title' => '<script>Test</script>', 662 ) 663 ); 657 664 $post = get_post( $post_id ); 658 665 $this->assertSame( '<script>Test</script>', $post->post_title ); … … 667 674 ) 668 675 ); 676 677 kses_remove_filters(); 678 669 679 $post = get_post( $post->ID ); 670 680 $this->assertSame( 'Test', $post->post_title ); 671 672 kses_remove_filters();673 681 } 674 682 … … 679 687 kses_remove_filters(); 680 688 681 $post_id = wp_insert_post( array( 'post_title' => '<script>Test</script>' ) ); 689 $post_id = wp_insert_post( 690 array( 691 'post_title' => '<script>Test</script>', 692 ) 693 ); 682 694 $post = get_post( $post_id ); 683 695 $this->assertSame( '<script>Test</script>', $post->post_title ); … … 687 699 688 700 wp_publish_post( $post->ID ); 701 702 kses_remove_filters(); 703 689 704 $post = get_post( $post->ID ); 690 705 $this->assertSame( '<script>Test</script>', $post->post_title ); 691 692 kses_remove_filters();693 706 } 694 707 … … 698 711 public function test_get_post_ancestors_within_loop() { 699 712 global $post; 713 700 714 $parent_id = self::factory()->post->create(); 701 $post = self::factory()->post->create_and_get( array( 'post_parent' => $parent_id ) ); 715 $post = self::factory()->post->create_and_get( 716 array( 717 'post_parent' => $parent_id, 718 ) 719 ); 720 702 721 $this->assertSame( array( $parent_id ), get_post_ancestors( 0 ) ); 703 722 } … … 707 726 */ 708 727 public function test_update_invalid_post_id() { 709 $post_id = self::factory()->post->create( array( 'post_name' => 'get-page-uri-post-name' ));728 $post_id = self::factory()->post->create(); 710 729 $post = get_post( $post_id, ARRAY_A ); 711 730 … … 722 741 public function test_parse_post_content_single_page() { 723 742 global $multipage, $pages, $numpages; 724 $post_id = self::factory()->post->create( array( 'post_content' => 'Page 0' ) ); 743 744 $post_id = self::factory()->post->create( 745 array( 746 'post_content' => 'Page 0', 747 ) 748 ); 725 749 $post = get_post( $post_id ); 726 750 setup_postdata( $post ); 751 727 752 $this->assertSame( 0, $multipage ); 728 753 $this->assertCount( 1, $pages ); … … 733 758 public function test_parse_post_content_multi_page() { 734 759 global $multipage, $pages, $numpages; 735 $post_id = self::factory()->post->create( array( 'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3' ) ); 760 761 $post_id = self::factory()->post->create( 762 array( 763 'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3', 764 ) 765 ); 736 766 $post = get_post( $post_id ); 737 767 setup_postdata( $post ); 768 738 769 $this->assertSame( 1, $multipage ); 739 770 $this->assertCount( 4, $pages ); … … 744 775 public function test_parse_post_content_remaining_single_page() { 745 776 global $multipage, $pages, $numpages; 746 $post_id = self::factory()->post->create( array( 'post_content' => 'Page 0' ) ); 777 778 $post_id = self::factory()->post->create( 779 array( 780 'post_content' => 'Page 0', 781 ) 782 ); 747 783 $post = get_post( $post_id ); 748 784 setup_postdata( $post ); 785 749 786 $this->assertSame( 0, $multipage ); 750 787 $this->assertCount( 1, $pages ); … … 755 792 public function test_parse_post_content_remaining_multi_page() { 756 793 global $multipage, $pages, $numpages; 757 $post_id = self::factory()->post->create( array( 'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3' ) ); 794 795 $post_id = self::factory()->post->create( 796 array( 797 'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3', 798 ) 799 ); 758 800 $post = get_post( $post_id ); 759 801 setup_postdata( $post ); 802 760 803 $this->assertSame( 1, $multipage ); 761 804 $this->assertCount( 4, $pages ); … … 769 812 public function test_parse_post_content_starting_with_nextpage() { 770 813 global $multipage, $pages, $numpages; 771 $post_id = self::factory()->post->create( array( 'post_content' => '<!--nextpage-->Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3' ) ); 814 815 $post_id = self::factory()->post->create( 816 array( 817 'post_content' => '<!--nextpage-->Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3', 818 ) 819 ); 772 820 $post = get_post( $post_id ); 773 821 setup_postdata( $post ); 822 774 823 $this->assertSame( 1, $multipage ); 775 824 $this->assertCount( 4, $pages ); … … 783 832 public function test_parse_post_content_starting_with_nextpage_multi() { 784 833 global $multipage, $pages, $numpages; 785 $post_id = self::factory()->post->create( array( 'post_content' => '<!--nextpage-->Page 0' ) ); 834 835 $post_id = self::factory()->post->create( 836 array( 837 'post_content' => '<!--nextpage-->Page 0', 838 ) 839 ); 786 840 $post = get_post( $post_id ); 787 841 setup_postdata( $post ); 842 788 843 $this->assertSame( 0, $multipage ); 789 844 $this->assertCount( 1, $pages ); … … 800 855 register_taxonomy( 'test_tax', 'post' ); 801 856 802 $title 803 $ post_data= array(857 $title = 'title'; 858 $data = array( 804 859 'post_author' => self::$editor_id, 805 860 'post_status' => 'publish', … … 810 865 ), 811 866 ); 812 $insert_post_id = wp_insert_post( $post_data, true, true ); 813 $this->assertIsInt( $insert_post_id ); 814 $this->assertGreaterThan( 0, $insert_post_id ); 815 816 $post = get_post( $insert_post_id ); 817 $this->assertEquals( $post->post_author, self::$editor_id ); 818 $this->assertSame( $post->post_title, $title ); 867 868 $post_id = wp_insert_post( $data, true, true ); 869 $this->assertIsInt( $post_id ); 870 $this->assertGreaterThan( 0, $post_id ); 871 872 $post = get_post( $post_id ); 873 $this->assertEquals( self::$editor_id, $post->post_author ); 874 $this->assertSame( $title, $post->post_title ); 819 875 } 820 876 … … 825 881 $post_type = rand_str( 20 ); 826 882 register_post_type( $post_type ); 883 827 884 self::factory()->post->create( 828 885 array( … … 831 888 ) 832 889 ); 890 833 891 $count = wp_count_posts( $post_type, 'readable' ); 834 892 $this->assertEquals( 1, $count->publish ); 893 835 894 _unregister_post_type( $post_type ); 836 $this->assertEquals( new stdClass, wp_count_posts( $post_type, 'readable' ) ); 895 $count = wp_count_posts( $post_type, 'readable' ); 896 $this->assertEquals( new stdClass, $count ); 837 897 } 838 898 … … 840 900 $post_type = rand_str( 20 ); 841 901 register_post_type( $post_type ); 902 842 903 self::factory()->post->create_many( 843 904 3, … … 847 908 ) 848 909 ); 910 849 911 $count1 = wp_count_posts( $post_type, 'readable' ); 850 912 $this->assertEquals( 3, $count1->publish ); 913 851 914 add_filter( 'wp_count_posts', array( $this, 'filter_wp_count_posts' ) ); 852 853 915 $count2 = wp_count_posts( $post_type, 'readable' ); 916 remove_filter( 'wp_count_posts', array( $this, 'filter_wp_count_posts' ) ); 854 917 $this->assertEquals( 2, $count2->publish ); 855 856 remove_filter( 'wp_count_posts', array( $this, 'filter_wp_count_posts' ) );857 918 } 858 919 … … 866 927 $initial_counts = wp_count_posts(); 867 928 868 $key = array_rand( $post_ids ); 869 $_post = get_post( $post_ids[ $key ], ARRAY_A ); 929 $key = array_rand( $post_ids ); 930 $_post = get_post( $post_ids[ $key ], ARRAY_A ); 931 870 932 $_post['post_status'] = 'draft'; 871 933 wp_insert_post( $_post ); 934 872 935 $post = get_post( $post_ids[ $key ] ); 873 936 $this->assertSame( 'draft', $post->post_status ); … … 1026 1089 $post_type = rand_str( 20 ); 1027 1090 register_post_type( $post_type, array( 'supports' => array( 'comments', 'trackbacks' ) ) ); 1091 1028 1092 $post_id = self::factory()->post->create( 1029 1093 array( … … 1037 1101 $post = get_post( $post_id ); 1038 1102 1103 _unregister_post_type( $post_type ); 1104 1039 1105 $this->assertSame( 'open', $post->comment_status ); 1040 1106 $this->assertSame( 'open', $post->ping_status ); 1041 _unregister_post_type( $post_type );1042 1107 } 1043 1108 … … 1048 1113 $post_type = rand_str( 20 ); 1049 1114 register_post_type( $post_type ); 1115 1050 1116 $post_id = self::factory()->post->create( 1051 1117 array( … … 1059 1125 $post = get_post( $post_id ); 1060 1126 1127 _unregister_post_type( $post_type ); 1128 1061 1129 $this->assertSame( 'closed', $post->comment_status ); 1062 1130 $this->assertSame( 'closed', $post->ping_status ); 1063 _unregister_post_type( $post_type );1064 1131 } 1065 1132 … … 1160 1227 stick_post( $post_id ); 1161 1228 $this->assertTrue( is_sticky( $post_id ) ); 1229 1162 1230 unstick_post( $post_id ); 1163 1231 $this->assertFalse( is_sticky( $post_id ) ); … … 1218 1286 */ 1219 1287 public function test_wp_insert_post_should_respect_post_date_gmt() { 1220 $ post= array(1288 $data = array( 1221 1289 'post_author' => self::$editor_id, 1222 1290 'post_status' => 'publish', … … 1227 1295 1228 1296 // Insert a post and make sure the ID is OK. 1229 $ id = wp_insert_post( $post);1230 1231 $ out = get_post( $id );1232 1233 $this->assertSame( $ post['post_content'], $out->post_content );1234 $this->assertSame( $ post['post_title'], $out->post_title );1235 $this->assertEquals( $ post['post_author'], $out->post_author );1236 $this->assertSame( get_date_from_gmt( $ post['post_date_gmt'] ), $out->post_date );1237 $this->assertSame( $ post['post_date_gmt'], $out->post_date_gmt );1297 $post_id = wp_insert_post( $data ); 1298 1299 $post = get_post( $post_id ); 1300 1301 $this->assertSame( $data['post_content'], $post->post_content ); 1302 $this->assertSame( $data['post_title'], $post->post_title ); 1303 $this->assertEquals( $data['post_author'], $post->post_author ); 1304 $this->assertSame( get_date_from_gmt( $data['post_date_gmt'] ), $post->post_date ); 1305 $this->assertSame( $data['post_date_gmt'], $post->post_date_gmt ); 1238 1306 } 1239 1307 … … 1252 1320 ) 1253 1321 ); 1322 1254 1323 $this->assertSame( $parent_page_id, get_post( $page_id )->post_parent ); 1324 1255 1325 wp_delete_post( $parent_page_id, true ); 1256 1326 $this->assertSame( $grandparent_page_id, get_post( $page_id )->post_parent ); 1327 1257 1328 wp_delete_post( $grandparent_page_id, true ); 1258 1329 $this->assertSame( 0, get_post( $page_id )->post_parent ); … … 1266 1337 */ 1267 1338 public function test_wp_insert_post_for_customize_changeset_should_not_drop_post_name() { 1268 1269 1339 $this->assertSame( 10, has_filter( 'wp_insert_post_data', '_wp_customize_changeset_filter_insert_post_data' ) ); 1270 1340 … … 1371 1441 1372 1442 $post = get_post( $post_id ); 1373 self::assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date_gmt ), 2, 'The dates should be equal' ); 1443 self::assertEqualsWithDelta( 1444 strtotime( gmdate( 'Y-m-d H:i:s' ) ), 1445 strtotime( $post->post_date_gmt ), 1446 2, 1447 'The dates should be equal' 1448 ); 1374 1449 } 1375 1450 … … 1429 1504 ); 1430 1505 $post = get_post( $post_id ); 1431 $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' ); 1506 $this->assertEqualsWithDelta( 1507 strtotime( gmdate( 'Y-m-d H:i:s' ) ), 1508 strtotime( $post->post_date ), 1509 2, 1510 'The dates should be equal' 1511 ); 1432 1512 $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt ); 1433 1513 … … 1439 1519 ); 1440 1520 $post = get_post( $post_id ); 1441 $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' ); 1521 $this->assertEqualsWithDelta( 1522 strtotime( gmdate( 'Y-m-d H:i:s' ) ), 1523 strtotime( $post->post_date ), 1524 2, 1525 'The dates should be equal' 1526 ); 1442 1527 $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt ); 1443 1528 … … 1449 1534 ); 1450 1535 $post = get_post( $post_id ); 1451 $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' ); 1452 $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( get_gmt_from_date( $post->post_date ) ), 2, 'The dates should be equal' ); 1536 $this->assertEqualsWithDelta( 1537 strtotime( gmdate( 'Y-m-d H:i:s' ) ), 1538 strtotime( $post->post_date ), 1539 2, 1540 'The dates should be equal' 1541 ); 1542 $this->assertEqualsWithDelta( 1543 strtotime( gmdate( 'Y-m-d H:i:s' ) ), 1544 strtotime( get_gmt_from_date( $post->post_date ) ), 1545 2, 1546 'The dates should be equal' 1547 ); 1453 1548 1454 1549 $post_id = self::factory()->post->create( … … 1459 1554 ); 1460 1555 $post = get_post( $post_id ); 1461 $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' ); 1462 $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( get_gmt_from_date( $post->post_date ) ), 2, 'The dates should be equal' ); 1556 $this->assertEqualsWithDelta( 1557 strtotime( gmdate( 'Y-m-d H:i:s' ) ), 1558 strtotime( $post->post_date ), 1559 2, 1560 'The dates should be equal' 1561 ); 1562 $this->assertEqualsWithDelta( 1563 strtotime( gmdate( 'Y-m-d H:i:s' ) ), 1564 strtotime( get_gmt_from_date( $post->post_date ) ), 1565 2, 1566 'The dates should be equal' 1567 ); 1463 1568 1464 1569 // Valid post_date_gmt … … 1630 1735 1631 1736 $resolved_post_date = wp_resolve_post_date(); 1632 $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $resolved_post_date ), 2, 'The dates should be equal' ); 1737 $this->assertEqualsWithDelta( 1738 strtotime( gmdate( 'Y-m-d H:i:s' ) ), 1739 strtotime( $resolved_post_date ), 1740 2, 1741 'The dates should be equal' 1742 ); 1633 1743 1634 1744 $resolved_post_date = wp_resolve_post_date( '', $post_date_gmt );
Note: See TracChangeset
for help on using the changeset viewer.