Changeset 32996 for trunk/tests/phpunit/tests/term/wpGenerateTagCloud.php
- Timestamp:
- 06/29/2015 02:15:59 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term/wpGenerateTagCloud.php
r32995 r32996 165 165 } 166 166 167 167 public function test_topic_count_text() { 168 register_taxonomy( 'wptests_tax', 'post' ); 169 $terms = $this->factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) ); 170 $posts = $this->factory->post->create_many( 2 ); 171 172 wp_set_post_terms( $posts[0], $terms, 'wptests_tax' ); 173 wp_set_post_terms( $posts[1], array( $terms[1] ), 'wptests_tax' ); 174 175 $term_objects = $this->retrieve_terms( array( 176 'include' => $terms, 177 ), 'wptests_tax' ); 178 179 $actual = wp_generate_tag_cloud( $term_objects, array( 180 'format' => 'array', 181 'topic_count_text' => array( 182 'singular' => 'Term has %s post', 183 'plural' => 'Term has %s posts', 184 'domain' => 'foo', 185 'context' => 'bar', 186 ), 187 ) ); 188 189 $this->assertContains( "title='Term has 1 post'", $actual[0] ); 190 $this->assertContains( "title='Term has 2 posts'", $actual[1] ); 191 } 192 193 public function test_topic_count_text_callback() { 194 register_taxonomy( 'wptests_tax', 'post' ); 195 $terms = $this->factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) ); 196 $posts = $this->factory->post->create_many( 2 ); 197 198 wp_set_post_terms( $posts[0], $terms, 'wptests_tax' ); 199 wp_set_post_terms( $posts[1], array( $terms[1] ), 'wptests_tax' ); 200 201 $term_objects = $this->retrieve_terms( array( 202 'include' => $terms, 203 ), 'wptests_tax' ); 204 205 $actual = wp_generate_tag_cloud( $term_objects, array( 206 'format' => 'array', 207 'topic_count_text_callback' => array( $this, 'topic_count_text_callback' ), 208 ) ); 209 210 $this->assertContains( "title='1 foo'", $actual[0] ); 211 $this->assertContains( "title='2 foo'", $actual[1] ); 212 } 168 213 169 214 /** … … 176 221 * @return array 177 222 */ 178 protected function retrieve_terms( $get_terms_args ) { 179 180 $terms = get_terms( array( 'post_tag' ), $get_terms_args ); 223 protected function retrieve_terms( $get_terms_args, $taxonomy = 'post_tag' ) { 224 $terms = get_terms( array( $taxonomy ), $get_terms_args ); 181 225 182 226 $tags = array(); … … 190 234 return $tags; 191 235 } 236 237 public function topic_count_text_callback( $real_count, $tag, $args ) { 238 return sprintf( '%s foo', $real_count ); 239 } 192 240 }
Note: See TracChangeset
for help on using the changeset viewer.