Add unit tests for WP_Comment_Query 'orderby' param.

For better testability, the SQL string generated in `WP_Comment_Query::get_posts()`
is now stored as a 'request' property on the object.

See #29902.

git-svn-id: https://develop.svn.wordpress.org/trunk@30003 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2014-10-24 02:33:46 +00:00
parent 1880bf988c
commit ce810ba5b3
2 changed files with 75 additions and 4 deletions

View File

@@ -221,6 +221,15 @@ function get_comments( $args = '' ) {
* @since 3.1.0
*/
class WP_Comment_Query {
/**
* SQL for database query.
*
* @since 4.0.1
* @access public
* @var string
*/
public $request;
/**
* Metadata query container
*
@@ -578,18 +587,19 @@ class WP_Comment_Query {
if ( $groupby ) {
$groupby = 'GROUP BY ' . $groupby;
}
$query = "SELECT $fields FROM $wpdb->comments $join WHERE $where $groupby ORDER BY $orderby $order $limits";
$this->request = "SELECT $fields FROM $wpdb->comments $join WHERE $where $groupby $orderby $order $limits";
if ( $this->query_vars['count'] ) {
return $wpdb->get_var( $query );
return $wpdb->get_var( $this->request );
}
if ( 'ids' == $this->query_vars['fields'] ) {
$this->comments = $wpdb->get_col( $query );
$this->comments = $wpdb->get_col( $this->request );
return array_map( 'intval', $this->comments );
}
$results = $wpdb->get_results( $query );
$results = $wpdb->get_results( $this->request );
/**
* Filter the comment query results.
*