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