Changeset 30003
- Timestamp:
- 10/24/2014 02:33:46 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment.php
r29965 r30003 222 222 */ 223 223 class WP_Comment_Query { 224 /** 225 * SQL for database query. 226 * 227 * @since 4.0.1 228 * @access public 229 * @var string 230 */ 231 public $request; 232 224 233 /** 225 234 * Metadata query container … … 579 588 $groupby = 'GROUP BY ' . $groupby; 580 589 } 581 $query = "SELECT $fields FROM $wpdb->comments $join WHERE $where $groupby ORDER BY $orderby $order $limits"; 590 591 $this->request = "SELECT $fields FROM $wpdb->comments $join WHERE $where $groupby $orderby $order $limits"; 582 592 583 593 if ( $this->query_vars['count'] ) { 584 return $wpdb->get_var( $ query);594 return $wpdb->get_var( $this->request ); 585 595 } 586 596 587 597 if ( 'ids' == $this->query_vars['fields'] ) { 588 $this->comments = $wpdb->get_col( $ query);598 $this->comments = $wpdb->get_col( $this->request ); 589 599 return array_map( 'intval', $this->comments ); 590 600 } 591 601 592 $results = $wpdb->get_results( $ query);602 $results = $wpdb->get_results( $this->request ); 593 603 /** 594 604 * Filter the comment query results. -
trunk/tests/phpunit/tests/comment/query.php
r29982 r30003 517 517 $this->assertEquals( array( $c1, $c2, $c3, $c4, $c5 ), $found ); 518 518 } 519 520 public function test_orderby_default() { 521 $q = new WP_Comment_Query(); 522 $q->query( array() ); 523 524 $this->assertContains( 'ORDER BY comment_date_gmt', $q->request ); 525 } 526 527 public function test_orderby_single() { 528 $q = new WP_Comment_Query(); 529 $q->query( array( 530 'orderby' => 'comment_agent', 531 ) ); 532 533 $this->assertContains( 'ORDER BY comment_agent', $q->request ); 534 } 535 536 public function test_orderby_single_invalid() { 537 $q = new WP_Comment_Query(); 538 $q->query( array( 539 'orderby' => 'foo', 540 ) ); 541 542 $this->assertContains( 'ORDER BY comment_date_gmt', $q->request ); 543 } 544 545 public function test_orderby_comma_separated() { 546 $q = new WP_Comment_Query(); 547 $q->query( array( 548 'orderby' => 'comment_agent, comment_approved', 549 ) ); 550 551 $this->assertContains( 'ORDER BY comment_agent, comment_approved', $q->request ); 552 } 553 554 public function test_orderby_array() { 555 $q = new WP_Comment_Query(); 556 $q->query( array( 557 'orderby' => array( 'comment_agent', 'comment_approved' ), 558 ) ); 559 560 $this->assertContains( 'ORDER BY comment_agent, comment_approved', $q->request ); 561 } 562 563 public function test_orderby_array_contains_invalid_item() { 564 $q = new WP_Comment_Query(); 565 $q->query( array( 566 'orderby' => array( 'comment_agent', 'foo', 'comment_approved' ), 567 ) ); 568 569 $this->assertContains( 'ORDER BY comment_agent, comment_approved', $q->request ); 570 } 571 572 public function test_orderby_array_contains_all_invalid_items() { 573 $q = new WP_Comment_Query(); 574 $q->query( array( 575 'orderby' => array( 'foo', 'bar', 'baz' ), 576 ) ); 577 578 $this->assertContains( 'ORDER BY comment_date_gmt', $q->request ); 579 } 519 580 }
Note: See TracChangeset
for help on using the changeset viewer.