Make WordPress Core

Ticket #26653: unit-test.26653.diff

File unit-test.26653.diff, 2.1 KB (added by oso96_2000, 11 years ago)

Unit test and fixed diff route

  • src/wp-includes/date.php

    diff --git src/wp-includes/date.php src/wp-includes/date.php
    index 0c42766..7b73a3e 100644
    class WP_Date_Query { 
    235235
    236236                $compare = $this->get_compare( $query );
    237237
     238                $inclusive = ! empty( $query['inclusive'] );
     239
    238240                $lt = '<';
    239241                $gt = '>';
    240                 if ( ! empty( $query['inclusive'] ) ) {
     242                if ( $inclusive ) {
    241243                        $lt .= '=';
    242244                        $gt .= '=';
    243245                }
    244246
    245247                // Range queries
    246248                if ( ! empty( $query['after'] ) )
    247                         $where_parts[] = $wpdb->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], true ) );
     249                        $where_parts[] = $wpdb->prepare( "$column $gt %s", $this->build_mysql_datetime( $query['after'], ! $inclusive ) );
    248250
    249251                if ( ! empty( $query['before'] ) )
    250                         $where_parts[] = $wpdb->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], false ) );
     252                        $where_parts[] = $wpdb->prepare( "$column $lt %s", $this->build_mysql_datetime( $query['before'], $inclusive ) );
    251253
    252254                // Specific value queries
    253255
  • tests/phpunit/tests/query/dateQuery.php

    diff --git tests/phpunit/tests/query/dateQuery.php tests/phpunit/tests/query/dateQuery.php
    index 47cc71d..d737d60 100644
    class Tests_Query_DateQuery extends WP_UnitTestCase { 
    254254                $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
    255255        }
    256256
     257        public function test_date_query_inclusive_between_dates() {
     258                $posts = $this->_get_query_result( array(
     259                        'date_query' => array(
     260                                'after' => array(
     261                                        'year' => 2007,
     262                                        'month' => 1
     263                                ),
     264                                'before' => array(
     265                                        'year' => 2008,
     266                                        'month' => 12
     267                                ),
     268                                'inclusive' => true
     269                        ),
     270                ) );
     271
     272
     273                $expected_dates = array(
     274                        '2007-01-22 03:49:21',
     275                        '2007-05-16 17:32:22',
     276                        '2007-09-24 07:17:23',
     277                        '2008-03-29 09:04:25',
     278                        '2008-07-15 11:32:26',
     279                        '2008-12-10 13:06:27',
     280                );
     281
     282                $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
     283        }
     284
    257285        public function test_date_query_year_expecting_results() {
    258286                $posts = $this->_get_query_result( array(
    259287                        'date_query' => array(