Ticket #30854: 30854.diff
File 30854.diff, 5.9 KB (added by , 7 years ago) |
---|
-
src/wp-includes/default-filters.php
306 306 add_action( 'shutdown', 'wp_ob_end_flush_all', 1 ); 307 307 // Create a revision whenever a post is updated. 308 308 add_action( 'post_updated', 'wp_save_post_revision', 10, 1 ); 309 add_action( 'new_to_publish', 'wp_save_post_revision', 10, 1 ); 309 310 add_action( 'publish_post', '_publish_post_hook', 5, 1 ); 310 311 add_action( 'transition_post_status', '_transition_post_status', 5, 3 ); 311 312 add_action( 'transition_post_status', '_update_term_count_on_transition_post_status', 10, 3 ); -
tests/phpunit/tests/post/revisions.php
141 141 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 142 142 143 143 $revisions = wp_get_post_revisions( $post_id ); 144 $this->assertCount( 1, $revisions );144 $this->assertCount( 2, $revisions ); 145 145 $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $post_id ) ); 146 146 147 147 foreach ( $revisions as $revision ) { … … 163 163 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 164 164 165 165 $revisions = wp_get_post_revisions( $post_id ); 166 $this->assertCount( 1, $revisions );166 $this->assertCount( 2, $revisions ); 167 167 foreach ( $revisions as $revision ) { 168 168 $this->assertTrue( user_can( self::$editor_user_id, 'edit_post', $revision->post_parent ) ); 169 169 } … … 185 185 186 186 // Diff checks if you can read both left and right revisions 187 187 $revisions = wp_get_post_revisions( $post_id ); 188 $this->assertCount( 2, $revisions );188 $this->assertCount( 3, $revisions ); 189 189 foreach ( $revisions as $revision ) { 190 190 $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $revision->ID ) ); 191 191 } … … 211 211 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 212 212 213 213 $revisions = wp_get_post_revisions( $post_id ); 214 $this->assertCount( 1, $revisions );214 $this->assertCount( 2, $revisions ); 215 215 $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $post_id ) ); 216 216 217 217 foreach ( $revisions as $revision ) { … … 244 244 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 245 245 246 246 $revisions = wp_get_post_revisions( $post_id ); 247 $this->assertCount( 1, $revisions );247 $this->assertCount( 2, $revisions ); 248 248 foreach ( $revisions as $revision ) { 249 249 $this->assertTrue( user_can( self::$editor_user_id, 'edit_post', $revision->post_parent ) ); 250 250 } … … 313 313 314 314 // Diff checks if you can read both left and right revisions 315 315 $revisions = wp_get_post_revisions( $post_id ); 316 $this->assertCount( 2, $revisions );316 $this->assertCount( 3, $revisions ); 317 317 foreach ( $revisions as $revision ) { 318 318 $this->assertTrue( user_can( self::$editor_user_id, 'read_post', $revision->ID ) ); 319 319 } … … 329 329 */ 330 330 function test_wp_get_post_revisions_should_order_by_post_date() { 331 331 global $wpdb; 332 $now = time(); 333 $date = date( 'Y-m-d H:i:s', $now ); 332 334 333 $post = self::factory()->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) );335 $post = self::factory()->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content', 'post_date' => $date, 'post_date_gmt' => $date ) ); 334 336 335 337 $post = (array) $post; 338 $revision_ids = array(); 339 340 $revisions = wp_get_post_revisions( $post['ID'] ); 341 $revision_ids[] = current( $revisions )->ID; 342 336 343 $post_revision_fields = _wp_post_revision_data( $post ); 337 344 $post_revision_fields = wp_slash( $post_revision_fields ); 338 345 339 $revision_ids = array();340 $now = time();341 346 for ( $j = 1; $j < 3; $j++ ) { 342 347 // Manually modify dates to ensure they're different. 343 348 $date = date( 'Y-m-d H:i:s', $now - ( $j * 10 ) ); … … 358 363 * @ticket 26042 359 364 */ 360 365 function test_wp_get_post_revisions_should_order_by_ID_when_post_date_matches() { 361 $post = self::factory()->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) ); 362 366 $revision_ids = array(); 367 $date = date( 'Y-m-d H:i:s', time() - 10 ); 368 $post = self::factory()->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content', 'post_date' => $date, 'post_date_gmt' => $date ) ); 363 369 $post = (array) $post; 364 370 $post_revision_fields = _wp_post_revision_data( $post ); 365 371 $post_revision_fields = wp_slash( $post_revision_fields ); 372 $revisions = wp_get_post_revisions( $post['ID'] ); 373 $revision_ids[] = current( $revisions )->ID; 366 374 367 $revision_ids = array();368 $date = date( 'Y-m-d H:i:s', time() - 10 );369 375 for ( $j = 1; $j < 3; $j++ ) { 370 376 // Manually modify dates to ensure they're the same. 371 377 $post_revision_fields['post_date'] = $date; … … 382 388 383 389 $this->assertEquals( $revision_ids, array_values( wp_list_pluck( $revisions, 'ID' ) ) ); 384 390 } 391 392 /** 393 * @ticket 39011 394 */ 395 function test_wp_first_revision_is_not_lost() { 396 $post = self::factory()->post->create_and_get( array( 397 'post_title' => 'some-post', 398 'post_type' => 'post', 399 'post_content' => 'Initial Content', 400 ) ); 401 402 wp_update_post( array( 403 'ID' => $post->ID, 404 'post_content' => 'Update #1', 405 ) ); 406 407 wp_update_post( array( 408 'ID' => $post->ID, 409 'post_content' => 'Update #2', 410 ) ); 411 412 $revisions = wp_get_post_revisions( $post->ID ); 413 $earliest_revision = end( $revisions ); 414 415 $this->assertEquals( 'Initial Content', $earliest_revision->post_content ); 416 } 385 417 }