Make WordPress Core


Ignore:
Timestamp:
05/04/2014 11:06:07 PM (11 years ago)
Author:
wonderboymusic
Message:

In WP_Date_Query::get_sql_for_subquery(), don't parse duplicate parameters - only parse one of w and week or month and monthnum.

Adds unit tests.

Props oso96_2000, ChriCo.
Fixes #25835.

File:
1 edited

Legend:

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

    r25139 r28252  
    556556        $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
    557557    }
     558
     559    public function test_date_params_monthnum_m_duplicate() {
     560        $posts = $this->_get_query_result( array(
     561            'date_query' => array(
     562                'month' => 5,
     563                'monthnum' => 9
     564            ),
     565        ) );
     566
     567        $expected_dates = array(
     568            '1972-05-24 14:53:45',
     569            '2003-05-27 22:45:07',
     570            '2004-05-22 12:34:12',
     571            '2007-05-16 17:32:22',
     572            '2025-05-20 10:13:01',
     573        );
     574
     575        $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
     576
     577        $this->assertContains( "AND ( ( MONTH( post_date ) = 5 ) ) AND", $this->q->request );
     578
     579        $this->assertNotContains( "AND ( ( MONTH( post_date ) = 5 AND MONTH( post_date ) = 9 ) ) AND", $this->q->request );
     580    }
     581
     582    public function test_date_params_week_w_duplicate() {
     583        $posts = $this->_get_query_result( array(
     584            'date_query' => array(
     585                'week' => 21,
     586                'w' => 22
     587            ),
     588        ) );
     589
     590        $expected_dates = array(
     591            '1972-05-24 14:53:45',
     592            '2004-05-22 12:34:12',
     593            '2025-05-20 10:13:01',
     594        );
     595
     596
     597        $this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
     598
     599        $this->assertContains( "AND ( ( WEEK( post_date, 1 ) = 21 ) ) AND", $this->q->request );
     600
     601        $this->assertNotContains( "AND ( ( WEEK( post_date, 1 ) = 21 AND WEEK( post_date, 1 ) = 22 ) ) AND", $this->q->request );
     602    }
    558603}
Note: See TracChangeset for help on using the changeset viewer.