Changeset 34270 for trunk/tests/phpunit/tests/comment/metaCache.php
- Timestamp:
- 09/17/2015 08:00:31 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/comment/metaCache.php
r34268 r34270 82 82 } 83 83 84 public function test_comment_meta_cache() { 85 $post_id = $this->factory->post->create( array( 86 'post_status' => 'publish' 87 ) ); 84 /** 85 * @ticket 16894 86 */ 87 public function test_comment_meta_should_be_lazy_loaded_for_all_comments_in_comments_template() { 88 global $wpdb; 88 89 89 $comment_ids = $this->factory->comment->create_post_comments( $post_id, 10 ); 90 $p = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 91 $comment_ids = $this->factory->comment->create_post_comments( $p, 3 ); 90 92 91 93 foreach ( $comment_ids as $cid ) { … … 93 95 } 94 96 95 $ post = get_post( $post_id);97 $this->go_to( get_permalink( $p ) ); 96 98 97 $this->assertEquals( $post->comment_count, count( $comment_ids ) ); 99 if ( have_posts() ) { 100 while ( have_posts() ) { 101 the_post(); 98 102 99 $this->go_to( get_permalink( $post_id ) ); 103 // Load comments with `comments_template()`. 104 $cform = get_echo( 'comments_template' ); 100 105 101 $this->assertTrue( is_single() ); 102 $this->assertTrue( have_posts() ); 106 // First request will hit the database. 107 $num_queries = $wpdb->num_queries; 108 get_comment_meta( $comment_ids[0], 'sauce' ); 109 $this->assertSame( $num_queries + 1, $wpdb->num_queries ); 103 110 104 global $wp_query; 105 106 while ( have_posts() ) { 107 the_post(); 108 109 $comment_args = array( 110 'order' => 'ASC', 111 'orderby' => 'comment_date_gmt', 112 'status' => 'approve', 113 'post_id' => get_the_ID(), 114 ); 115 116 $comments = get_comments( $comment_args ); 117 118 // This is beyond awful 119 $wp_query->comments = $comments; 120 121 wp_list_comments( array( 122 'echo' => false, 123 'callback' => array( $this, '_comment_callback' ) 124 ) ); 111 // Second and third requests should be in cache. 112 get_comment_meta( $comment_ids[1], 'sauce' ); 113 get_comment_meta( $comment_ids[2], 'sauce' ); 114 $this->assertSame( $num_queries + 1, $wpdb->num_queries ); 115 } 125 116 } 126 117 } 127 128 public function _comment_callback( $comment ) {129 global $wpdb;130 131 get_comment_meta( $comment->comment_ID, 'sauce' );132 133 if ( 0 === $this->i ) {134 $this->queries = $wpdb->num_queries;135 } else {136 $this->assertEquals( $this->queries, $wpdb->num_queries );137 }138 139 $this->i++;140 }141 118 }
Note: See TracChangeset
for help on using the changeset viewer.