| | 1 | <?php |
| | 2 | |
| | 3 | class Tests_List_Categories extends WP_UnitTestCase { |
| | 4 | |
| | 5 | protected $parent_id; |
| | 6 | protected $news_id; |
| | 7 | |
| | 8 | function setup() { |
| | 9 | parent::setUp(); |
| | 10 | $this->parent_id = $this->factory->category->create( array( 'name' => 'Parent', 'slug' => 'parent' ) ); |
| | 11 | $this->news_id = $this->factory->category->create( array( 'name' => 'News', 'slug' => 'news' ) ); |
| | 12 | |
| | 13 | } |
| | 14 | |
| | 15 | function test_wp_list_categories_default() { |
| | 16 | $args = array( 'echo'=> 0, 'hide_empty' => 0 ); |
| | 17 | $expected = '<li class="categories">Categories<ul> <li class="cat-item cat-item-' . $this->news_id . '"><a href="' . get_category_link( $this->news_id ) . '" title="Term description 2">News</a> |
| | 18 | </li> |
| | 19 | <li class="cat-item cat-item-' . $this->parent_id . '"><a href="' . get_category_link( $this->parent_id ) . '" title="Term description 1">Parent</a> |
| | 20 | </li> |
| | 21 | <li class="cat-item cat-item-1"><a href="' . get_category_link( 1 ) . '" title="View all posts filed under Uncategorized">Uncategorized</a> |
| | 22 | </li> |
| | 23 | </ul></li>'; |
| | 24 | $actual = wp_list_categories( $args ); |
| | 25 | $this->AssertEquals( $expected, $actual ); |
| | 26 | } |
| | 27 | |
| | 28 | function test_wp_list_categories_show_option_all() { |
| | 29 | $args = array( 'echo'=> 0, 'hide_empty' => 0, 'show_option_all' => "All Categories" ); |
| | 30 | $expected = '<li class="categories">Categories<ul><li class=\'cat-item-all\'><a href=\'http://example.org/\'>All Categories</a></li> <li class="cat-item cat-item-' . $this->news_id . '"><a href="' . get_category_link( $this->news_id ) . '" title="Term description 2">News</a> |
| | 31 | </li> |
| | 32 | <li class="cat-item cat-item-' . $this->parent_id . '"><a href="' . get_category_link( $this->parent_id ) . '" title="Term description 1">Parent</a> |
| | 33 | </li> |
| | 34 | <li class="cat-item cat-item-1"><a href="' . get_category_link( 1 ) . '" title="View all posts filed under Uncategorized">Uncategorized</a> |
| | 35 | </li> |
| | 36 | </ul></li>'; |
| | 37 | $actual = wp_list_categories( $args ); |
| | 38 | $this->AssertEquals( $expected, $actual ); |
| | 39 | } |
| | 40 | |
| | 41 | function test_wp_list_categories_show_option_none() { |
| | 42 | $args = array( 'echo'=> 0, 'show_option_none' => 'Nothing Found...' ); |
| | 43 | $expected = '<li class="categories">Categories<ul><li class="cat-item-none">Nothing Found...</li></ul></li>'; |
| | 44 | $actual = wp_list_categories( $args ); |
| | 45 | $this->AssertEquals( $expected, $actual ); |
| | 46 | } |
| | 47 | |
| | 48 | function test_wp_list_categories_orderby() { |
| | 49 | $args = array( 'echo'=> 0, 'hide_empty' => 0, 'orderby' => 'ID' ); |
| | 50 | $expected = '<li class="categories">Categories<ul> <li class="cat-item cat-item-1"><a href="' . get_category_link( 1 ) . '" title="View all posts filed under Uncategorized">Uncategorized</a> |
| | 51 | </li> |
| | 52 | <li class="cat-item cat-item-' . $this->parent_id . '"><a href="' . get_category_link( $this->parent_id ) . '" title="Term description 1">Parent</a> |
| | 53 | </li> |
| | 54 | <li class="cat-item cat-item-' . $this->news_id . '"><a href="' . get_category_link( $this->news_id ) . '" title="Term description 2">News</a> |
| | 55 | </li> |
| | 56 | </ul></li>'; |
| | 57 | $actual = wp_list_categories( $args ); |
| | 58 | $this->AssertEquals( $expected, $actual ); |
| | 59 | } |
| | 60 | |
| | 61 | function test_wp_list_categories_order() { |
| | 62 | $args = array( 'echo'=> 0, 'hide_empty' => 0, 'orderby' => 'ID', 'order' => 'DESC' ); |
| | 63 | $expected = '<li class="categories">Categories<ul> <li class="cat-item cat-item-' . $this->news_id . '"><a href="' . get_category_link( $this->news_id ) . '" title="Term description 2">News</a> |
| | 64 | </li> |
| | 65 | <li class="cat-item cat-item-' . $this->parent_id . '"><a href="' . get_category_link( $this->parent_id ) . '" title="Term description 1">Parent</a> |
| | 66 | </li> |
| | 67 | <li class="cat-item cat-item-1"><a href="' . get_category_link( 1 ) . '" title="View all posts filed under Uncategorized">Uncategorized</a> |
| | 68 | </li> |
| | 69 | </ul></li>'; |
| | 70 | $actual = wp_list_categories( $args ); |
| | 71 | $this->AssertEquals( $expected, $actual ); |
| | 72 | } |
| | 73 | |
| | 74 | function test_wp_list_categories_style() { |
| | 75 | $args = array( 'echo'=> 0, 'hide_empty' => 0, 'style' => 'none' ); |
| | 76 | $expected = ' <a href="' . get_category_link( $this->news_id ) . '" title="Term description 2">News</a><br /> |
| | 77 | <a href="' . get_category_link( $this->parent_id ) . '" title="Term description 1">Parent</a><br /> |
| | 78 | <a href="' . get_category_link( 1 ) . '" title="View all posts filed under Uncategorized">Uncategorized</a><br /> |
| | 79 | '; |
| | 80 | $actual = wp_list_categories( $args ); |
| | 81 | $this->AssertEquals( $expected, $actual ); |
| | 82 | } |
| | 83 | |
| | 84 | function test_wp_list_categories_show_count() { |
| | 85 | $args = array( 'echo'=> 0, 'hide_empty' => 0, 'show_count' => 1 ); |
| | 86 | $expected = '<li class="categories">Categories<ul> <li class="cat-item cat-item-' . $this->news_id . '"><a href="' . get_category_link( $this->news_id ) . '" title="Term description 2">News</a> (0) |
| | 87 | </li> |
| | 88 | <li class="cat-item cat-item-' . $this->parent_id . '"><a href="' . get_category_link( $this->parent_id ) . '" title="Term description 1">Parent</a> (0) |
| | 89 | </li> |
| | 90 | <li class="cat-item cat-item-1"><a href="' . get_category_link( 1 ) . '" title="View all posts filed under Uncategorized">Uncategorized</a> (0) |
| | 91 | </li> |
| | 92 | </ul></li>'; |
| | 93 | $actual = wp_list_categories( $args ); |
| | 94 | $this->AssertEquals( $expected, $actual ); |
| | 95 | } |
| | 96 | |
| | 97 | function test_wp_list_categories_hide_empty() { |
| | 98 | $args = array( 'echo'=> 0, 'hide_empty' => 1 ); |
| | 99 | $expected = '<li class="categories">Categories<ul><li class="cat-item-none">No categories</li></ul></li>'; |
| | 100 | $actual = wp_list_categories( $args ); |
| | 101 | $this->AssertEquals( $expected, $actual ); |
| | 102 | } |
| | 103 | |
| | 104 | function test_wp_list_categories_use_desc_for_title() { |
| | 105 | $args = array( 'echo'=> 0, 'hide_empty' => 0, 'use_desc_for_title' => 0 ); |
| | 106 | $expected = '<li class="categories">Categories<ul> <li class="cat-item cat-item-' . $this->news_id . '"><a href="' . get_category_link( $this->news_id ) . '" title="View all posts filed under News">News</a> |
| | 107 | </li> |
| | 108 | <li class="cat-item cat-item-' . $this->parent_id . '"><a href="' . get_category_link( $this->parent_id ) . '" title="View all posts filed under Parent">Parent</a> |
| | 109 | </li> |
| | 110 | <li class="cat-item cat-item-1"><a href="' . get_category_link( 1 ) . '" title="View all posts filed under Uncategorized">Uncategorized</a> |
| | 111 | </li> |
| | 112 | </ul></li>'; |
| | 113 | $actual = wp_list_categories( $args ); |
| | 114 | $this->AssertEquals( $expected, $actual ); |
| | 115 | } |
| | 116 | |
| | 117 | function test_wp_list_categories_child_of() { |
| | 118 | $child_id = $this->factory->category->create( array( 'name' => 'Child', 'slug' => 'child', 'parent' => $this->parent_id ) ); |
| | 119 | $args = array( 'echo'=> 0, 'hide_empty' => 0, 'child_of' => $this->parent_id ); |
| | 120 | $expected = '<li class="categories">Categories<ul> <li class="cat-item cat-item-' . $child_id . '"><a href="' . get_category_link( $child_id ) . '" title="Term description 3">Child</a> |
| | 121 | </li> |
| | 122 | </ul></li>'; |
| | 123 | $actual = wp_list_categories( $args ); |
| | 124 | $this->AssertEquals( $expected, $actual ); |
| | 125 | } |
| | 126 | |
| | 127 | function test_wp_list_categories_feed() { |
| | 128 | $args = array( 'echo'=> 0, 'hide_empty' => 0, 'feed' => 'Feed' ); |
| | 129 | $expected = '<li class="categories">Categories<ul> <li class="cat-item cat-item-' . $this->news_id . '"><a href="' . get_category_link( $this->news_id ) . '" title="Term description 2">News</a> (<a href="http://example.org/?feed=rss2&cat=' . $this->news_id . '" title="Feed">Feed</a>) |
| | 130 | </li> |
| | 131 | <li class="cat-item cat-item-' . $this->parent_id . '"><a href="' . get_category_link( $this->parent_id ) . '" title="Term description 1">Parent</a> (<a href="http://example.org/?feed=rss2&cat=' . $this->parent_id . '" title="Feed">Feed</a>) |
| | 132 | </li> |
| | 133 | <li class="cat-item cat-item-1"><a href="' . get_category_link( 1 ) . '" title="View all posts filed under Uncategorized">Uncategorized</a> (<a href="http://example.org/?feed=rss2&cat=1" title="Feed">Feed</a>) |
| | 134 | </li> |
| | 135 | </ul></li>'; |
| | 136 | $actual = wp_list_categories( $args ); |
| | 137 | $this->AssertEquals( $expected, $actual ); |
| | 138 | } |
| | 139 | |
| | 140 | function test_wp_list_categories_feed_type() { |
| | 141 | $args = array( 'echo'=> 0, 'hide_empty' => 0, 'feed' => 'Feed', 'feed_type' => 'rss' ); |
| | 142 | $expected = '<li class="categories">Categories<ul> <li class="cat-item cat-item-' . $this->news_id . '"><a href="' . get_category_link( $this->news_id ) . '" title="Term description 2">News</a> (<a href="http://example.org/?feed=rss&cat=' . $this->news_id . '" title="Feed">Feed</a>) |
| | 143 | </li> |
| | 144 | <li class="cat-item cat-item-' . $this->parent_id . '"><a href="' . get_category_link( $this->parent_id ) . '" title="Term description 1">Parent</a> (<a href="http://example.org/?feed=rss&cat=' . $this->parent_id . '" title="Feed">Feed</a>) |
| | 145 | </li> |
| | 146 | <li class="cat-item cat-item-1"><a href="' . get_category_link( 1 ) . '" title="View all posts filed under Uncategorized">Uncategorized</a> (<a href="http://example.org/?feed=rss&cat=1" title="Feed">Feed</a>) |
| | 147 | </li> |
| | 148 | </ul></li>'; |
| | 149 | $actual = wp_list_categories( $args ); |
| | 150 | $this->AssertEquals( $expected, $actual ); |
| | 151 | } |
| | 152 | |
| | 153 | function test_wp_list_categories_feed_image() { |
| | 154 | $args = array( 'echo' => 0, 'hide_empty' => 0, 'feed_image' => 'http://domain.com/feed-image.png', 'feed' => 'rss' ); |
| | 155 | $expected = '<li class="categories">Categories<ul> <li class="cat-item cat-item-' . $this->news_id . '"><a href="' . get_category_link( $this->news_id ) . '" title="Term description 2">News</a> <a href="http://example.org/?feed=rss2&cat=' . $this->news_id . '" title="rss"><img src=\'http://domain.com/feed-image.png\' alt="rss" title="rss" /></a> |
| | 156 | </li> |
| | 157 | <li class="cat-item cat-item-' . $this->parent_id . '"><a href="' . get_category_link( $this->parent_id ) . '" title="Term description 1">Parent</a> <a href="http://example.org/?feed=rss2&cat=' . $this->parent_id . '" title="rss"><img src=\'http://domain.com/feed-image.png\' alt="rss" title="rss" /></a> |
| | 158 | </li> |
| | 159 | <li class="cat-item cat-item-1"><a href="' . get_category_link( 1 ) . '" title="View all posts filed under Uncategorized">Uncategorized</a> <a href="http://example.org/?feed=rss2&cat=1" title="rss"><img src=\'http://domain.com/feed-image.png\' alt="rss" title="rss" /></a> |
| | 160 | </li> |
| | 161 | </ul></li>'; |
| | 162 | $actual = wp_list_categories( $args ); |
| | 163 | $this->AssertEquals( $expected, $actual ); |
| | 164 | } |
| | 165 | |
| | 166 | function test_wp_list_categories_exclude() { |
| | 167 | $args = array( 'echo' => 0, 'hide_empty' => 0, 'exclude' => $this->parent_id ); |
| | 168 | $expected = '<li class="categories">Categories<ul> <li class="cat-item cat-item-' . $this->news_id . '"><a href="' . get_category_link( $this->news_id ) . '" title="Term description 2">News</a> |
| | 169 | </li> |
| | 170 | <li class="cat-item cat-item-1"><a href="' . get_category_link( 1 ) . '" title="View all posts filed under Uncategorized">Uncategorized</a> |
| | 171 | </li> |
| | 172 | </ul></li>'; |
| | 173 | $actual = wp_list_categories( $args ); |
| | 174 | $this->AssertEquals( $expected, $actual ); |
| | 175 | } |
| | 176 | |
| | 177 | /** |
| | 178 | * @ticket 12981 |
| | 179 | */ |
| | 180 | |
| | 181 | function test_wp_list_categories_exclude_tree() { |
| | 182 | $child_id = $this->factory->category->create( array( 'name' => 'Child', 'slug' => 'child', 'parent' => $this->parent_id ) ); |
| | 183 | $args = array( 'echo' => 0, 'hide_empty' => 0, 'exclude_tree' => $this->parent_id ); |
| | 184 | $expected = '<li class="categories">Categories<ul> <li class="cat-item cat-item-' . $this->news_id . '"><a href="' . get_category_link( $this->news_id ) . '" title="Term description 2">News</a> |
| | 185 | </li> |
| | 186 | <li class="cat-item cat-item-1"><a href="' . get_category_link( 1 ) . '" title="View all posts filed under Uncategorized">Uncategorized</a> |
| | 187 | </li> |
| | 188 | </ul></li>'; |
| | 189 | $actual = wp_list_categories( $args ); |
| | 190 | $this->AssertEquals( $expected, $actual ); |
| | 191 | } |
| | 192 | |
| | 193 | function test_wp_list_categories_current_category() { |
| | 194 | $args = array( 'echo' => 0, 'hide_empty' => 0, 'current_category' => $this->parent_id ); |
| | 195 | $expected = '<li class="categories">Categories<ul> <li class="cat-item cat-item-' . $this->news_id . '"><a href="' . get_category_link( $this->news_id ) . '" title="Term description 2">News</a> |
| | 196 | </li> |
| | 197 | <li class="cat-item cat-item-' . $this->parent_id . ' current-cat"><a href="' . get_category_link( $this->parent_id ) . '" title="Term description 1">Parent</a> |
| | 198 | </li> |
| | 199 | <li class="cat-item cat-item-1"><a href="' . get_category_link( 1 ) . '" title="View all posts filed under Uncategorized">Uncategorized</a> |
| | 200 | </li> |
| | 201 | </ul></li>'; |
| | 202 | $actual = wp_list_categories( $args ); |
| | 203 | $this->AssertEquals( $expected, $actual ); |
| | 204 | } |
| | 205 | |
| | 206 | function test_wp_list_categories_hierarchical() { |
| | 207 | $child_id = $this->factory->category->create( array( 'name' => 'Child', 'slug' => 'child', 'parent' => 36 ) ); |
| | 208 | $args = array( 'echo'=> 0, 'hide_empty' => 0, 'hierarchical' => 0 ); |
| | 209 | $expected = '<li class="categories">Categories<ul> <li class="cat-item cat-item-' . $child_id . '"><a href="' . get_category_link( $child_id ) . '" title="Term description 3">Child</a> |
| | 210 | </li> |
| | 211 | <li class="cat-item cat-item-' . $this->news_id . '"><a href="' . get_category_link( $this->news_id ) . '" title="Term description 2">News</a> |
| | 212 | </li> |
| | 213 | <li class="cat-item cat-item-' . $this->parent_id . '"><a href="' . get_category_link( $this->parent_id ) . '" title="Term description 1">Parent</a> |
| | 214 | </li> |
| | 215 | <li class="cat-item cat-item-1"><a href="' . get_category_link( 1 ) . '" title="View all posts filed under Uncategorized">Uncategorized</a> |
| | 216 | </li> |
| | 217 | </ul></li>'; |
| | 218 | $actual = wp_list_categories( $args ); |
| | 219 | $this->AssertEquals( $expected, $actual ); |
| | 220 | } |
| | 221 | |
| | 222 | function test_wp_list_categories_title_li() { |
| | 223 | $args = array( 'echo'=> 0, 'hide_empty' => 0, 'title_li' => 'My Categories' ); |
| | 224 | $expected = '<li class="categories">My Categories<ul> <li class="cat-item cat-item-' . $this->news_id . '"><a href="' . get_category_link( $this->news_id ) . '" title="Term description 2">News</a> |
| | 225 | </li> |
| | 226 | <li class="cat-item cat-item-' . $this->parent_id . '"><a href="' . get_category_link( $this->parent_id ) . '" title="Term description 1">Parent</a> |
| | 227 | </li> |
| | 228 | <li class="cat-item cat-item-1"><a href="' . get_category_link( 1 ) . '" title="View all posts filed under Uncategorized">Uncategorized</a> |
| | 229 | </li> |
| | 230 | </ul></li>'; |
| | 231 | $actual = wp_list_categories( $args ); |
| | 232 | $this->AssertEquals( $expected, $actual ); |
| | 233 | } |
| | 234 | |
| | 235 | function test_wp_list_categories_echo() { |
| | 236 | $args = array( 'echo'=> 1 ); |
| | 237 | $expected = '<li class="categories">Categories<ul><li class="cat-item-none">No categories</li></ul></li>'; |
| | 238 | ob_start(); |
| | 239 | wp_list_categories( $args ); |
| | 240 | $actual = ob_get_clean(); |
| | 241 | $this->AssertEquals( $expected, $actual ); |
| | 242 | } |
| | 243 | |
| | 244 | function test_wp_list_categories_depth() { |
| | 245 | $child_id = $this->factory->category->create( array( 'name' => 'Child', 'slug' => 'child', 'parent' => $this->parent_id ) ); |
| | 246 | $args = array( 'echo'=> 0, 'hide_empty' => 0, 'depth' => 1 ); |
| | 247 | $expected = '<li class="categories">Categories<ul> <li class="cat-item cat-item-' . $this->news_id . '"><a href="' . get_category_link( $this->news_id ) . '" title="Term description 2">News</a> |
| | 248 | </li> |
| | 249 | <li class="cat-item cat-item-' . $this->parent_id . '"><a href="' . get_category_link( $this->parent_id ) . '" title="Term description 1">Parent</a> |
| | 250 | </li> |
| | 251 | <li class="cat-item cat-item-1"><a href="' . get_category_link( 1 ) . '" title="View all posts filed under Uncategorized">Uncategorized</a> |
| | 252 | </li> |
| | 253 | </ul></li>'; |
| | 254 | $actual = wp_list_categories( $args ); |
| | 255 | $this->AssertEquals( $expected, $actual ); |
| | 256 | } |
| | 257 | |
| | 258 | } |