Changeset 35225 for trunk/tests/phpunit/tests/term/wpGenerateTagCloud.php
- Timestamp:
- 10/16/2015 09:04:12 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term/wpGenerateTagCloud.php
r34519 r35225 4 4 */ 5 5 class Tests_WP_Generate_Tag_Cloud extends WP_UnitTestCase { 6 protected $terms = array(); 7 6 8 /** 7 9 * Testing when passed $tags array is empty … … 26 28 */ 27 29 function test_empty_tags_list_returned( $expected, $args ) { 28 $this->factory->term->create_many( 4, array( 'taxonomy' => 'post_tag' ) ); 30 $term_ids = self::$factory->term->create_many( 4, array( 'taxonomy' => 'post_tag' ) ); 31 $this->terms = array(); 32 foreach ( $term_ids as $term_id ) { 33 $this->terms[] = get_term( $term_id, 'post_tag' ); 34 } 29 35 $tags = $this->retrieve_terms( array( 'number' => 4 ) ); 30 36 $this->assertSame( $expected, wp_generate_tag_cloud( $tags, $args ) ); … … 65 71 } 66 72 67 68 /** 69 * Testing the various output for a single link 70 * in various formats 71 * 72 * @dataProvider single_link_data_provider 73 * 74 * @param int $create How many tags to create. 75 * @param array $get_terms_args What args we want to pass to retreve terms. 76 * @param mixed $expected Expected output from `wp_generate_tag_cloud()`. 77 * @param array $args Options for `wp_generate_tag_cloud()`. 78 * 79 */ 80 function test_wp_generate_tag_cloud( $create, $get_terms_args, $expected, $args ) { 81 $this->factory->term->create_many( $create, array( 'taxonomy' => 'post_tag' ) ); 82 $tags = $this->retrieve_terms( $get_terms_args ); 83 84 $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, $args ) ); 85 } 86 87 88 function single_link_data_provider() { 89 return array( 90 array( 91 1, 92 array( 93 'number' => 1, 94 'hide_empty' => false, 95 ), 96 "<a href='http://" . WP_TESTS_DOMAIN . "/?tag=term-1' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>Term 1</a>", 97 array( 98 'hide_empty' => false, 99 ), 100 ), 101 102 // Should return an array of links. 103 array( 104 1, 105 array( 106 'number' => 1, 107 'hide_empty' => false, 108 ), 109 array( 110 "<a href='http://" . WP_TESTS_DOMAIN . "/?tag=term-1' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>Term 1</a>", 111 ), 112 array( 113 'hide_empty' => false, 114 'format' => 'array', 115 ), 116 ), 117 118 // Should return a string containing a <ul> list of links. 119 array( 120 1, 121 array( 122 'number' => 1, 123 'hide_empty' => false, 124 ), 125 "<ul class='wp-tag-cloud'>\n\t<li><a href='http://" . WP_TESTS_DOMAIN . "/?tag=term-1' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>Term 1</a></li>\n</ul>\n", 126 array( 127 'hide_empty' => false, 128 'format' => 'list', 129 ), 130 ), 131 132 array( 133 4, 134 array( 135 'number' => 4, 136 'hide_empty' => false, 137 ), 138 "<a href='http://" . WP_TESTS_DOMAIN . "/?tag=term-1' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>Term 1</a>\n". 139 "<a href='http://" . WP_TESTS_DOMAIN . "/?tag=term-2' class='tag-link-1' title='0 topics' style='font-size: 8pt;'>Term 2</a>\n". 140 "<a href='http://" . WP_TESTS_DOMAIN . "/?tag=term-3' class='tag-link-2' title='0 topics' style='font-size: 8pt;'>Term 3</a>\n". 141 "<a href='http://" . WP_TESTS_DOMAIN . "/?tag=term-4' class='tag-link-3' title='0 topics' style='font-size: 8pt;'>Term 4</a>", 142 array( 143 'hide_empty' => false, 144 ), 145 ), 146 147 array( 148 4, 149 array( 150 'number' => 4, 151 'hide_empty' => false, 152 ), 153 "<ul class='wp-tag-cloud'>\n\t<li>". 154 "<a href='http://" . WP_TESTS_DOMAIN . "/?tag=term-1' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>Term 1</a></li>\n\t<li>". 155 "<a href='http://" . WP_TESTS_DOMAIN . "/?tag=term-2' class='tag-link-1' title='0 topics' style='font-size: 8pt;'>Term 2</a></li>\n\t<li>". 156 "<a href='http://" . WP_TESTS_DOMAIN . "/?tag=term-3' class='tag-link-2' title='0 topics' style='font-size: 8pt;'>Term 3</a></li>\n\t<li>". 157 "<a href='http://" . WP_TESTS_DOMAIN . "/?tag=term-4' class='tag-link-3' title='0 topics' style='font-size: 8pt;'>Term 4</a>". 158 "</li>\n</ul>\n", 159 array( 160 'hide_empty' => false, 161 'format' => 'list', 162 ), 163 ), 164 ); 73 function test_hide_empty_false() { 74 $term_id = self::$factory->tag->create(); 75 $term = get_term( $term_id, 'post_tag' ); 76 77 $tags = $this->retrieve_terms( array( 78 'number' => 1, 79 'hide_empty' => false, 80 ) ); 81 $expected = "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$term->slug}' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>{$term->name}</a>"; 82 $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array( 83 'hide_empty' => false, 84 ) ) ); 85 } 86 87 function test_hide_empty_false_format_array() { 88 $term_id = self::$factory->tag->create(); 89 $term = get_term( $term_id, 'post_tag' ); 90 91 $tags = $this->retrieve_terms( array( 92 'number' => 1, 93 'hide_empty' => false, 94 'format' => 'array', 95 ) ); 96 97 $expected = "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$term->slug}' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>{$term->name}</a>"; 98 $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array( 99 'hide_empty' => false, 100 ) ) ); 101 } 102 103 function test_hide_empty_false_format_list() { 104 $term_id = self::$factory->tag->create(); 105 $term = get_term( $term_id, 'post_tag' ); 106 107 $tags = $this->retrieve_terms( array( 108 'number' => 1, 109 'hide_empty' => false, 110 ) ); 111 112 $expected = "<ul class='wp-tag-cloud'>\n\t<li><a href='http://" . WP_TESTS_DOMAIN . "/?tag={$term->slug}' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>{$term->name}</a></li>\n</ul>\n"; 113 $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array( 114 'hide_empty' => false, 115 'format' => 'list', 116 ) ) ); 117 } 118 119 function test_hide_empty_false_multi() { 120 $term_ids = self::$factory->tag->create_many( 4 ); 121 $terms = array(); 122 foreach ( $term_ids as $term_id ) { 123 $terms[] = get_term( $term_id, 'post_tag' ); 124 } 125 126 $tags = $this->retrieve_terms( array( 127 'number' => 4, 128 'order' => 'id', 129 'hide_empty' => false, 130 ) ); 131 132 $expected = "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[0]->slug}' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>{$terms[0]->name}</a>\n". 133 "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[1]->slug}' class='tag-link-1' title='0 topics' style='font-size: 8pt;'>{$terms[1]->name}</a>\n". 134 "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[2]->slug}' class='tag-link-2' title='0 topics' style='font-size: 8pt;'>{$terms[2]->name}</a>\n". 135 "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[3]->slug}' class='tag-link-3' title='0 topics' style='font-size: 8pt;'>{$terms[3]->name}</a>"; 136 $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array( 137 'hide_empty' => false, 138 ) ) ); 139 } 140 141 function test_hide_empty_false_multi_format_list() { 142 $term_ids = self::$factory->tag->create_many( 4 ); 143 $terms = array(); 144 foreach ( $term_ids as $term_id ) { 145 $terms[] = get_term( $term_id, 'post_tag' ); 146 } 147 148 $tags = $this->retrieve_terms( array( 149 'number' => 4, 150 'orderby' => 'id', 151 'hide_empty' => false, 152 ) ); 153 154 $expected = "<ul class='wp-tag-cloud'>\n\t<li>". 155 "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[0]->slug}' class='tag-link-0' title='0 topics' style='font-size: 8pt;'>{$terms[0]->name}</a></li>\n\t<li>". 156 "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[1]->slug}' class='tag-link-1' title='0 topics' style='font-size: 8pt;'>{$terms[1]->name}</a></li>\n\t<li>". 157 "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[2]->slug}' class='tag-link-2' title='0 topics' style='font-size: 8pt;'>{$terms[2]->name}</a></li>\n\t<li>". 158 "<a href='http://" . WP_TESTS_DOMAIN . "/?tag={$terms[3]->slug}' class='tag-link-3' title='0 topics' style='font-size: 8pt;'>{$terms[3]->name}</a>". 159 "</li>\n</ul>\n"; 160 161 $this->assertEquals( $expected, wp_generate_tag_cloud( $tags, array( 162 'hide_empty' => false, 163 'format' => 'list', 164 ) ) ); 165 165 } 166 166 167 167 public function test_topic_count_text() { 168 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' ); 169 $term_ids = self::$factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) ); 170 $this->terms = array(); 171 foreach ( $term_ids as $term_id ) { 172 $this->terms[] = get_term( $term_id, 'post_tag' ); 173 } 174 $posts = self::$factory->post->create_many( 2 ); 175 176 wp_set_post_terms( $posts[0], $term_ids, 'wptests_tax' ); 177 wp_set_post_terms( $posts[1], array( $term_ids[1] ), 'wptests_tax' ); 174 178 175 179 $term_objects = $this->retrieve_terms( array( 176 'include' => $term s,180 'include' => $term_ids, 177 181 ), 'wptests_tax' ); 178 182 … … 193 197 public function test_topic_count_text_callback() { 194 198 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' ); 199 $term_ids = self::$factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) ); 200 $this->terms = array(); 201 foreach ( $term_ids as $term_id ) { 202 $this->terms[] = get_term( $term_id, 'post_tag' ); 203 } 204 $posts = self::$factory->post->create_many( 2 ); 205 206 wp_set_post_terms( $posts[0], $term_ids, 'wptests_tax' ); 207 wp_set_post_terms( $posts[1], array( $term_ids[1] ), 'wptests_tax' ); 200 208 201 209 $term_objects = $this->retrieve_terms( array( 202 'include' => $term s,210 'include' => $term_ids, 203 211 ), 'wptests_tax' ); 204 212
Note: See TracChangeset
for help on using the changeset viewer.