Changeset 31467 for trunk/tests/phpunit/tests/comment/query.php
- Timestamp:
- 02/16/2015 02:09:40 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/comment/query.php
r31015 r31467 613 613 614 614 $comments = get_comments( array( 'meta_value' => 'value3', 'orderby' => array( 'key' ) ) ); 615 $this->assertEquals( 2, count( $comments ) ); 616 $this->assertEquals( $comment_id, $comments[0]->comment_ID ); 617 $this->assertEquals( $comment_id3, $comments[1]->comment_ID ); 615 $this->assertEquals( array( $comment_id3, $comment_id ), wp_list_pluck( $comments, 'comment_ID' ) ); 618 616 619 617 $comments = get_comments( array( 'meta_value' => 'value3', 'orderby' => array( 'meta_value' ) ) ); 620 $this->assertEquals( 2, count( $comments ) ); 621 $this->assertEquals( $comment_id, $comments[0]->comment_ID ); 622 $this->assertEquals( $comment_id3, $comments[1]->comment_ID ); 618 $this->assertEquals( array( $comment_id3, $comment_id ), wp_list_pluck( $comments, 'comment_ID' ) ); 623 619 624 620 // value1 is present on two different keys for $comment_id yet we should get only one instance … … 630 626 $this->assertEquals( 1, count( $comments ) ); 631 627 } 628 629 /** 630 * @ticket 30478 631 */ 632 public function test_orderby_clause_key() { 633 $comments = $this->factory->comment->create_many( 3 ); 634 add_comment_meta( $comments[0], 'foo', 'aaa' ); 635 add_comment_meta( $comments[1], 'foo', 'zzz' ); 636 add_comment_meta( $comments[2], 'foo', 'jjj' ); 637 638 $q = new WP_Comment_Query(); 639 $found = $q->query( array( 640 'fields' => 'ids', 641 'meta_query' => array( 642 'foo_key' => array( 643 'key' => 'foo', 644 'compare' => 'EXISTS', 645 ), 646 ), 647 'orderby' => 'foo_key', 648 'order' => 'DESC', 649 ) ); 650 651 $this->assertEquals( array( $comments[1], $comments[2], $comments[0] ), $found ); 652 } 653 654 /** 655 * @ticket 30478 656 */ 657 public function test_orderby_clause_key_as_secondary_sort() { 658 $c1 = $this->factory->comment->create( array( 659 'comment_date' => '2015-01-28 03:00:00', 660 ) ); 661 $c2 = $this->factory->comment->create( array( 662 'comment_date' => '2015-01-28 05:00:00', 663 ) ); 664 $c3 = $this->factory->comment->create( array( 665 'comment_date' => '2015-01-28 03:00:00', 666 ) ); 667 668 add_comment_meta( $c1, 'foo', 'jjj' ); 669 add_comment_meta( $c2, 'foo', 'zzz' ); 670 add_comment_meta( $c3, 'foo', 'aaa' ); 671 672 $q = new WP_Comment_Query(); 673 $found = $q->query( array( 674 'fields' => 'ids', 675 'meta_query' => array( 676 'foo_key' => array( 677 'key' => 'foo', 678 'compare' => 'EXISTS', 679 ), 680 ), 681 'orderby' => array( 682 'comment_date' => 'asc', 683 'foo_key' => 'asc', 684 ), 685 ) ); 686 687 $this->assertEquals( array( $c3, $c1, $c2 ), $found ); 688 } 689 690 /** 691 * @ticket 30478 692 */ 693 public function test_orderby_more_than_one_clause_key() { 694 $comments = $this->factory->comment->create_many( 3 ); 695 696 add_comment_meta( $comments[0], 'foo', 'jjj' ); 697 add_comment_meta( $comments[1], 'foo', 'zzz' ); 698 add_comment_meta( $comments[2], 'foo', 'jjj' ); 699 add_comment_meta( $comments[0], 'bar', 'aaa' ); 700 add_comment_meta( $comments[1], 'bar', 'ccc' ); 701 add_comment_meta( $comments[2], 'bar', 'bbb' ); 702 703 $q = new WP_Comment_Query(); 704 $found = $q->query( array( 705 'fields' => 'ids', 706 'meta_query' => array( 707 'foo_key' => array( 708 'key' => 'foo', 709 'compare' => 'EXISTS', 710 ), 711 'bar_key' => array( 712 'key' => 'bar', 713 'compare' => 'EXISTS', 714 ), 715 ), 716 'orderby' => array( 717 'foo_key' => 'asc', 718 'bar_key' => 'desc', 719 ), 720 ) ); 721 722 $this->assertEquals( array( $comments[2], $comments[0], $comments[1] ), $found ); 723 } 724 632 725 633 726 /** … … 986 1079 987 1080 public function test_orderby_default() { 1081 global $wpdb; 1082 988 1083 $q = new WP_Comment_Query(); 989 1084 $q->query( array() ); 990 1085 991 $this->assertContains( 'ORDER BY comment_date_gmt', $q->request );1086 $this->assertContains( "ORDER BY $wpdb->comments.comment_date_gmt", $q->request ); 992 1087 } 993 1088 994 1089 public function test_orderby_single() { 1090 global $wpdb; 1091 995 1092 $q = new WP_Comment_Query(); 996 1093 $q->query( array( … … 998 1095 ) ); 999 1096 1000 $this->assertContains( 'ORDER BY comment_agent', $q->request );1097 $this->assertContains( "ORDER BY $wpdb->comments.comment_agent", $q->request ); 1001 1098 } 1002 1099 1003 1100 public function test_orderby_single_invalid() { 1101 global $wpdb; 1102 1004 1103 $q = new WP_Comment_Query(); 1005 1104 $q->query( array( … … 1007 1106 ) ); 1008 1107 1009 $this->assertContains( 'ORDER BY comment_date_gmt', $q->request );1108 $this->assertContains( "ORDER BY $wpdb->comments.comment_date_gmt", $q->request ); 1010 1109 } 1011 1110 1012 1111 public function test_orderby_comma_separated() { 1112 global $wpdb; 1113 1013 1114 $q = new WP_Comment_Query(); 1014 1115 $q->query( array( … … 1016 1117 ) ); 1017 1118 1018 $this->assertContains( 'ORDER BY comment_agent, comment_approved', $q->request ); 1019 } 1020 1021 public function test_orderby_array() { 1119 $this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request ); 1120 } 1121 1122 public function test_orderby_flat_array() { 1123 global $wpdb; 1124 1022 1125 $q = new WP_Comment_Query(); 1023 1126 $q->query( array( … … 1025 1128 ) ); 1026 1129 1027 $this->assertContains( 'ORDER BY comment_agent, comment_approved', $q->request );1130 $this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request ); 1028 1131 } 1029 1132 1030 1133 public function test_orderby_array_contains_invalid_item() { 1134 global $wpdb; 1135 1031 1136 $q = new WP_Comment_Query(); 1032 1137 $q->query( array( … … 1034 1139 ) ); 1035 1140 1036 $this->assertContains( 'ORDER BY comment_agent, comment_approved', $q->request );1141 $this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request ); 1037 1142 } 1038 1143 1039 1144 public function test_orderby_array_contains_all_invalid_items() { 1145 global $wpdb; 1146 1040 1147 $q = new WP_Comment_Query(); 1041 1148 $q->query( array( … … 1043 1150 ) ); 1044 1151 1045 $this->assertContains( 'ORDER BY comment_date_gmt', $q->request );1152 $this->assertContains( "ORDER BY $wpdb->comments.comment_date_gmt", $q->request ); 1046 1153 } 1047 1154 … … 1080 1187 1081 1188 $this->assertNotContains( 'ORDER BY', $q->request ); 1189 } 1190 1191 /** 1192 * @ticket 30478 1193 */ 1194 public function test_orderby_array() { 1195 global $wpdb; 1196 1197 $q = new WP_Comment_Query(); 1198 $found = $q->query( array( 1199 'fields' => 'ids', 1200 'orderby' => array( 1201 'comment_agent' => 'DESC', 1202 'comment_date_gmt' => 'ASC', 1203 'comment_ID' => 'DESC', 1204 ), 1205 ) ); 1206 1207 $this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date_gmt ASC, $wpdb->comments.comment_ID DESC", $q->request ); 1208 } 1209 1210 /** 1211 * @ticket 30478 1212 */ 1213 public function test_orderby_array_should_discard_invalid_columns() { 1214 global $wpdb; 1215 1216 $q = new WP_Comment_Query(); 1217 $found = $q->query( array( 1218 'fields' => 'ids', 1219 'orderby' => array( 1220 'comment_agent' => 'DESC', 1221 'foo' => 'ASC', 1222 'comment_ID' => 'DESC', 1223 ), 1224 ) ); 1225 1226 $this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_ID DESC", $q->request ); 1227 } 1228 1229 /** 1230 * @ticket 30478 1231 */ 1232 public function test_orderby_array_should_convert_invalid_order_to_DESC() { 1233 global $wpdb; 1234 1235 $q = new WP_Comment_Query(); 1236 $found = $q->query( array( 1237 'fields' => 'ids', 1238 'orderby' => array( 1239 'comment_agent' => 'DESC', 1240 'comment_date_gmt' => 'foo', 1241 'comment_ID' => 'DESC', 1242 ), 1243 ) ); 1244 1245 $this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date_gmt DESC, $wpdb->comments.comment_ID DESC", $q->request ); 1246 } 1247 1248 /** 1249 * @ticket 30478 1250 */ 1251 public function test_orderby_array_should_sort_by_comment_ID_as_fallback_and_should_inherit_order_from_comment_date_gmt() { 1252 global $wpdb; 1253 1254 $q = new WP_Comment_Query(); 1255 $found = $q->query( array( 1256 'fields' => 'ids', 1257 'orderby' => array( 1258 'comment_agent' => 'DESC', 1259 'comment_date_gmt' => 'ASC', 1260 ), 1261 ) ); 1262 1263 $this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date_gmt ASC, $wpdb->comments.comment_ID ASC", $q->request ); 1264 } 1265 1266 /** 1267 * @ticket 30478 1268 */ 1269 public function test_orderby_array_should_sort_by_comment_ID_as_fallback_and_should_inherit_order_from_comment_date() { 1270 global $wpdb; 1271 1272 $q = new WP_Comment_Query(); 1273 $found = $q->query( array( 1274 'fields' => 'ids', 1275 'orderby' => array( 1276 'comment_agent' => 'DESC', 1277 'comment_date' => 'ASC', 1278 ), 1279 ) ); 1280 1281 $this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date ASC, $wpdb->comments.comment_ID ASC", $q->request ); 1282 } 1283 1284 /** 1285 * @ticket 30478 1286 */ 1287 public function test_orderby_array_should_sort_by_comment_ID_DESC_as_fallback_when_not_sorted_by_date() { 1288 global $wpdb; 1289 1290 $q = new WP_Comment_Query(); 1291 $found = $q->query( array( 1292 'fields' => 'ids', 1293 'orderby' => array( 1294 'comment_agent' => 'ASC', 1295 ), 1296 ) ); 1297 1298 $this->assertContains( "ORDER BY $wpdb->comments.comment_agent ASC, $wpdb->comments.comment_ID DESC", $q->request ); 1299 } 1300 1301 /** 1302 * @ticket 30478 1303 */ 1304 public function test_orderby_date_modified_gmt_should_order_by_comment_ID_in_case_of_tie_ASC() { 1305 $now = current_time( 'mysql', 1 ); 1306 $comments = $this->factory->comment->create_many( 5, array( 1307 'comment_post_ID' => $this->post_id, 1308 'comment_date_gmt' => $now, 1309 ) ); 1310 1311 $q = new WP_Comment_Query(); 1312 $found = $q->query( array( 1313 'orderby' => 'comment_date_gmt', 1314 'order' => 'ASC', 1315 ) ); 1316 1317 // $comments is ASC by default. 1318 $this->assertEquals( $comments, wp_list_pluck( $found, 'comment_ID' ) ); 1319 } 1320 1321 /** 1322 * @ticket 30478 1323 */ 1324 public function test_orderby_date_modified_gmt_should_order_by_comment_ID_in_case_of_tie_DESC() { 1325 $now = current_time( 'mysql', 1 ); 1326 $comments = $this->factory->comment->create_many( 5, array( 1327 'comment_post_ID' => $this->post_id, 1328 'comment_date_gmt' => $now, 1329 ) ); 1330 1331 $q = new WP_Comment_Query(); 1332 $found = $q->query( array( 1333 'orderby' => 'comment_date_gmt', 1334 'order' => 'DESC', 1335 ) ); 1336 1337 // $comments is ASC by default. 1338 rsort( $comments ); 1339 1340 $this->assertEquals( $comments, wp_list_pluck( $found, 'comment_ID' ) ); 1082 1341 } 1083 1342
Note: See TracChangeset
for help on using the changeset viewer.