Make WordPress Core

Changeset 13 in tests


Ignore:
Timestamp:
09/20/2007 11:46:13 AM (19 years ago)
Author:
tellyworth
Message:

fix test_vb_insert_future_edit_bug

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_includes_post.php

    r1 r13  
    7474                $this->assertEquals(array($id), $cron_args['args']);
    7575        }
     76       
     77        // helper function: return the timestamp(s) of cron jobs for the specified hook and post
     78        function _next_schedule_for_post($hook, $id) {
     79                return wp_next_scheduled('publish_future_post', array(0=>strval($id)));
     80        }
    7681
    7782        function test_vb_insert_future_edit_bug() {
    78                 // there was a bug that happens when you publish a future post, then change
    79                 // the timestamp - the original cron schedule is left intact so it's
    80                 // published at the wrong time.
     83                // future post bug: posts get published at the wrong time if you edit the timestamp
     84                // http://trac.wordpress.org/ticket/4710
    8185
    8286                $future_date_1 = strtotime('+1 day');
     
    9397                // insert a post and make sure the ID is ok
    9498                $id = $this->post_ids[] = wp_insert_post($post);
    95                 #dmp(_get_cron_array());
    96                 $this->assertTrue(is_numeric($id));
    97                 $this->assertTrue($id > 0);
    9899
    99                 $cron = _get_cron_array();
    100                 dmp($future_date_1, $cron);
     100                // fetch the post and make sure has the correct date and status
     101                $out = wp_get_single_post($id);
     102                $this->assertEquals('future', $out->post_status);
     103                $this->assertEquals($post['post_date'], $out->post_date);
     104
     105                // check that there's a publish_future_post job scheduled at the right time
     106                $this->assertEquals($future_date_1, $this->_next_schedule_for_post('publish_future_post', $id));
    101107
    102108                // now save it again with a date further in the future
    103109
    104                 // fetch the post and make sure it matches
     110                $post['ID'] = $id;
     111                $post['post_date'] = strftime("%Y-%m-%d %H:%M:%S", $future_date_2);
     112                $post['post_date_gmt'] = NULL;
     113                wp_update_post($post);
     114
     115                // fetch the post again and make sure it has the new post_date
    105116                $out = wp_get_single_post($id);
    106 
    107                 $this->assertEquals($post['post_content'], $out->post_content);
    108                 $this->assertEquals($post['post_title'], $out->post_title);
    109117                $this->assertEquals('future', $out->post_status);
    110                 $this->assertEquals($post['post_author'], $out->post_author);
    111118                $this->assertEquals($post['post_date'], $out->post_date);
    112119
    113                 // now change the date
    114                 $post['ID'] = $id;
    115                 $post['post_date'] = strftime("%Y-%m-%d %H:%M:%S", $future_date_1);
    116                 wp_update_post($post);
    117 
    118                 $this->assertEquals($post['post_content'], $out->post_content);
    119                 $this->assertEquals($post['post_title'], $out->post_title);
    120                 $this->assertEquals('future', $out->post_status);
    121                 $this->assertEquals($post['post_author'], $out->post_author);
    122                 $this->assertEquals($post['post_date'], $out->post_date);
    123 
    124                 $cron = _get_cron_array();
    125                 dmp($future_date_2, $cron);
    126 
    127                 $this->assertTrue(is_array($cron[$future_date_2]['publish_future_post']));
    128                 $cron_args = array_pop($cron[$future_date_2]['publish_future_post']);
    129                 $this->assertEquals('future', $cron_args['schedule']);
    130                 $this->assertEquals(array($id), $cron_args['args']);
     120                // and the correct date on the cron job
     121                $this->assertEquals($future_date_2, $this->_next_schedule_for_post('publish_future_post', $id));
    131122        }
    132123
Note: See TracChangeset for help on using the changeset viewer.