Changeset 54717 for trunk/tests/phpunit/tests/category/makeCatCompat.php
- Timestamp:
- 10/29/2022 02:38:18 PM (23 months ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
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.