Changeset 35537 for trunk/tests/phpunit/tests/term/getTerm.php
- Timestamp:
- 11/05/2015 04:44:59 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term/getTerm.php
r35242 r35537 10 10 } 11 11 12 /** 13 * Utility function for generating two shared terms, in the 'wptests_tax' and 'wptests_tax_2' taxonomies. 14 * 15 * @return array Array of term_id/old_term_id/term_taxonomy_id triplets. 16 */ 17 protected function generate_shared_terms() { 18 global $wpdb; 19 20 register_taxonomy( 'wptests_tax_2', 'post' ); 21 22 $t1 = wp_insert_term( 'Foo', 'wptests_tax' ); 23 $t2 = wp_insert_term( 'Foo', 'wptests_tax_2' ); 24 25 // Manually modify because shared terms shouldn't naturally occur. 26 $wpdb->update( $wpdb->term_taxonomy, 27 array( 'term_id' => $t1['term_id'] ), 28 array( 'term_taxonomy_id' => $t2['term_taxonomy_id'] ), 29 array( '%d' ), 30 array( '%d' ) 31 ); 32 33 return array( 34 array( 35 'term_id' => $t1['term_id'], 36 'old_term_id' => $t1['term_id'], 37 'term_taxonomy_id' => $t1['term_taxonomy_id'], 38 ), 39 array( 40 'term_id' => $t1['term_id'], 41 'old_term_id' => $t2['term_id'], 42 'term_taxonomy_id' => $t2['term_taxonomy_id'], 43 ), 44 ); 45 } 46 12 47 public function test_should_return_error_for_empty_term() { 13 48 $found = get_term( '', 'wptests_tax' ); … … 115 150 $this->assertNull( get_term( $term_id, 'category' ) ); 116 151 } 152 153 /** 154 * @ticket 34533 155 */ 156 public function test_should_return_wp_error_when_term_is_shared_and_no_taxonomy_is_specified() { 157 $terms = $this->generate_shared_terms(); 158 159 $found = get_term( $terms[0]['term_id'] ); 160 161 $this->assertWPError( $found ); 162 } 163 164 /** 165 * @ticket 34533 166 */ 167 public function test_should_return_term_when_term_is_shared_and_correct_taxonomy_is_specified() { 168 $terms = $this->generate_shared_terms(); 169 170 $found = get_term( $terms[0]['term_id'], 'wptests_tax' ); 171 172 $this->assertInstanceOf( 'WP_Term', $found ); 173 $this->assertSame( $terms[0]['term_id'], $found->term_id ); 174 } 175 176 /** 177 * @ticket 34533 178 */ 179 public function test_should_return_null_when_term_is_shared_and_incorrect_taxonomy_is_specified() { 180 $terms = $this->generate_shared_terms(); 181 182 $found = get_term( $terms[0]['term_id'], 'post_tag' ); 183 184 $this->assertNull( $found ); 185 } 186 187 /** 188 * @ticket 34533 189 */ 190 public function test_shared_term_in_cache_should_be_ignored_when_specifying_a_different_taxonomy() { 191 global $wpdb; 192 193 $terms = $this->generate_shared_terms(); 194 195 // Prime cache for 'wptests_tax'. 196 get_term( $terms[0]['term_id'], 'wptests_tax' ); 197 $num_queries = $wpdb->num_queries; 198 199 // Database should be hit again. 200 $found = get_term( $terms[1]['term_id'], 'wptests_tax_2' ); 201 $num_queries++; 202 203 $this->assertSame( $num_queries, $wpdb->num_queries ); 204 $this->assertInstanceOf( 'WP_Term', $found ); 205 $this->assertSame( 'wptests_tax_2', $found->taxonomy ); 206 } 207 208 /** 209 * @ticket 34533 210 */ 211 public function test_should_return_error_when_only_matching_term_is_in_an_invalid_taxonomy() { 212 $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) ); 213 214 _unregister_taxonomy( 'wptests_tax' ); 215 216 $found = get_term( $t ); 217 $this->assertWPError( $found ); 218 $this->assertSame( 'invalid_taxonomy', $found->get_error_code() ); 219 } 220 221 /** 222 * @ticket 34533 223 */ 224 public function test_term_should_be_returned_when_id_is_shared_only_with_invalid_taxonomies() { 225 $terms = $this->generate_shared_terms(); 226 227 _unregister_taxonomy( 'wptests_tax' ); 228 229 $found = get_term( $terms[1]['term_id'] ); 230 $this->assertInstanceOf( 'WP_Term', $found ); 231 $this->assertSame( 'wptests_tax_2', $found->taxonomy ); 232 $this->assertSame( $terms[1]['term_id'], $found->term_id ); 233 } 117 234 }
Note: See TracChangeset
for help on using the changeset viewer.