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