Changeset 1057 in tests
- Timestamp:
- 09/27/2012 09:53:44 PM (13 years ago)
- File:
-
- 1 edited
-
trunk/tests/comment/query.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/comment/query.php
r1056 r1057 34 34 $this->assertEquals( $comment_id, $result->comment_ID ); 35 35 } 36 37 function test_get_comments_for_post() { 38 $post_id = $this->factory->post->create(); 39 $this->factory->comment->create_post_comments( $post_id, 10 ); 40 $comments = get_comments( array( 'post_id' => $post_id ) ); 41 $this->assertEquals( 10, count( $comments ) ); 42 foreach ( $comments as $comment ) { 43 $this->assertEquals( $post_id, $comment->comment_post_ID ); 44 } 45 46 $post_id2 = $this->factory->post->create(); 47 $this->factory->comment->create_post_comments( $post_id2, 10 ); 48 $comments = get_comments( array( 'post_id' => $post_id2 ) ); 49 $this->assertEquals( 10, count( $comments ) ); 50 foreach ( $comments as $comment ) { 51 $this->assertEquals( $post_id2, $comment->comment_post_ID ); 52 } 53 54 $post_id3 = $this->factory->post->create(); 55 $this->factory->comment->create_post_comments( $post_id3, 10, array( 'comment_approved' => '0' ) ); 56 $comments = get_comments( array( 'post_id' => $post_id3 ) ); 57 $this->assertEquals( 10, count( $comments ) ); 58 foreach ( $comments as $comment ) { 59 $this->assertEquals( $post_id3, $comment->comment_post_ID ); 60 } 61 62 $comments = get_comments( array( 'post_id' => $post_id3, 'status' => 'hold' ) ); 63 $this->assertEquals( 10, count( $comments ) ); 64 foreach ( $comments as $comment ) { 65 $this->assertEquals( $post_id3, $comment->comment_post_ID ); 66 } 67 68 $comments = get_comments( array( 'post_id' => $post_id3, 'status' => 'approve' ) ); 69 $this->assertEquals( 0, count( $comments ) ); 70 71 $this->factory->comment->create_post_comments( $post_id3, 10, array( 'comment_approved' => '1' ) ); 72 $comments = get_comments( array( 'post_id' => $post_id3 ) ); 73 // $this->assertEquals( 20, count( $comments ) ); @todo Fix cache bug in WP_Comment_Query::query() 74 foreach ( $comments as $comment ) { 75 $this->assertEquals( $post_id3, $comment->comment_post_ID ); 76 } 77 } 78 79 /** 80 * @ticket 21003 81 */ 82 function test_orderby_meta() { 83 $comment_id = $this->factory->comment->create(); 84 $comment_id2 = $this->factory->comment->create(); 85 $comment_id3 = $this->factory->comment->create(); 86 87 add_comment_meta( $comment_id, 'key', 'value1', true ); 88 add_comment_meta( $comment_id, 'key1', 'value1', true ); 89 add_comment_meta( $comment_id, 'key3', 'value3', true ); 90 add_comment_meta( $comment_id2, 'key', 'value2', true ); 91 add_comment_meta( $comment_id2, 'key2', 'value2', true ); 92 add_comment_meta( $comment_id3, 'key3', 'value3', true ); 93 94 $comments = get_comments( array( 'meta_key' => 'key', 'orderby' => array( 'meta_value' ) ) ); 95 $this->assertEquals( 2, count( $comments ) ); 96 $this->assertEquals( $comment_id2, $comments[0]->comment_ID ); 97 $this->assertEquals( $comment_id, $comments[1]->comment_ID ); 98 99 $comments = get_comments( array( 'meta_key' => 'key', 'orderby' => array( 'meta_value' ), 'order' => 'ASC' ) ); 100 $this->assertEquals( 2, count( $comments ) ); 101 $this->assertEquals( $comment_id, $comments[0]->comment_ID ); 102 $this->assertEquals( $comment_id2, $comments[1]->comment_ID ); 103 104 $comments = get_comments( array( 'meta_value' => 'value3', 'orderby' => array( 'meta_value' ) ) ); 105 $this->assertEquals( 2, count( $comments ) ); 106 $this->assertEquals( $comment_id, $comments[0]->comment_ID ); 107 $this->assertEquals( $comment_id3, $comments[1]->comment_ID ); 108 109 // value1 is present on two different keys for $comment_id yet we should get only one instance 110 // of that comment in the results 111 $comments = get_comments( array( 'meta_value' => 'value1', 'orderby' => array( 'meta_value' ) ) ); 112 $this->assertEquals( 1, count( $comments ) ); 113 } 36 114 }
Note: See TracChangeset
for help on using the changeset viewer.