Changeset 47122 for trunk/tests/phpunit/tests/term/wpSetObjectTerms.php
- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term/wpSetObjectTerms.php
r46586 r47122 19 19 $hier = rand_str( 10 ); 20 20 21 // Register taxonomies 21 // Register taxonomies. 22 22 register_taxonomy( $non_hier, array() ); 23 23 register_taxonomy( $hier, array( 'hierarchical' => true ) ); … … 113 113 foreach ( $ids as $id ) { 114 114 $tt = wp_set_object_terms( $id, array_values( $term_id ), $this->taxonomy ); 115 // should return three term taxonomy ids115 // Should return three term taxonomy IDs. 116 116 $this->assertEquals( 3, count( $tt ) ); 117 117 } 118 118 119 // each term should be associated with every post119 // Each term should be associated with every post. 120 120 foreach ( $term_id as $term => $id ) { 121 121 $actual = get_objects_in_term( $id, $this->taxonomy ); … … 123 123 } 124 124 125 // each term should have a count of 5125 // Each term should have a count of 5. 126 126 foreach ( array_keys( $term_id ) as $term ) { 127 127 $t = get_term_by( 'name', $term, $this->taxonomy ); … … 141 141 foreach ( $ids as $id ) { 142 142 $tt = wp_set_object_terms( $id, $terms, $this->taxonomy ); 143 // should return three term taxonomy ids143 // Should return three term taxonomy IDs. 144 144 $this->assertEquals( 3, count( $tt ) ); 145 // remember which term has which term_id145 // Remember which term has which term_id. 146 146 for ( $i = 0; $i < 3; $i++ ) { 147 147 $term = get_term_by( 'name', $terms[ $i ], $this->taxonomy ); … … 150 150 } 151 151 152 // each term should be associated with every post152 // Each term should be associated with every post. 153 153 foreach ( $term_id as $term => $id ) { 154 154 $actual = get_objects_in_term( $id, $this->taxonomy ); … … 156 156 } 157 157 158 // each term should have a count of 5158 // Each term should have a count of 5. 159 159 foreach ( $terms as $term ) { 160 160 $t = get_term_by( 'name', $term, $this->taxonomy ); … … 164 164 165 165 function test_set_object_terms_invalid() { 166 // bogus taxonomy166 // Bogus taxonomy. 167 167 $result = wp_set_object_terms( self::$post_ids[0], array( rand_str() ), rand_str() ); 168 168 $this->assertWPError( $result ); … … 244 244 } 245 245 246 /** 247 * Set some terms on an object; then change them while leaving one intact. 248 */ 246 249 function test_change_object_terms_by_id() { 247 // set some terms on an object; then change them while leaving one intact248 249 250 $post_id = self::$post_ids[0]; 250 251 251 // first set: 3 terms252 // First set: 3 terms. 252 253 $terms_1 = array(); 253 254 for ( $i = 0; $i < 3; $i++ ) { … … 258 259 } 259 260 260 // second set: one of the original terms, plus one new term261 // Second set: one of the original terms, plus one new term. 261 262 $terms_2 = array(); 262 263 $terms_2[0] = $terms_1[1]; … … 266 267 $terms_2[1] = $result['term_id']; 267 268 268 // set the initial terms269 // Set the initial terms. 269 270 $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy ); 270 271 $this->assertEquals( 3, count( $tt_1 ) ); 271 272 272 // make sure they're correct273 // Make sure they're correct. 273 274 $terms = wp_get_object_terms( 274 275 $post_id, … … 281 282 $this->assertEquals( $terms_1, $terms ); 282 283 283 // change the terms284 // Change the terms. 284 285 $tt_2 = wp_set_object_terms( $post_id, $terms_2, $this->taxonomy ); 285 286 $this->assertEquals( 2, count( $tt_2 ) ); 286 287 287 // make sure they're correct288 // Make sure they're correct. 288 289 $terms = wp_get_object_terms( 289 290 $post_id, … … 296 297 $this->assertEquals( $terms_2, $terms ); 297 298 298 // make sure the tt id for 'bar' matches299 // Make sure the term taxonomy ID for 'bar' matches. 299 300 $this->assertEquals( $tt_1[1], $tt_2[0] ); 300 301 301 302 } 302 303 304 /** 305 * Set some terms on an object; then change them while leaving one intact. 306 */ 303 307 function test_change_object_terms_by_name() { 304 // set some terms on an object; then change them while leaving one intact305 306 308 $post_id = self::$post_ids[0]; 307 309 … … 309 311 $terms_2 = array( 'bar', 'bing' ); 310 312 311 // set the initial terms313 // Set the initial terms. 312 314 $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy ); 313 315 $this->assertEquals( 3, count( $tt_1 ) ); 314 316 315 // make sure they're correct317 // Make sure they're correct. 316 318 $terms = wp_get_object_terms( 317 319 $post_id, … … 324 326 $this->assertEquals( $terms_1, $terms ); 325 327 326 // change the terms328 // Change the terms. 327 329 $tt_2 = wp_set_object_terms( $post_id, $terms_2, $this->taxonomy ); 328 330 $this->assertEquals( 2, count( $tt_2 ) ); 329 331 330 // make sure they're correct332 // Make sure they're correct. 331 333 $terms = wp_get_object_terms( 332 334 $post_id, … … 339 341 $this->assertEquals( $terms_2, $terms ); 340 342 341 // make sure the tt id for 'bar' matches343 // Make sure the term taxonomy ID for 'bar' matches. 342 344 $this->assertEquals( $tt_1[1], $tt_2[0] ); 343 345
Note: See TracChangeset
for help on using the changeset viewer.