@@ -88,6 +88,20 @@ protected function get_feature() {
8888 protected function create_date_query_posts () {
8989 $ post_date = wp_date ( 'U ' , strtotime ( 'January 6th, 2012 11:59PM ' ) );
9090
91+ /**
92+ * Create dummy posts with the following dates.
93+ *
94+ * 2012-01-05 22:59:00
95+ * 2012-01-04 21:59:00
96+ * 2012-01-03 20:59:00
97+ * 2012-01-02 19:59:00
98+ * 2012-01-01 18:59:00
99+ * 2011-12-31 17:59:00
100+ * 2011-12-30 16:59:00
101+ * 2011-12-29 15:59:00
102+ * 2011-12-28 14:59:00
103+ * 2011-12-27 13:59:00
104+ */
91105 for ( $ i = 0 ; $ i <= 10 ; ++$ i ) {
92106 $ this ->ep_factory ->post ->create (
93107 array (
@@ -5502,17 +5516,17 @@ public function test_date_query_with_range_and_relation_or() {
55025516
55035517 $ args = [
55045518 'ep_integrate ' => true ,
5505- 'date_query ' => [
5506- 'relation ' => 'OR ' ,
5507- [
5508- 'year ' => 2025 ,
5509- 'month ' => 2 ,
5510- ],
5511- [
5512- 'year ' => 2025 ,
5513- 'month ' => 3 ,
5519+ 'date_query ' => [
5520+ 'relation ' => 'OR ' ,
5521+ [
5522+ 'year ' => 2025 ,
5523+ 'month ' => 2 ,
5524+ ],
5525+ [
5526+ 'year ' => 2025 ,
5527+ 'month ' => 3 ,
5528+ ],
55145529 ],
5515- ],
55165530 ];
55175531
55185532 $ query = new \WP_Query ( $ args );
@@ -5725,6 +5739,63 @@ public function testDateQueryValidateDateDoingItWrong() {
57255739 $ this ->assertFalse ( $ valid );
57265740 }
57275741
5742+ /**
5743+ * Test date_query with week and dayofyear, expecting specific post counts.
5744+ *
5745+ * @group post
5746+ */
5747+ public function test_date_query_week_and_day_of_year () {
5748+ $ this ->create_date_query_posts ();
5749+
5750+ $ args = [
5751+ 's ' => 'findme ' ,
5752+ 'date_query ' => [
5753+ [
5754+ 'week ' => 1 ,
5755+ 'year ' => 2012 ,
5756+ ],
5757+ ],
5758+ ];
5759+ $ query = new \WP_Query ( $ args );
5760+ $ this ->assertTrue ( $ query ->elasticsearch_success );
5761+ $ this ->assertEquals ( 5 , $ query ->post_count );
5762+
5763+ $ args = [
5764+ 's ' => 'findme ' ,
5765+ 'date_query ' => [
5766+ [
5767+ 'dayofyear ' => 5 ,
5768+ 'year ' => 2012 ,
5769+ ],
5770+ ],
5771+ ];
5772+ $ query = new \WP_Query ( $ args );
5773+ $ this ->assertTrue ( $ query ->elasticsearch_success );
5774+ $ this ->assertEquals ( 1 , $ query ->post_count );
5775+ }
5776+
5777+ /**
5778+ * Test date_query with compare !=.
5779+ *
5780+ * @group post
5781+ */
5782+ public function test_date_query_not_equals_compare () {
5783+ $ this ->create_date_query_posts ();
5784+ $ args = [
5785+ 's ' => 'findme ' ,
5786+ 'date_query ' => [
5787+ [
5788+ 'compare ' => '!= ' ,
5789+ 'year ' => 2012 ,
5790+ ],
5791+ ],
5792+ ];
5793+ $ query = new \WP_Query ( $ args );
5794+
5795+ $ this ->assertTrue ( $ query ->elasticsearch_success );
5796+ $ this ->assertEquals ( 5 , $ query ->post_count );
5797+ }
5798+
57285799 /**
57295800 * Test a date query with BETWEEN comparison
57305801 *
@@ -6016,18 +6087,23 @@ public function testDateQueryWeekdayRange() {
60166087 $ this ->assertEquals ( 9 , $ query ->found_posts );
60176088 }
60186089
6090+ /**
6091+ * Test date query with OR relation.
6092+ *
6093+ * @group post
6094+ */
60196095 public function test_date_query_with_or_relation () {
60206096 $ this ->create_date_query_posts ();
60216097
6022- $ args = [
6098+ $ args = [
60236099 'ep_integrate ' => true ,
60246100 'date_query ' => [
60256101 'relation ' => 'OR ' ,
60266102 [
6027- 'before ' => 'December 29th 2011 00:00:00 ' ,
6103+ 'before ' => 'December 29th 2011 00:00:00 ' ,
60286104 ],
60296105 [
6030- 'after ' => 'January 4th 2012 23:59:00 ' ,
6106+ 'after ' => 'January 4th 2012 23:59:00 ' ,
60316107 ],
60326108 ],
60336109 ];
@@ -6038,6 +6114,11 @@ public function test_date_query_with_or_relation() {
60386114 $ this ->assertEquals ( 4 , $ query ->found_posts );
60396115 }
60406116
6117+ /**
6118+ * Test date query with OR relation and year.
6119+ *
6120+ * @group post
6121+ */
60416122 public function test_date_query_with_or_relation_with_year () {
60426123 $ this ->ep_factory ->post ->create (
60436124 [
0 commit comments