Improve performance of post revision order test.
`test_revision_order()` was written ([28541], #26042) to ensure that revision order was properly preserved in two different cases: (1) where the post_date varied (in which case the revisions would be sorted by post_date DESC) and (2) where the post_date was the same (in which case sorting would fall back on ID DESC). In an attempt to ensure that both of these scenarios arose in the context of a single test, 100 posts were created. We can make the process far more efficient by manually creating the revisions with the post_dates explicitly declared, and splitting the two different cases into two separate test methods. This test was previously the single worst offender in the entire suite, taking upwards of 15 seconds to run. All that most maddens and torments; all that stirs up the lees of things; all truth with malice in it; all that cracks the sinews and cakes the brain; all the subtle demonisms of life and thought; all evil, to crazy Boone, were visibly personified, and made practically assailable in `test_revision_order()`. See #30017. git-svn-id: https://develop.svn.wordpress.org/trunk@30511 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
36315d2b3f
commit
cfeae751a0
|
@ -342,29 +342,61 @@ class Tests_Post_Revisions extends WP_UnitTestCase {
|
|||
/**
|
||||
* @ticket 26042
|
||||
*/
|
||||
function test_revision_order() {
|
||||
$ok = 0;
|
||||
$reversed = 0;
|
||||
function test_wp_get_post_revisions_should_order_by_post_date() {
|
||||
global $wpdb;
|
||||
|
||||
for ( $i = 0; $i < 100; $i++ ) {
|
||||
$post_id = $this->factory->post->create( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) );
|
||||
$post = $this->factory->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) );
|
||||
|
||||
for ( $j = 1; $j < 3; $j++ ) {
|
||||
wp_update_post( array( 'post_content' => 'updated post' . $j , 'ID' => $post_id ) );
|
||||
}
|
||||
$post = (array) $post;
|
||||
$post_revision_fields = _wp_post_revision_fields( $post );
|
||||
$post_revision_fields = wp_slash( $post_revision_fields );
|
||||
|
||||
$revisions = wp_get_post_revisions( $post_id );
|
||||
$first = array_shift( $revisions );
|
||||
$last = array_pop( $revisions );
|
||||
$revision_ids = array();
|
||||
$now = time();
|
||||
for ( $j = 1; $j < 3; $j++ ) {
|
||||
// Manually modify dates to ensure they're different.
|
||||
$date = date( 'Y-m-d H:i:s', $now - ( $j * 10 ) );
|
||||
$post_revision_fields['post_date'] = $date;
|
||||
$post_revision_fields['post_date_gmt'] = $date;
|
||||
|
||||
if ( $first->ID < $last->ID ) {
|
||||
$reversed++;
|
||||
} else {
|
||||
$ok++;
|
||||
}
|
||||
$revision_id = wp_insert_post( $post_revision_fields );
|
||||
|
||||
$revision_ids[] = $revision_id;
|
||||
}
|
||||
|
||||
$this->assertEquals( 100, $ok );
|
||||
$this->assertEquals( 0, $reversed );
|
||||
$revisions = wp_get_post_revisions( $post['ID'] );
|
||||
|
||||
$this->assertEquals( $revision_ids, array_values( wp_list_pluck( $revisions, 'ID' ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 26042
|
||||
*/
|
||||
function test_wp_get_post_revisions_should_order_by_ID_when_post_date_matches() {
|
||||
global $wpdb;
|
||||
|
||||
$post = $this->factory->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) );
|
||||
|
||||
$post = (array) $post;
|
||||
$post_revision_fields = _wp_post_revision_fields( $post );
|
||||
$post_revision_fields = wp_slash( $post_revision_fields );
|
||||
|
||||
$revision_ids = array();
|
||||
$date = date( 'Y-m-d H:i:s', time() - 10 );
|
||||
for ( $j = 1; $j < 3; $j++ ) {
|
||||
// Manually modify dates to ensure they're the same.
|
||||
$post_revision_fields['post_date'] = $date;
|
||||
$post_revision_fields['post_date_gmt'] = $date;
|
||||
|
||||
$revision_id = wp_insert_post( $post_revision_fields );
|
||||
|
||||
$revision_ids[] = $revision_id;
|
||||
}
|
||||
|
||||
rsort( $revision_ids );
|
||||
|
||||
$revisions = wp_get_post_revisions( $post['ID'] );
|
||||
|
||||
$this->assertEquals( $revision_ids, array_values( wp_list_pluck( $revisions, 'ID' ) ) );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue