Changeset 42343 for trunk/tests/phpunit/tests/date/query.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/date/query.php
r42056 r42343 35 35 36 36 public function test_construct_relation_or_lowercase() { 37 $q = new WP_Date_Query( array( 38 'relation' => 'or', 39 ) ); 37 $q = new WP_Date_Query( 38 array( 39 'relation' => 'or', 40 ) 41 ); 40 42 41 43 $this->assertSame( 'OR', $q->relation ); … … 43 45 44 46 public function test_construct_relation_invalid() { 45 $q = new WP_Date_Query( array( 46 'relation' => 'foo', 47 ) ); 47 $q = new WP_Date_Query( 48 array( 49 'relation' => 'foo', 50 ) 51 ); 48 52 49 53 $this->assertSame( 'AND', $q->relation ); … … 51 55 52 56 public function test_construct_query_not_an_array_of_arrays() { 53 $q = new WP_Date_Query( array( 54 'before' => array( 55 'year' => 2008, 56 'month' => 6, 57 ), 58 ) ); 59 60 $expected = array( 61 0 => array( 57 $q = new WP_Date_Query( 58 array( 62 59 'before' => array( 63 'year' => 2008,60 'year' => 2008, 64 61 'month' => 6, 65 62 ), 66 'column' => 'post_date', 67 'compare' => '=', 68 'relation' => 'AND', 69 ), 70 'column' => 'post_date', 71 'compare' => '=', 72 'relation' => 'AND', 73 ); 74 75 $this->assertSame( $expected, $q->queries ); 76 } 77 78 public function test_construct_query_contains_non_arrays() { 79 $q = new WP_Date_Query( array( 80 'foo', 81 'bar', 82 array( 83 'before' => array( 84 'year' => 2008, 63 ) 64 ); 65 66 $expected = array( 67 0 => array( 68 'before' => array( 69 'year' => 2008, 85 70 'month' => 6, 86 71 ), 87 ), 88 ) ); 72 'column' => 'post_date', 73 'compare' => '=', 74 'relation' => 'AND', 75 ), 76 'column' => 'post_date', 77 'compare' => '=', 78 'relation' => 'AND', 79 ); 80 81 $this->assertSame( $expected, $q->queries ); 82 } 83 84 public function test_construct_query_contains_non_arrays() { 85 $q = new WP_Date_Query( 86 array( 87 'foo', 88 'bar', 89 array( 90 'before' => array( 91 'year' => 2008, 92 'month' => 6, 93 ), 94 ), 95 ) 96 ); 89 97 90 98 $expected = array( 91 99 array( 92 'before' => array(93 'year' => 2008,100 'before' => array( 101 'year' => 2008, 94 102 'month' => 6, 95 103 ), 96 'column' => 'post_date', 104 'column' => 'post_date', 105 'compare' => '=', 106 'relation' => 'AND', 107 ), 108 'column' => 'post_date', 109 'compare' => '=', 110 'relation' => 'AND', 111 ); 112 113 $this->assertEquals( $expected, $q->queries ); 114 } 115 116 public function test_get_compare_empty() { 117 $q = new WP_Date_Query( array() ); 118 $this->assertSame( '=', $q->get_compare( array() ) ); 119 } 120 121 public function test_get_compare_equals() { 122 $q = new WP_Date_Query( array() ); 123 124 $found = $q->get_compare( 125 array( 97 126 'compare' => '=', 98 'relation' => 'AND', 99 ), 100 'column' => 'post_date', 101 'compare' => '=', 102 'relation' => 'AND', 103 ); 104 105 $this->assertEquals( $expected, $q->queries ); 106 } 107 108 public function test_get_compare_empty() { 109 $q = new WP_Date_Query( array() ); 110 $this->assertSame( '=', $q->get_compare( array() ) ); 111 } 112 113 public function test_get_compare_equals() { 114 $q = new WP_Date_Query( array() ); 115 116 $found = $q->get_compare( array( 117 'compare' => '=', 118 ) ); 127 ) 128 ); 119 129 $this->assertSame( '=', $found ); 120 130 } … … 123 133 $q = new WP_Date_Query( array() ); 124 134 125 $found = $q->get_compare( array( 126 'compare' => '!=', 127 ) ); 135 $found = $q->get_compare( 136 array( 137 'compare' => '!=', 138 ) 139 ); 128 140 $this->assertSame( '!=', $found ); 129 141 } … … 132 144 $q = new WP_Date_Query( array() ); 133 145 134 $found = $q->get_compare( array( 135 'compare' => '>', 136 ) ); 146 $found = $q->get_compare( 147 array( 148 'compare' => '>', 149 ) 150 ); 137 151 $this->assertSame( '>', $found ); 138 152 } … … 141 155 $q = new WP_Date_Query( array() ); 142 156 143 $found = $q->get_compare( array( 144 'compare' => '>=', 145 ) ); 157 $found = $q->get_compare( 158 array( 159 'compare' => '>=', 160 ) 161 ); 146 162 $this->assertSame( '>=', $found ); 147 163 } … … 150 166 $q = new WP_Date_Query( array() ); 151 167 152 $found = $q->get_compare( array( 153 'compare' => '<', 154 ) ); 168 $found = $q->get_compare( 169 array( 170 'compare' => '<', 171 ) 172 ); 155 173 $this->assertSame( '<', $found ); 156 174 } … … 159 177 $q = new WP_Date_Query( array() ); 160 178 161 $found = $q->get_compare( array( 162 'compare' => '<=', 163 ) ); 179 $found = $q->get_compare( 180 array( 181 'compare' => '<=', 182 ) 183 ); 164 184 $this->assertSame( '<=', $found ); 165 185 } … … 168 188 $q = new WP_Date_Query( array() ); 169 189 170 $found = $q->get_compare( array( 171 'compare' => 'IN', 172 ) ); 190 $found = $q->get_compare( 191 array( 192 'compare' => 'IN', 193 ) 194 ); 173 195 $this->assertSame( 'IN', $found ); 174 196 } … … 177 199 $q = new WP_Date_Query( array() ); 178 200 179 $found = $q->get_compare( array( 180 'compare' => 'NOT IN', 181 ) ); 201 $found = $q->get_compare( 202 array( 203 'compare' => 'NOT IN', 204 ) 205 ); 182 206 $this->assertSame( 'NOT IN', $found ); 183 207 } … … 186 210 $q = new WP_Date_Query( array() ); 187 211 188 $found = $q->get_compare( array( 189 'compare' => 'BETWEEN', 190 ) ); 212 $found = $q->get_compare( 213 array( 214 'compare' => 'BETWEEN', 215 ) 216 ); 191 217 $this->assertSame( 'BETWEEN', $found ); 192 218 } … … 195 221 $q = new WP_Date_Query( array() ); 196 222 197 $found = $q->get_compare( array( 198 'compare' => 'BETWEEN', 199 ) ); 223 $found = $q->get_compare( 224 array( 225 'compare' => 'BETWEEN', 226 ) 227 ); 200 228 $this->assertSame( 'BETWEEN', $found ); 201 229 } … … 367 395 $q = new WP_Date_Query( array() ); 368 396 369 $found = $q->build_value( 'BETWEEN', array( 370 2 => 4, 371 3 => 5, 372 ) ); 397 $found = $q->build_value( 398 'BETWEEN', array( 399 2 => 4, 400 3 => 5, 401 ) 402 ); 373 403 374 404 $this->assertSame( '4 AND 5', $found ); … … 425 455 $q = new WP_Date_Query( array() ); 426 456 427 $found = $q->build_value( 'NOT BETWEEN', array( 428 2 => 4, 429 3 => 5, 430 ) ); 457 $found = $q->build_value( 458 'NOT BETWEEN', array( 459 2 => 4, 460 3 => 5, 461 ) 462 ); 431 463 432 464 $this->assertSame( '4 AND 5', $found ); … … 471 503 472 504 // This might be a fragile test if it takes longer than 1 second to run 473 $found = $q->build_mysql_datetime( 'foo' );505 $found = $q->build_mysql_datetime( 'foo' ); 474 506 $expected = gmdate( 'Y-m-d H:i:s', false ); 475 507 $this->assertSame( $expected, $found ); … … 479 511 $q = new WP_Date_Query( array() ); 480 512 481 $found = $q->build_mysql_datetime( array( 482 'year' => 2011, 483 ), true ); 513 $found = $q->build_mysql_datetime( 514 array( 515 'year' => 2011, 516 ), true 517 ); 484 518 $this->assertSame( '2011-12-31 23:59:59', $found ); 485 519 } … … 488 522 $q = new WP_Date_Query( array() ); 489 523 490 $found = $q->build_mysql_datetime( array( 491 'year' => 2011, 492 ), false ); 524 $found = $q->build_mysql_datetime( 525 array( 526 'year' => 2011, 527 ), false 528 ); 493 529 $this->assertSame( '2011-01-01 00:00:00', $found ); 494 530 } … … 497 533 $q = new WP_Date_Query( array() ); 498 534 499 $found = $q->build_mysql_datetime( array( 500 'year' => 2011, 501 ), false ); 535 $found = $q->build_mysql_datetime( 536 array( 537 'year' => 2011, 538 ), false 539 ); 502 540 $this->assertSame( '2011-01-01 00:00:00', $found ); 503 541 } … … 650 688 * @expectedIncorrectUsage WP_Date_Query 651 689 */ 652 public function test_validate_date_query_before_after() {690 public function test_validate_date_query_before_after() { 653 691 // Valid values. 654 692 $valid_args = array( … … 697 735 * @expectedIncorrectUsage WP_Date_Query 698 736 */ 699 public function test_validate_date_query_before_after_with_month() {737 public function test_validate_date_query_before_after_with_month() { 700 738 // Both are valid. 701 739 $args = array( … … 704 742 'year' => 2014, 705 743 ), 706 'month' => 10,744 'month' => 10, 707 745 ); 708 746 $this->assertTrue( $this->q->validate_date_values( $args ) ); … … 714 752 'year' => 2014, 715 753 ), 716 'month' => 10,754 'month' => 10, 717 755 ); 718 756 $this->assertFalse( $this->q->validate_date_values( $args ) ); … … 724 762 'year' => 2014, 725 763 ), 726 'month' => 14,764 'month' => 14, 727 765 ); 728 766 $this->assertFalse( $this->q->validate_date_values( $args ) ); … … 734 772 'year' => 2014, 735 773 ), 736 'month' => 14,774 'month' => 14, 737 775 ); 738 776 $this->assertFalse( $this->q->validate_date_values( $args ) ); … … 784 822 'week' => 54, 785 823 'year' => 2009, 786 ) 824 ), 787 825 ); 788 826 … … 983 1021 $p2 = self::factory()->post->create( array( 'post_date' => '2013-01-12 00:00:00' ) ); 984 1022 985 $q = new WP_Query( array( 986 'date_query' => array( 987 array( 988 'compare' => 'BETWEEN', 989 'year' => array( 2012, 2014 ), 1023 $q = new WP_Query( 1024 array( 1025 'date_query' => array( 1026 array( 1027 'compare' => 'BETWEEN', 1028 'year' => array( 2012, 2014 ), 1029 ), 990 1030 ), 991 ),992 'fields' => 'ids',993 ) );1031 'fields' => 'ids', 1032 ) 1033 ); 994 1034 995 1035 $this->assertEquals( array( $p2 ), $q->posts ); … … 1003 1043 $p2 = self::factory()->post->create( array( 'post_date' => '2015-01-10 00:00:00' ) ); 1004 1044 1005 $q = new WP_Query( array( 1006 'date_query' => array( 1007 array( 1008 'compare' => 'BETWEEN', 1009 'day' => array( 9, 11 ), 1045 $q = new WP_Query( 1046 array( 1047 'date_query' => array( 1048 array( 1049 'compare' => 'BETWEEN', 1050 'day' => array( 9, 11 ), 1051 ), 1010 1052 ), 1011 ),1012 'fields' => 'ids',1013 ) );1053 'fields' => 'ids', 1054 ) 1055 ); 1014 1056 1015 1057 $this->assertEquals( array( $p2 ), $q->posts ); … … 1024 1066 $p2 = self::factory()->post->create( array( 'post_date' => '2015-01-10 00:00:00' ) ); 1025 1067 1026 $q = new WP_Query( array( 1027 'date_query' => array( 1028 array( 1029 'compare' => 'BETWEEN', 1030 'day' => array( 9, 32 ), 1068 $q = new WP_Query( 1069 array( 1070 'date_query' => array( 1071 array( 1072 'compare' => 'BETWEEN', 1073 'day' => array( 9, 32 ), 1074 ), 1031 1075 ), 1032 ),1033 'fields' => 'ids',1034 ) );1076 'fields' => 'ids', 1077 ) 1078 ); 1035 1079 1036 1080 // MySQL ignores the invalid clause. … … 1038 1082 } 1039 1083 1040 /** Helpers * *********************************************************/1084 /** Helpers */ 1041 1085 1042 1086 public function date_query_valid_columns_callback( $columns ) {
Note: See TracChangeset
for help on using the changeset viewer.