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.



git-svn-id: https://develop.svn.wordpress.org/trunk@28252 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2014-05-04 23:06:07 +00:00
parent 61765b8efd
commit 89ecbcc7cb
2 changed files with 47 additions and 6 deletions

View File

@@ -555,4 +555,49 @@ class Tests_Query_DateQuery extends WP_UnitTestCase {
$this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
}
public function test_date_params_monthnum_m_duplicate() {
$posts = $this->_get_query_result( array(
'date_query' => array(
'month' => 5,
'monthnum' => 9
),
) );
$expected_dates = array(
'1972-05-24 14:53:45',
'2003-05-27 22:45:07',
'2004-05-22 12:34:12',
'2007-05-16 17:32:22',
'2025-05-20 10:13:01',
);
$this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
$this->assertContains( "AND ( ( MONTH( post_date ) = 5 ) ) AND", $this->q->request );
$this->assertNotContains( "AND ( ( MONTH( post_date ) = 5 AND MONTH( post_date ) = 9 ) ) AND", $this->q->request );
}
public function test_date_params_week_w_duplicate() {
$posts = $this->_get_query_result( array(
'date_query' => array(
'week' => 21,
'w' => 22
),
) );
$expected_dates = array(
'1972-05-24 14:53:45',
'2004-05-22 12:34:12',
'2025-05-20 10:13:01',
);
$this->assertEquals( $expected_dates, wp_list_pluck( $posts, 'post_date' ) );
$this->assertContains( "AND ( ( WEEK( post_date, 1 ) = 21 ) ) AND", $this->q->request );
$this->assertNotContains( "AND ( ( WEEK( post_date, 1 ) = 21 AND WEEK( post_date, 1 ) = 22 ) ) AND", $this->q->request );
}
}