[wp-trac] [WordPress Trac] #40136: Failing rest-api test test_empty_post_date_gmt_shimmed_using_post_date

WordPress Trac noreply at wordpress.org
Tue Mar 14 13:21:34 UTC 2017


#40136: Failing rest-api test test_empty_post_date_gmt_shimmed_using_post_date
-------------------------------------------------+-------------------------
 Reporter:  afercia                              |       Owner:  jnylen0
     Type:  defect (bug)                         |      Status:  reopened
 Priority:  normal                               |   Milestone:  Awaiting
Component:  REST API                             |  Review
 Severity:  major                                |     Version:
 Keywords:  needs-refresh needs-patch dev-       |  Resolution:
  feedback                                       |     Focuses:
-------------------------------------------------+-------------------------
Changes (by nerrad):

 * keywords:  fixed-major => needs-refresh needs-patch dev-feedback
 * severity:  normal => major


Comment:

 So I did some diving to find out why tests using the
 `posts_dates_provider` are passing is because the way the tests run, the
 _date_ used in the tests are NOT in DST (i.e. _December 12_ is not in DST)
 and so all the related conversions happening in post controller/wp_posts
 api are working explicitly with the provided date.  So those tests don’t
 need changed.

 However, I’ve reversed my position and I think the original tests for
 `test_empty_post_date_gmt_shimmed_using_post_date` were actually correct
 and the fail was a valid fail.  The problem is this line of code (found in
 `WP_REST_Posts_Controller::prepare_item_for_response`:

 {{{
 $post_date_gmt = date( 'Y-m-d H:i:s', strtotime( $post->post_date ) - (
 get_option( 'gmt_offset' ) * 3600 ) );
 }}}

 That line is NOT considering the provided date when determining whether
 there should be a DST offset or not.  In other words, if the provided date
 was `12-12` (in `America/Chicago`) it should NOT have a DST for the
 conversion.  If the provided date was `3-14` in `America/Chicago` is
 _should_ have DST.

 Instead, that function is ALWAYS providing whatever state of DST exists
 for the _current_time_ .

 So that line that was introduced in [40115] needs fixed.  The unit test
 was actually working correctly and exposing a valid fail.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40136#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list