- Timestamp:
- 10/29/2022 02:38:18 PM (23 months ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
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() {
Note: See TracChangeset
for help on using the changeset viewer.