Changeset 407 in tests for wp-testcase/test_includes_taxonomy.php
- Timestamp:
- 08/04/2011 08:38:26 PM (15 years ago)
- File:
-
- 1 edited
-
wp-testcase/test_includes_taxonomy.php (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-testcase/test_includes_taxonomy.php
r396 r407 6 6 $this->assertEquals(array('category', 'post_tag', 'post_format'), get_object_taxonomies('post')); 7 7 } 8 8 9 9 function test_get_link_taxonomies() { 10 10 $this->assertEquals(array('link_category'), get_object_taxonomies('link')); 11 11 } 12 12 13 13 function test_get_unknown_taxonomies() { 14 14 // taxonomies for an unknown object type … … 19 19 $this->assertEquals( array(), get_object_taxonomies(NULL) ); 20 20 } 21 21 22 22 function test_get_post_taxonomy() { 23 23 foreach ( get_object_taxonomies('post') as $taxonomy ) { … … 45 45 $this->assertTrue( is_taxonomy('link_category') ); 46 46 } 47 47 48 48 function test_is_taxonomy_unknown() { 49 49 $this->assertFalse( is_taxonomy(rand_str()) ); … … 52 52 $this->assertFalse( is_taxonomy(NULL) ); 53 53 } 54 54 55 55 function test_is_taxonomy_hierarchical() { 56 56 $this->assertTrue( is_taxonomy_hierarchical('category') ); … … 58 58 $this->assertFalse( is_taxonomy_hierarchical('link_category') ); 59 59 } 60 60 61 61 function test_is_taxonomy_hierarchical_unknown() { 62 62 $this->assertFalse( is_taxonomy_hierarchical(rand_str()) ); … … 65 65 $this->assertFalse( is_taxonomy_hierarchical(NULL) ); 66 66 } 67 67 68 68 function test_register_taxonomy() { 69 69 70 70 // make up a new taxonomy name, and ensure it's unused 71 71 $tax = rand_str(); 72 72 $this->assertFalse( is_taxonomy($tax) ); 73 73 74 74 register_taxonomy( $tax, 'post' ); 75 75 $this->assertTrue( is_taxonomy($tax) ); 76 $this->assertFalse( is_taxonomy_hierarchical($tax) ); 77 76 $this->assertFalse( is_taxonomy_hierarchical($tax) ); 77 78 78 // clean up 79 79 unset($GLOBALS['wp_taxonomies'][$tax]); 80 80 } 81 81 82 82 function test_register_hierarchical_taxonomy() { 83 83 84 84 // make up a new taxonomy name, and ensure it's unused 85 85 $tax = rand_str(); 86 86 $this->assertFalse( is_taxonomy($tax) ); 87 87 88 88 register_taxonomy( $tax, 'post', array('hierarchical'=>true) ); 89 89 $this->assertTrue( is_taxonomy($tax) ); 90 $this->assertTrue( is_taxonomy_hierarchical($tax) ); 91 90 $this->assertTrue( is_taxonomy_hierarchical($tax) ); 91 92 92 // clean up 93 93 unset($GLOBALS['wp_taxonomies'][$tax]); … … 97 97 class TestTermAPI extends _WPEmptyBlog { 98 98 var $taxonomy = 'category'; 99 99 100 100 function setUp() { 101 101 parent::setUp(); … … 106 106 wp_insert_term( $term, $tax ); 107 107 } 108 108 109 109 function test_wp_insert_delete_term() { 110 110 // a new unused term 111 111 $term = rand_str(); 112 112 $this->assertNull( is_term($term) ); 113 113 114 114 $initial_count = wp_count_terms( $this->taxonomy ); 115 115 116 116 $t = wp_insert_term( $term, $this->taxonomy ); 117 117 $this->assertTrue( is_array($t) ); … … 120 120 $this->assertTrue( $t['term_taxonomy_id'] > 0 ); 121 121 $this->assertEquals( $initial_count + 1, wp_count_terms($this->taxonomy) ); 122 122 123 123 // make sure the term exists 124 124 $this->assertTrue( is_term($term) > 0 ); 125 125 $this->assertTrue( is_term($t['term_id']) > 0 ); 126 126 127 127 // now delete it 128 128 $this->assertTrue( wp_delete_term($t['term_id'], $this->taxonomy) ); … … 131 131 $this->assertEquals( $initial_count, wp_count_terms($this->taxonomy) ); 132 132 } 133 133 134 134 function test_is_term_known() { 135 135 // insert a term 136 136 $term = rand_str(); 137 137 $t = wp_insert_term( $term, $this->taxonomy ); 138 138 139 139 $this->assertEquals( $t['term_id'], is_term($t['term_id']) ); 140 140 $this->assertEquals( $t['term_id'], is_term($term) ); 141 141 142 142 // clean up 143 143 $this->assertTrue( wp_delete_term($t['term_id'], $this->taxonomy) ); 144 144 } 145 145 146 146 function test_is_term_unknown() { 147 147 $this->assertNull( is_term(rand_str()) ); … … 150 150 $this->assertEquals( 0, is_term(NULL) ); 151 151 } 152 152 153 153 function test_is_term_type() { 154 154 // insert a term … … 163 163 $this->assertTrue( wp_delete_term($t['term_id'], $this->taxonomy) ); 164 164 } 165 165 166 166 function test_set_object_terms_by_id() { 167 167 $this->_insert_quick_posts(5); 168 168 169 169 $terms = array(); 170 170 for ($i=0; $i<3; $i++ ) { … … 173 173 $term_id[$term] = $result['term_id']; 174 174 } 175 175 176 176 foreach ($this->post_ids as $id) { 177 177 $tt = wp_set_object_terms( $id, array_values($term_id), $this->taxonomy ); … … 185 185 $this->assertEquals( $this->post_ids, array_map('intval', $actual) ); 186 186 } 187 187 188 188 // each term should have a count of 5 189 189 foreach (array_keys($term_id) as $term) { … … 192 192 } 193 193 } 194 194 195 195 function test_set_object_terms_by_name() { 196 196 $this->_insert_quick_posts(5); 197 197 198 198 $terms = array( 199 199 rand_str(), 200 200 rand_str(), 201 201 rand_str()); 202 202 203 203 foreach ($this->post_ids as $id) { 204 204 $tt = wp_set_object_terms( $id, $terms, $this->taxonomy ); … … 217 217 $this->assertEquals( $this->post_ids, array_map('intval', $actual) ); 218 218 } 219 219 220 220 // each term should have a count of 5 221 221 foreach ($terms as $term) { … … 224 224 } 225 225 } 226 226 227 227 function test_change_object_terms_by_name() { 228 228 // set some terms on an object; then change them while leaving one intact 229 229 230 230 $this->_insert_quick_posts(1); 231 231 $post_id = end($this->post_ids); … … 233 233 $terms_1 = array('foo', 'bar', 'baz'); 234 234 $terms_2 = array('bar', 'bing'); 235 235 236 236 // set the initial terms 237 237 $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy ); … … 241 241 $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'names', 'orderby' => 't.term_id')); 242 242 $this->assertEquals( $terms_1, $terms ); 243 243 244 244 // change the terms 245 245 $tt_2 = wp_set_object_terms( $post_id, $terms_2, $this->taxonomy ); … … 249 249 $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'names', 'orderby' => 't.term_id')); 250 250 $this->assertEquals( $terms_2, $terms ); 251 251 252 252 // make sure the tt id for 'bar' matches 253 253 $this->assertEquals( $tt_1[1], $tt_2[0] ); 254 254 255 255 } 256 256 257 257 function test_change_object_terms_by_id() { 258 258 // set some terms on an object; then change them while leaving one intact 259 259 260 260 $this->_insert_quick_posts(1); 261 261 $post_id = end($this->post_ids); … … 272 272 $terms_2 = array(); 273 273 $terms_2[0] = $terms_1[1]; 274 274 275 275 $term = rand_str(); 276 276 $result = wp_insert_term( $term, $this->taxonomy ); 277 277 $terms_2[1] = $result['term_id']; 278 278 279 279 280 280 // set the initial terms 281 281 $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy ); … … 285 285 $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'ids', 'orderby' => 't.term_id')); 286 286 $this->assertEquals( $terms_1, $terms ); 287 287 288 288 // change the terms 289 289 $tt_2 = wp_set_object_terms( $post_id, $terms_2, $this->taxonomy ); … … 293 293 $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'ids', 'orderby' => 't.term_id')); 294 294 $this->assertEquals( $terms_2, $terms ); 295 295 296 296 // make sure the tt id for 'bar' matches 297 297 $this->assertEquals( $tt_1[1], $tt_2[0] ); 298 299 } 300 298 299 } 300 301 301 function test_set_object_terms_invalid() { 302 302 $this->_insert_quick_posts(1); … … 307 307 $this->assertTrue( is_wp_error($result) ); 308 308 } 309 309 310 310 } 311 311
Note: See TracChangeset
for help on using the changeset viewer.