Permalink
Browse files

Add `WPCOM_Liveblog_Entry_Query::count()` method

  • Loading branch information...
1 parent 88dbc03 commit 79c0e3cfc1dcbcfbbda0386f0ac30674444e7f38 @nb nb committed Jan 18, 2014
Showing with 20 additions and 0 deletions.
  1. +4 −0 classes/class-wpcom-liveblog-entry-query.php
  2. +16 −0 t/test-entry-query.php
@@ -43,6 +43,10 @@ public function get_all( $args = array() ) {
return self::remove_replaced_entries( $this->get( $args ) );
}
+ public function count( $args = array() ) {
+ return count( $this->get_all( $args ) );
+ }
+
public function get_by_id( $id ) {
$comment = get_comment( $id );
if ( $comment->comment_post_ID != $this->post_id || $comment->comment_type != $this->key || $comment->comment_approved != $this->key) {
View
@@ -102,6 +102,22 @@ function test_has_any_returns_true_if_we_add_some_entries() {
$this->assertTrue( $this->entry_query->has_any() );
}
+ function test_count_counts_all_entries() {
+ $this->create_comment();
+ $this->create_comment();
+ $this->assertEquals( 2, $this->entry_query->count() );
+ }
+
+ function test_count_returns_0_on_no_entries() {
+ $this->assertEquals( 0, $this->entry_query->count() );
+ }
+
+ function test_count_honors_the_query_args() {
+ $this->create_comment( array( 'comment_author_email' => 'baba@example.org' ) );
+ $this->create_comment( array( 'comment_author_email' => 'dyado@example.org' ) );
+ $this->assertEquals( 1, $this->entry_query->count( array( 'author_email' => 'baba@example.org' ) ) );
+ }
+
private function create_comment( $args = array() ) {
$defaults = array(
'comment_post_ID' => $this->entry_query->post_id,

0 comments on commit 79c0e3c

Please sign in to comment.