- Timestamp:
- 11/22/2014 02:17:21 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/revisions.php
r28962 r30511 343 343 * @ticket 26042 344 344 */ 345 function test_revision_order() { 346 $ok = 0; 347 $reversed = 0; 348 349 for ( $i = 0; $i < 100; $i++ ) { 350 $post_id = $this->factory->post->create( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) ); 351 352 for ( $j = 1; $j < 3; $j++ ) { 353 wp_update_post( array( 'post_content' => 'updated post' . $j , 'ID' => $post_id ) ); 354 } 355 356 $revisions = wp_get_post_revisions( $post_id ); 357 $first = array_shift( $revisions ); 358 $last = array_pop( $revisions ); 359 360 if ( $first->ID < $last->ID ) { 361 $reversed++; 362 } else { 363 $ok++; 364 } 365 } 366 367 $this->assertEquals( 100, $ok ); 368 $this->assertEquals( 0, $reversed ); 345 function test_wp_get_post_revisions_should_order_by_post_date() { 346 global $wpdb; 347 348 $post = $this->factory->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) ); 349 350 $post = (array) $post; 351 $post_revision_fields = _wp_post_revision_fields( $post ); 352 $post_revision_fields = wp_slash( $post_revision_fields ); 353 354 $revision_ids = array(); 355 $now = time(); 356 for ( $j = 1; $j < 3; $j++ ) { 357 // Manually modify dates to ensure they're different. 358 $date = date( 'Y-m-d H:i:s', $now - ( $j * 10 ) ); 359 $post_revision_fields['post_date'] = $date; 360 $post_revision_fields['post_date_gmt'] = $date; 361 362 $revision_id = wp_insert_post( $post_revision_fields ); 363 364 $revision_ids[] = $revision_id; 365 } 366 367 $revisions = wp_get_post_revisions( $post['ID'] ); 368 369 $this->assertEquals( $revision_ids, array_values( wp_list_pluck( $revisions, 'ID' ) ) ); 370 } 371 372 /** 373 * @ticket 26042 374 */ 375 function test_wp_get_post_revisions_should_order_by_ID_when_post_date_matches() { 376 global $wpdb; 377 378 $post = $this->factory->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) ); 379 380 $post = (array) $post; 381 $post_revision_fields = _wp_post_revision_fields( $post ); 382 $post_revision_fields = wp_slash( $post_revision_fields ); 383 384 $revision_ids = array(); 385 $date = date( 'Y-m-d H:i:s', time() - 10 ); 386 for ( $j = 1; $j < 3; $j++ ) { 387 // Manually modify dates to ensure they're the same. 388 $post_revision_fields['post_date'] = $date; 389 $post_revision_fields['post_date_gmt'] = $date; 390 391 $revision_id = wp_insert_post( $post_revision_fields ); 392 393 $revision_ids[] = $revision_id; 394 } 395 396 rsort( $revision_ids ); 397 398 $revisions = wp_get_post_revisions( $post['ID'] ); 399 400 $this->assertEquals( $revision_ids, array_values( wp_list_pluck( $revisions, 'ID' ) ) ); 369 401 } 370 402 }
Note: See TracChangeset
for help on using the changeset viewer.