- Timestamp:
- 05/19/2016 02:22:59 AM (9 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/category/wpDropdownCategories.php
r37463 r37464 1 1 <?php 2 2 /** 3 * Validate Category API 4 * 5 * Notes: 6 * cat_is_ancestor_of is validated under test\term\term_is_ancestor_of 7 * 3 * @group taxonomy 8 4 * @group category.php 9 5 */ 10 class Tests_Category extends WP_UnitTestCase { 11 12 function tearDown() { 13 _unregister_taxonomy( 'test_tax_cat' ); 14 parent::tearDown(); 15 } 16 17 /** 18 * Validate get_all_category_ids 19 * 20 * @expectedDeprecated get_all_category_ids 21 */ 22 function test_get_all_category_ids() { 23 // create categories 24 self::factory()->category->create_many( 2 ); 25 26 // create new taxonomy to ensure not included 27 register_taxonomy( 'test_tax_cat', 'post' ); 28 wp_insert_term( "test1", 'test_tax_cat' ); 29 30 // Validate length is 1 + created due to uncategorized 31 $cat_ids = get_all_category_ids(); 32 $this->assertEquals( 3, count($cat_ids)); 33 } 34 35 /** 36 * Validate get_category_by_slug function 37 */ 38 function test_get_category_by_slug() { 39 40 // create Test Categories 41 $testcat = self::factory()->category->create_and_get( 42 array( 43 'slug' => 'testcat', 44 'name' => 'Test Category 1' 45 ) 46 ); 47 $testcat2 = self::factory()->category->create_and_get( 48 array( 49 'slug' => 'testcat2', 50 'name' => 'Test Category 2' 51 ) 52 ); 53 54 // validate category is returned by slug 55 $ret_testcat = get_category_by_slug( 'testcat' ); 56 $this->assertEquals( $testcat->term_id, $ret_testcat->term_id ); 57 $ret_testcat = get_category_by_slug( 'TeStCaT' ); 58 $this->assertEquals( $testcat->term_id, $ret_testcat->term_id ); 59 60 // validate unknown category returns false 61 $this->assertFalse( get_category_by_slug( 'testcat3' ) ); 62 63 } 64 65 /** 66 * Validate _make_cat_compat function 67 */ 68 function test__make_cat_compat() { 69 70 // create Test Categories and Array Representations 71 $testcat_array = array( 72 'slug' => 'testmcc', 73 'name' => 'Test MCC', 74 'description' => 'Category Test' 75 ); 76 $testcat = self::factory()->category->create_and_get( $testcat_array ); 77 $testcat_array['term_id'] = $testcat->term_id; 78 79 $testcat2_array = array( 80 'slug' => 'testmcc', 81 'name' => 'Test MCC', 82 'description' => 'Category Test', 83 'parent' => $testcat->term_id 84 ); 85 $testcat2 = self::factory()->category->create_and_get( $testcat2_array ); 86 $testcat2_array['term_id'] = $testcat2->term_id; 87 88 // unset properties to enable validation of object 89 unset( $testcat->cat_ID ); 90 unset( $testcat->category_count ); 91 unset( $testcat->category_description ); 92 unset( $testcat->cat_name ); 93 unset( $testcat->category_nicename ); 94 unset( $testcat->category_parent ); 95 96 unset( $testcat2->cat_ID ); 97 unset( $testcat2->category_count ); 98 unset( $testcat2->category_description ); 99 unset( $testcat2->cat_name ); 100 unset( $testcat2->category_nicename ); 101 unset( $testcat2->category_parent ); 102 103 // make Compatible 104 _make_cat_compat( $testcat ); 105 _make_cat_compat( $testcat2 ); 106 _make_cat_compat( $testcat_array ); 107 _make_cat_compat( $testcat2_array ); 108 109 // Validate Compatibility Object 110 $this->assertEquals( $testcat->cat_ID, $testcat->term_id ); 111 $this->assertEquals( $testcat->category_count, $testcat->count ); 112 $this->assertEquals( $testcat->category_description, $testcat->description ); 113 $this->assertEquals( $testcat->cat_name, $testcat->name ); 114 $this->assertEquals( $testcat->category_nicename, $testcat->slug ); 115 $this->assertEquals( $testcat->category_parent, $testcat->parent ); 116 117 // Validate Compatibility Object with Parent 118 $this->assertEquals( $testcat->cat_ID, $testcat->term_id ); 119 $this->assertEquals( $testcat->category_count, $testcat->count ); 120 $this->assertEquals( $testcat->category_description, $testcat->description ); 121 $this->assertEquals( $testcat->cat_name, $testcat->name ); 122 $this->assertEquals( $testcat->category_nicename, $testcat->slug ); 123 $this->assertEquals( $testcat->category_parent, $testcat->parent ); 124 125 // Validate Compatibility Array 126 $this->assertEquals( $testcat_array['cat_ID'], $testcat_array['term_id'] ); 127 $this->assertEquals( $testcat_array['category_count'], $testcat_array['count'] ); 128 $this->assertEquals( $testcat_array['category_description'], $testcat_array['description'] ); 129 $this->assertEquals( $testcat_array['cat_name'], $testcat_array['name'] ); 130 $this->assertEquals( $testcat_array['category_nicename'], $testcat_array['slug'] ); 131 $this->assertEquals( $testcat_array['category_parent'], $testcat_array['parent'] ); 132 133 // Validate Compatibility Array with Parent 134 $this->assertEquals( $testcat_array['cat_ID'], $testcat_array['term_id'] ); 135 $this->assertEquals( $testcat_array['category_count'], $testcat_array['count'] ); 136 $this->assertEquals( $testcat_array['category_description'], $testcat_array['description'] ); 137 $this->assertEquals( $testcat_array['cat_name'], $testcat_array['name'] ); 138 $this->assertEquals( $testcat_array['category_nicename'], $testcat_array['slug'] ); 139 $this->assertEquals( $testcat_array['category_parent'], $testcat_array['parent'] ); 140 } 141 142 /** 143 * Validate get_cat_name function 144 */ 145 function test_get_cat_name() { 146 147 // create Test Category 148 $testcat = self::factory()->category->create_and_get( 149 array( 150 'slug' => 'testcat', 151 'name' => 'Test Category 1' 152 ) 153 ); 154 155 // Validate 156 $this->assertEquals( $testcat->name, get_cat_name( $testcat->term_id ) ); 157 $this->assertEquals( '', get_cat_name( -1 ) ); 158 $this->assertEquals( '', get_cat_name( $testcat->term_id + 100 ) ); 159 160 } 161 162 /** 163 * Validate get_cat_name function 164 */ 165 function test_get_cat_ID() { 166 167 // create Test Category 168 $testcat = self::factory()->category->create_and_get( 169 array( 170 'slug' => 'testcat', 171 'name' => 'Test Category 1' 172 ) 173 ); 174 175 // Validate 176 $this->assertEquals( $testcat->term_id, get_cat_ID( $testcat->name ) ); 177 $this->assertEquals( 0, get_cat_ID( "NO CAT" ) ); 178 $this->assertEquals( 0, get_cat_ID( 12 ) ); 179 180 } 181 182 /** 183 * Validate get_category_by_path function 184 */ 185 function test_get_category_by_path() { 186 187 // create Test Categories 188 $root_id = self::factory()->category->create( 189 array( 190 'slug' => 'root', 191 ) 192 ); 193 $root_cat_id = self::factory()->category->create( 194 array( 195 'slug' => 'cat', 196 'parent' => $root_id 197 ) 198 ); 199 $root_cat_cat_id = self::factory()->category->create( 200 array( 201 'slug' => 'cat', //note this is modified on create 202 'parent' => $root_cat_id 203 ) 204 ); 205 $root_path_id = self::factory()->category->create( 206 array( 207 'slug' => 'path', 208 'parent' => $root_id 209 ) 210 ); 211 $root_path_cat_id = self::factory()->category->create( 212 array( 213 'slug' => 'cat', //note this is modified on create 214 'parent' => $root_path_id 215 ) 216 ); 217 $root_level_id = self::factory()->category->create( 218 array( 219 'slug' => 'level-1', 220 'parent' => $root_id 221 ) 222 ); 223 $root_level_cat_id = self::factory()->category->create( 224 array( 225 'slug' => 'cat', //note this is modified on create 226 'parent' => $root_level_id 227 ) 228 ); 229 230 // Validate Full Match 231 $ret_cat = get_category_by_path( '/root/level-1', true ); 232 $this->assertEquals( $root_level_id, $ret_cat->term_id ); 233 $this->assertNull( get_category_by_path( 'level-1', true ) ); 234 $this->assertNull( get_category_by_path( 'nocat/nocat/', true) ); 235 236 // Validate Partial Match 237 $ret_cat = get_category_by_path( 'level-1', false ); 238 $this->assertEquals( $root_level_id, $ret_cat->term_id ); 239 $ret_cat = get_category_by_path( 'root/cat/level-1', false ); 240 $this->assertEquals( $root_level_id, $ret_cat->term_id ); 241 $ret_cat = get_category_by_path( 'root$2Fcat%20%2Flevel-1', false ); 242 $this->assertEquals( $root_level_id, $ret_cat->term_id ); 243 $this->assertNull( get_category_by_path( 'nocat/nocat/', false) ); 244 } 245 6 class Tests_Category_WpDropdownCategories extends WP_UnitTestCase { 246 7 /** 247 8 * @ticket 30306
Note: See TracChangeset
for help on using the changeset viewer.