Make WordPress Core


Ignore:
Timestamp:
10/23/2014 01:55:43 AM (10 years ago)
Author:
boonebgorges
Message:

Streamline WP_Date_Query unit tests.

By creating less dummy data and eliminating redundant tests, we cut group
execution time by more than 50%.

See #30017.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/query/dateQuery.php

    r29936 r29993  
    3434
    3535    public function test_date_query_before_array() {
    36         $this->create_posts();
     36        $p1 = $this->factory->post->create( array( 'post_date' => '2007-09-24 07:17:23',) );
     37        $p2 = $this->factory->post->create( array( 'post_date' => '2008-03-29 07:17:23',) );
     38        $p3 = $this->factory->post->create( array( 'post_date' => '2008-07-15 07:17:23',) );
     39        $p4 = $this->factory->post->create( array( 'post_date' => '2009-06-11 07:17:23',) );
    3740
    3841        $posts = $this->_get_query_result( array(
     
    4750        ) );
    4851
    49         $expected_dates = array(
    50             '1972-05-24 14:53:45',
    51             '1984-07-28 19:28:56',
    52             '2003-05-27 22:45:07',
    53             '2004-01-03 08:54:10',
    54             '2004-05-22 12:34:12',
    55             '2005-02-17 00:00:15',
    56             '2005-12-31 23:59:20',
    57             '2007-01-22 03:49:21',
    58             '2007-05-16 17:32:22',
    59             '2007-09-24 07:17:23',
    60             '2008-03-29 09:04:25',
    61         );
    62 
    63         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
     52        $this->assertEqualSets( array( $p1, $p2 ), wp_list_pluck( $posts, 'ID' ) );
    6453    }
    6554
     
    6958     */
    7059    public function test_date_query_before_array_test_defaulting() {
    71         $this->create_posts();
     60        $p1 = $this->factory->post->create( array( 'post_date' => '2007-09-24 07:17:23',) );
     61        $p2 = $this->factory->post->create( array( 'post_date' => '2008-03-29 07:17:23',) );
    7262
    7363        $posts = $this->_get_query_result( array(
     
    8171        ) );
    8272
    83         $expected_dates = array(
    84             '1972-05-24 14:53:45',
    85             '1984-07-28 19:28:56',
    86             '2003-05-27 22:45:07',
    87             '2004-01-03 08:54:10',
    88             '2004-05-22 12:34:12',
    89             '2005-02-17 00:00:15',
    90             '2005-12-31 23:59:20',
    91             '2007-01-22 03:49:21',
    92             '2007-05-16 17:32:22',
    93             '2007-09-24 07:17:23',
    94         );
    95 
    96         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
     73        $this->assertEqualSets( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
    9774    }
    9875
    9976    public function test_date_query_before_string() {
    100         $this->create_posts();
     77        $p1 = $this->factory->post->create( array( 'post_date' => '2007-09-24 07:17:23',) );
     78        $p2 = $this->factory->post->create( array( 'post_date' => '2008-03-29 07:17:23',) );
     79        $p3 = $this->factory->post->create( array( 'post_date' => '2008-07-15 07:17:23',) );
     80        $p4 = $this->factory->post->create( array( 'post_date' => '2009-06-11 07:17:23',) );
    10181
    10282        $posts = $this->_get_query_result( array(
     
    10888        ) );
    10989
    110         $expected_dates = array(
    111             '1972-05-24 14:53:45',
    112             '1984-07-28 19:28:56',
    113             '2003-05-27 22:45:07',
    114             '2004-01-03 08:54:10',
    115             '2004-05-22 12:34:12',
    116             '2005-02-17 00:00:15',
    117             '2005-12-31 23:59:20',
    118             '2007-01-22 03:49:21',
    119             '2007-05-16 17:32:22',
    120             '2007-09-24 07:17:23',
    121             '2008-03-29 09:04:25',
    122         );
    123 
    124         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
     90        $this->assertEquals( array( $p1, $p2 ), wp_list_pluck( $posts, 'ID' ) );
    12591    }
    12692
    12793    public function test_date_query_after_array() {
    128         $this->create_posts();
     94        $p1 = $this->factory->post->create( array( 'post_date' => '2009-10-18 10:42:29', ) );
     95        $p2 = $this->factory->post->create( array( 'post_date' => '2009-12-18 10:42:29', ) );
     96        $p3 = $this->factory->post->create( array( 'post_date' => '2010-06-11 07:17:23', ) );
    12997
    13098        $posts = $this->_get_query_result( array(
     
    140108        ) );
    141109
    142         $expected_dates = array(
    143             '2010-06-17 17:09:30',
    144             '2011-02-23 12:12:31',
    145             '2011-07-04 01:56:32',
    146             '2011-12-12 16:39:33',
    147             '2012-06-13 14:03:34',
    148             '2025-04-20 10:13:00',
    149             '2025-04-20 10:13:01',
    150             '2025-05-20 10:13:01',
    151         );
    152 
    153         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
     110        $this->assertEqualSets( array( $p3 ), wp_list_pluck( $posts, 'ID' ) );
    154111    }
    155112
     
    159116     */
    160117    public function test_date_query_after_array_test_defaulting() {
    161         $this->create_posts();
     118        $p1 = $this->factory->post->create( array( 'post_date' => '2008-12-18 10:42:29', ) );
     119        $p2 = $this->factory->post->create( array( 'post_date' => '2009-01-18 10:42:29', ) );
    162120
    163121        $posts = $this->_get_query_result( array(
     
    171129        ) );
    172130
    173         $expected_dates = array(
    174             '2009-06-11 21:30:28',
    175             '2009-12-18 10:42:29',
    176             '2010-06-17 17:09:30',
    177             '2011-02-23 12:12:31',
    178             '2011-07-04 01:56:32',
    179             '2011-12-12 16:39:33',
    180             '2012-06-13 14:03:34',
    181             '2025-04-20 10:13:00',
    182             '2025-04-20 10:13:01',
    183             '2025-05-20 10:13:01',
    184         );
    185 
    186         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
     131        $this->assertEquals( array( $p2 ), wp_list_pluck( $posts, 'ID' ) );
    187132    }
    188133
    189134    public function test_date_query_after_string() {
    190         $this->create_posts();
     135        $p1 = $this->factory->post->create( array( 'post_date' => '2009-12-18 09:42:29', ) );
     136        $p2 = $this->factory->post->create( array( 'post_date' => '2009-12-18 10:42:29', ) );
     137        $p3 = $this->factory->post->create( array( 'post_date' => '2009-12-19 10:42:29', ) );
    191138
    192139        $posts = $this->_get_query_result( array(
     
    198145        ) );
    199146
    200         $expected_dates = array(
    201             '2010-06-17 17:09:30',
    202             '2011-02-23 12:12:31',
    203             '2011-07-04 01:56:32',
    204             '2011-12-12 16:39:33',
    205             '2012-06-13 14:03:34',
    206             '2025-04-20 10:13:00',
    207             '2025-04-20 10:13:01',
    208             '2025-05-20 10:13:01',
    209         );
    210 
    211         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
     147        $this->assertEquals( array( $p3 ), wp_list_pluck( $posts, 'ID' ) );
    212148    }
    213149
    214150    public function test_date_query_after_string_inclusive() {
    215         $this->create_posts();
     151        $p1 = $this->factory->post->create( array( 'post_date' => '2009-12-18 09:42:29', ) );
     152        $p2 = $this->factory->post->create( array( 'post_date' => '2009-12-18 10:42:29', ) );
     153        $p3 = $this->factory->post->create( array( 'post_date' => '2009-12-19 10:42:29', ) );
    216154
    217155        $posts = $this->_get_query_result( array(
     
    224162        ) );
    225163
    226         $expected_dates = array(
    227             '2009-12-18 10:42:29',
    228             '2010-06-17 17:09:30',
    229             '2011-02-23 12:12:31',
    230             '2011-07-04 01:56:32',
    231             '2011-12-12 16:39:33',
    232             '2012-06-13 14:03:34',
    233             '2025-04-20 10:13:00',
    234             '2025-04-20 10:13:01',
    235             '2025-05-20 10:13:01',
    236         );
    237 
    238         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
     164        $this->assertEquals( array( $p2, $p3 ), wp_list_pluck( $posts, 'ID' ) );
    239165    }
    240166
     
    243169     */
    244170    public function test_date_query_inclusive_between_dates() {
    245         $this->create_posts();
     171        $p1 = $this->factory->post->create( array( 'post_date' => '2006-12-18 09:42:29', ) );
     172        $p2 = $this->factory->post->create( array( 'post_date' => '2007-01-18 10:42:29', ) );
     173        $p3 = $this->factory->post->create( array( 'post_date' => '2007-12-19 10:42:29', ) );
     174        $p4 = $this->factory->post->create( array( 'post_date' => '2008-12-19 10:42:29', ) );
     175        $p5 = $this->factory->post->create( array( 'post_date' => '2009-12-19 10:42:29', ) );
    246176
    247177        $posts = $this->_get_query_result( array(
     
    259189        ) );
    260190
    261 
    262         $expected_dates = array(
    263             '2007-01-22 03:49:21',
    264             '2007-05-16 17:32:22',
    265             '2007-09-24 07:17:23',
    266             '2008-03-29 09:04:25',
    267             '2008-07-15 11:32:26',
    268             '2008-12-10 13:06:27',
    269         );
    270 
    271         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
     191        $this->assertEquals( array( $p2, $p3, $p4 ), wp_list_pluck( $posts, 'ID' ) );
    272192    }
    273193
     
    644564    }
    645565
    646     public function test_date_query_year_expecting_results() {
    647         $this->create_posts();
    648 
     566    public function test_date_query_year() {
     567        $p1 = $this->factory->post->create( array( 'post_date' => '2009-12-19 10:42:29', ) );
     568        $p2 = $this->factory->post->create( array( 'post_date' => '2010-12-19 10:42:29', ) );
    649569        $posts = $this->_get_query_result( array(
    650570            'date_query' => array(
     
    655575        ) );
    656576
    657         $expected_dates = array(
    658             '2009-06-11 21:30:28',
    659             '2009-12-18 10:42:29',
    660         );
    661 
    662         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
    663     }
    664 
    665     public function test_date_query_year_expecting_noresults() {
    666         $this->create_posts();
    667 
    668         $posts = $this->_get_query_result( array(
    669             'date_query' => array(
    670                 array(
    671                     'year' => 2001,
    672                 ),
    673             ),
    674         ) );
    675 
    676         $this->assertCount( 0, $posts );
    677     }
    678 
    679     public function test_date_query_month_expecting_results() {
    680         $this->create_posts();
    681 
     577        $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     578    }
     579
     580    public function test_date_query_month() {
     581        $p1 = $this->factory->post->create( array( 'post_date' => '2009-12-19 10:42:29', ) );
     582        $p2 = $this->factory->post->create( array( 'post_date' => '2010-11-19 10:42:29', ) );
    682583        $posts = $this->_get_query_result( array(
    683584            'date_query' => array(
     
    688589        ) );
    689590
    690         $expected_dates = array(
    691             '2005-12-31 23:59:20',
    692             '2008-12-10 13:06:27',
    693             '2009-12-18 10:42:29',
    694             '2011-12-12 16:39:33',
    695         );
    696 
    697         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
    698     }
    699 
    700     public function test_date_query_month_expecting_noresults() {
    701         $this->create_posts();
    702 
    703         $posts = $this->_get_query_result( array(
    704             'date_query' => array(
    705                 array(
    706                     'month' => 8,
    707                 ),
    708             ),
    709         ) );
    710 
    711         $this->assertCount( 0, $posts );
    712     }
    713 
    714     public function test_date_query_week_expecting_results() {
    715         $this->create_posts();
    716 
     591        $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     592    }
     593
     594    public function test_date_query_week() {
     595        $p1 = $this->factory->post->create( array( 'post_date' => '2009-01-02 10:42:29', ) );
     596        $p2 = $this->factory->post->create( array( 'post_date' => '2010-03-19 10:42:29', ) );
    717597        $posts = $this->_get_query_result( array(
    718598            'date_query' => array(
     
    723603        ) );
    724604
    725         $expected_dates = array(
    726             '2004-01-03 08:54:10',
    727         );
    728 
    729         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
    730     }
    731 
    732     public function test_date_query_week_expecting_noresults() {
    733         $this->create_posts();
    734 
    735         $posts = $this->_get_query_result( array(
    736             'date_query' => array(
    737                 array(
    738                     'week' => 10,
    739                 ),
    740             ),
    741         ) );
    742 
    743         $this->assertCount( 0, $posts );
    744     }
    745 
    746     public function test_date_query_day_expecting_results() {
    747         $this->create_posts();
     605        $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     606    }
     607
     608    public function test_date_query_day() {
     609        $p1 = $this->factory->post->create( array( 'post_date' => '2009-01-17 10:42:29', ) );
     610        $p2 = $this->factory->post->create( array( 'post_date' => '2009-01-18 10:42:29', ) );
    748611
    749612        $posts = $this->_get_query_result( array(
     
    755618        ) );
    756619
    757         $expected_dates = array(
    758             '2005-02-17 00:00:15',
    759             '2010-06-17 17:09:30',
    760         );
    761 
    762         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
    763     }
    764 
    765     public function test_date_query_day_expecting_noresults() {
    766         $this->create_posts();
    767 
    768         $posts = $this->_get_query_result( array(
    769             'date_query' => array(
    770                 array(
    771                     'day' => 19,
    772                 ),
    773             ),
    774         ) );
    775 
    776         $this->assertCount( 0, $posts );
    777     }
    778 
    779     public function test_date_query_dayofweek_expecting_results() {
    780         $this->create_posts();
    781 
    782         $posts = $this->_get_query_result( array(
    783             'date_query' => array(
    784                 array(
    785                     'dayofweek' => 7,
    786                 ),
    787             ),
    788         ) );
    789 
    790         $expected_dates = array(
    791             '1984-07-28 19:28:56',
    792             '2004-01-03 08:54:10',
    793             '2004-05-22 12:34:12',
    794             '2005-12-31 23:59:20',
    795             '2008-03-29 09:04:25',
    796         );
    797 
    798         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
    799     }
    800 
    801     public function test_date_query_hour_expecting_results() {
    802         $this->create_posts();
     620        $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     621    }
     622
     623    public function test_date_query_dayofweek() {
     624        $p1 = $this->factory->post->create( array( 'post_date' => '2014-10-21 10:42:29', ) );
     625        $p2 = $this->factory->post->create( array( 'post_date' => '2014-10-20 10:42:29', ) );
     626
     627        $posts = $this->_get_query_result( array(
     628            'date_query' => array(
     629                array(
     630                    'dayofweek' => 3,
     631                ),
     632            ),
     633        ) );
     634
     635        $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     636    }
     637
     638    public function test_date_query_hour() {
     639        $p1 = $this->factory->post->create( array( 'post_date' => '2014-10-21 13:42:29', ) );
     640        $p2 = $this->factory->post->create( array( 'post_date' => '2014-10-21 12:42:29', ) );
    803641
    804642        $posts = $this->_get_query_result( array(
     
    810648        ) );
    811649
    812         $expected_dates = array(
    813             '2008-12-10 13:06:27',
    814         );
    815 
    816         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
    817     }
    818 
    819     public function test_date_query_hour_expecting_noresults() {
    820         $this->create_posts();
    821 
    822         $posts = $this->_get_query_result( array(
    823             'date_query' => array(
    824                 array(
    825                     'hour' => 2,
    826                 ),
    827             ),
    828         ) );
    829 
    830         $this->assertCount( 0, $posts );
    831     }
    832 
    833     public function test_date_query_minute_expecting_results() {
    834         $this->create_posts();
     650        $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     651    }
     652
     653    public function test_date_query_minute() {
     654        $p1 = $this->factory->post->create( array( 'post_date' => '2014-10-21 10:56:29', ) );
     655        $p2 = $this->factory->post->create( array( 'post_date' => '2014-10-21 10:42:29', ) );
    835656
    836657        $posts = $this->_get_query_result( array(
     
    842663        ) );
    843664
    844         $expected_dates = array(
    845             '2011-07-04 01:56:32',
    846         );
    847 
    848         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
    849     }
    850 
    851     public function test_date_query_minute_expecting_noresults() {
    852         $this->create_posts();
    853 
    854         $posts = $this->_get_query_result( array(
    855             'date_query' => array(
    856                 array(
    857                     'minute' => 2,
    858                 ),
    859             ),
    860         ) );
    861 
    862         $this->assertCount( 0, $posts );
    863     }
    864 
    865     public function test_date_query_second_expecting_results() {
    866         $this->create_posts();
     665        $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
     666    }
     667
     668    public function test_date_query_second() {
     669        $p1 = $this->factory->post->create( array( 'post_date' => '2014-10-21 10:42:21', ) );
     670        $p2 = $this->factory->post->create( array( 'post_date' => '2014-10-21 10:42:29', ) );
    867671
    868672        $posts = $this->_get_query_result( array(
     
    874678        ) );
    875679
    876         $expected_dates = array(
    877             '2007-01-22 03:49:21',
    878         );
    879 
    880         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
    881     }
    882 
    883     public function test_date_query_second_expecting_noresults() {
    884         $this->create_posts();
    885 
    886         $posts = $this->_get_query_result( array(
    887             'date_query' => array(
    888                 array(
    889                     'second' => 2,
    890                 ),
    891             ),
    892         ) );
    893 
    894         $this->assertCount( 0, $posts );
     680        $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
    895681    }
    896682
    897683    public function test_date_query_between_two_times() {
    898         $this->create_posts();
     684        $p1 = $this->factory->post->create( array( 'post_date' => '2005-12-18 08:42:29', ) );
     685        $p2 = $this->factory->post->create( array( 'post_date' => '2006-12-18 09:00:29', ) );
     686        $p3 = $this->factory->post->create( array( 'post_date' => '2007-12-18 10:42:29', ) );
     687        $p4 = $this->factory->post->create( array( 'post_date' => '2008-12-18 17:00:29', ) );
     688        $p5 = $this->factory->post->create( array( 'post_date' => '2009-12-18 18:42:29', ) );
    899689
    900690        $posts = $this->_get_query_result( array(
     
    913703        ) );
    914704
    915         $expected_dates = array(
    916             '1972-05-24 14:53:45',
    917             '2004-05-22 12:34:12',
    918             '2008-03-29 09:04:25',
    919             '2008-07-15 11:32:26',
    920             '2008-12-10 13:06:27',
    921             '2009-12-18 10:42:29',
    922             '2011-02-23 12:12:31',
    923             '2011-12-12 16:39:33',
    924             '2012-06-13 14:03:34',
    925             '2025-04-20 10:13:00',
    926             '2025-04-20 10:13:01',
    927             '2025-05-20 10:13:01',
    928         );
    929 
    930         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
     705        $this->assertEqualSets( array( $p2, $p3, $p4 ), wp_list_pluck( $posts, 'ID' ) );
    931706    }
    932707
    933708    public function test_date_query_relation_or() {
    934         $this->create_posts();
     709        $p1 = $this->factory->post->create( array( 'post_date' => '2006-12-18 14:42:29', ) );
     710        $p2 = $this->factory->post->create( array( 'post_date' => '2007-01-18 10:42:29', ) );
     711        $p3 = $this->factory->post->create( array( 'post_date' => '2007-12-19 10:34:29', ) );
    935712
    936713        $posts = $this->_get_query_result( array(
     
    946723        ) );
    947724
    948         $expected_dates = array(
    949             '1972-05-24 14:53:45',
    950             '2004-05-22 12:34:12',
    951             '2012-06-13 14:03:34',
    952         );
    953 
    954         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
     725        $this->assertEquals( array( $p1, $p3 ), wp_list_pluck( $posts, 'ID' ) );
    955726    }
    956727
    957728    public function test_date_query_compare_greater_than_or_equal_to() {
    958         $this->create_posts();
     729        $p1 = $this->factory->post->create( array( 'post_date' => '2006-12-18 13:42:29', ) );
     730        $p2 = $this->factory->post->create( array( 'post_date' => '2007-01-18 14:34:29', ) );
     731        $p3 = $this->factory->post->create( array( 'post_date' => '2007-12-19 14:37:29', ) );
     732        $p4 = $this->factory->post->create( array( 'post_date' => '2007-12-19 15:34:29', ) );
    959733
    960734        $posts = $this->_get_query_result( array(
     
    968742        ) );
    969743
    970         $expected_dates = array(
    971             '1972-05-24 14:53:45',
    972             '1984-07-28 19:28:56',
    973             '2003-05-27 22:45:07',
    974             '2005-12-31 23:59:20',
    975             '2007-05-16 17:32:22',
    976             '2009-06-11 21:30:28',
    977             '2010-06-17 17:09:30',
    978             '2011-12-12 16:39:33',
    979         );
    980 
    981         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
     744        $this->assertEquals( array( $p2, $p3, $p4 ), wp_list_pluck( $posts, 'ID' ) );
    982745    }
    983746
     
    985748        global $wpdb;
    986749
    987         $this->create_posts();
     750        $p1 = $this->factory->post->create( array( 'post_date' => '2006-05-18 13:42:29', ) );
     751        $p2 = $this->factory->post->create( array( 'post_date' => '2007-09-18 14:34:29', ) );
     752        $p3 = $this->factory->post->create( array( 'post_date' => '2007-01-18 14:34:29', ) );
    988753
    989754        $posts = $this->_get_query_result( array(
     
    994759        ) );
    995760
    996         $expected_dates = array(
    997             '1972-05-24 14:53:45',
    998             '2003-05-27 22:45:07',
    999             '2004-05-22 12:34:12',
    1000             '2007-05-16 17:32:22',
    1001             '2025-05-20 10:13:01',
    1002         );
    1003 
    1004         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
     761        $this->assertEquals( array( $p1 ), wp_list_pluck( $posts, 'ID' ) );
    1005762
    1006763        $this->assertContains( "MONTH( $wpdb->posts.post_date ) = 5", $this->q->request );
     
    1011768        global $wpdb;
    1012769
    1013         $this->create_posts();
    1014 
    1015         $posts = $this->_get_query_result( array(
    1016             'date_query' => array(
    1017                 'week' => 21,
    1018                 'w' => 22
    1019             ),
    1020         ) );
    1021 
    1022         $expected_dates = array(
    1023             '1972-05-24 14:53:45',
    1024             '2004-05-22 12:34:12',
    1025             '2025-05-20 10:13:01',
    1026         );
    1027 
    1028 
    1029         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
    1030 
    1031         $this->assertContains( "WEEK( $wpdb->posts.post_date, 1 ) = 21", $this->q->request );
    1032         $this->assertNotContains( "WEEK( $wpdb->posts.post_date, 1 ) = 22", $this->q->request );
     770        $p1 = $this->factory->post->create( array( 'post_date' => '2014-10-01 13:42:29', ) );
     771        $p2 = $this->factory->post->create( array( 'post_date' => '2014-10-22 14:34:29', ) );
     772        $p3 = $this->factory->post->create( array( 'post_date' => '2014-10-15 14:34:29', ) );
     773
     774        $posts = $this->_get_query_result( array(
     775            'date_query' => array(
     776                'week' => 43,
     777                'w' => 42,
     778            ),
     779        ) );
     780
     781        $this->assertEquals( array( $p2 ), wp_list_pluck( $posts, 'ID' ) );
     782
     783        $this->assertContains( "WEEK( $wpdb->posts.post_date, 1 ) = 43", $this->q->request );
     784        $this->assertNotContains( "WEEK( $wpdb->posts.post_date, 1 ) = 42", $this->q->request );
    1033785    }
    1034786
     
    1069821     */
    1070822    public function test_date_query_one_nested_query() {
    1071         $this->create_posts();
    1072 
     823        $p1 = $this->factory->post->create( array( 'post_date' => '2004-10-01 13:42:29', ) );
     824        $p2 = $this->factory->post->create( array( 'post_date' => '2004-01-22 14:34:29', ) );
     825        $p3 = $this->factory->post->create( array( 'post_date' => '1984-10-15 14:34:29', ) );
     826        $p4 = $this->factory->post->create( array( 'post_date' => '1985-10-15 14:34:29', ) );
    1073827        $posts = $this->_get_query_result( array(
    1074828            'date_query' => array(
     
    1089843        ) );
    1090844
    1091         $expected_dates = array(
    1092             '1984-07-28 19:28:56',
    1093             '2004-01-03 08:54:10',
    1094         );
    1095 
    1096         $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
     845        $this->assertEquals( array( $p2, $p3 ), wp_list_pluck( $posts, 'ID' ) );
    1097846    }
    1098847
     
    1217966    /** Helpers **********************************************************/
    1218967
    1219     protected function create_posts() {
    1220         // Be careful modifying this. Tests are coded to expect this exact sample data.
    1221         $post_dates = array(
    1222             '1972-05-24 14:53:45',
    1223             '1984-07-28 19:28:56',
    1224             '2003-05-27 22:45:07',
    1225             '2004-01-03 08:54:10',
    1226             '2004-05-22 12:34:12',
    1227             '2005-02-17 00:00:15',
    1228             '2005-12-31 23:59:20',
    1229             '2007-01-22 03:49:21',
    1230             '2007-05-16 17:32:22',
    1231             '2007-09-24 07:17:23',
    1232             '2008-03-29 09:04:25',
    1233             '2008-07-15 11:32:26',
    1234             '2008-12-10 13:06:27',
    1235             '2009-06-11 21:30:28',
    1236             '2009-12-18 10:42:29',
    1237             '2010-06-17 17:09:30',
    1238             '2011-02-23 12:12:31',
    1239             '2011-07-04 01:56:32',
    1240             '2011-12-12 16:39:33',
    1241             '2012-06-13 14:03:34',
    1242             '2025-04-20 10:13:00',
    1243             '2025-04-20 10:13:01',
    1244             '2025-05-20 10:13:01',
    1245         );
    1246 
    1247         foreach ( $post_dates as $post_date ) {
    1248             $this->factory->post->create( array( 'post_date' => $post_date ) );
    1249         }
    1250     }
    1251 
    1252968    /**
    1253969     * There's no way to change post_modified through the API.
Note: See TracChangeset for help on using the changeset viewer.