Changeset 42343 for trunk/tests/phpunit/tests/term/taxQuery.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/term/taxQuery.php (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term/taxQuery.php
r40918 r42343 19 19 20 20 public function test_construct_with_relation_or_lowercase() { 21 $tq = new WP_Tax_Query( array( 22 'relation' => 'or', 23 ) ); 21 $tq = new WP_Tax_Query( 22 array( 23 'relation' => 'or', 24 ) 25 ); 24 26 $this->assertSame( 'OR', $tq->relation ); 25 27 } 26 28 27 29 public function test_construct_with_relation_or_uppercase() { 28 $tq = new WP_Tax_Query( array( 29 'relation' => 'OR', 30 ) ); 30 $tq = new WP_Tax_Query( 31 array( 32 'relation' => 'OR', 33 ) 34 ); 31 35 $this->assertSame( 'OR', $tq->relation ); 32 36 } 33 37 34 38 public function test_construct_with_relation_other() { 35 $tq = new WP_Tax_Query( array( 36 'relation' => 'foo', 37 ) ); 39 $tq = new WP_Tax_Query( 40 array( 41 'relation' => 'foo', 42 ) 43 ); 38 44 $this->assertSame( 'AND', $tq->relation ); 39 45 } 40 46 41 47 public function test_construct_fill_missing_query_params() { 42 $tq = new WP_Tax_Query( array( 43 array(), 44 ) ); 48 $tq = new WP_Tax_Query( 49 array( 50 array(), 51 ) 52 ); 45 53 46 54 $expected = array( 47 'taxonomy' => '',48 'terms' => array(),55 'taxonomy' => '', 56 'terms' => array(), 49 57 'include_children' => true, 50 'field' => 'term_id',51 'operator' => 'IN',58 'field' => 'term_id', 59 'operator' => 'IN', 52 60 ); 53 61 … … 56 64 57 65 public function test_construct_fill_missing_query_params_merge_with_passed_values() { 58 $tq = new WP_Tax_Query( array( 59 array( 60 'taxonomy' => 'foo', 61 'include_children' => false, 62 'foo' => 'bar', 63 ), 64 ) ); 66 $tq = new WP_Tax_Query( 67 array( 68 array( 69 'taxonomy' => 'foo', 70 'include_children' => false, 71 'foo' => 'bar', 72 ), 73 ) 74 ); 65 75 66 76 $expected = array( 67 'taxonomy' => 'foo',68 'terms' => array(),77 'taxonomy' => 'foo', 78 'terms' => array(), 69 79 'include_children' => false, 70 'field' => 'term_id',71 'operator' => 'IN',72 'foo' => 'bar',80 'field' => 'term_id', 81 'operator' => 'IN', 82 'foo' => 'bar', 73 83 ); 74 84 … … 77 87 78 88 public function test_construct_cast_terms_to_array() { 79 $tq = new WP_Tax_Query( array( 80 array( 81 'terms' => 'foo', 82 ), 83 ) ); 84 85 $this->assertEquals( array( 'foo', ), $tq->queries[0]['terms'] ); 89 $tq = new WP_Tax_Query( 90 array( 91 array( 92 'terms' => 'foo', 93 ), 94 ) 95 ); 96 97 $this->assertEquals( array( 'foo' ), $tq->queries[0]['terms'] ); 86 98 } 87 99 … … 90 102 */ 91 103 public function test_construct_empty_strings_array_members_should_be_discarded() { 92 $q = new WP_Tax_Query( array( 93 '', 94 array( 95 'taxonomy' => 'post_tag', 96 'terms' => 'foo', 97 ), 98 ) ); 104 $q = new WP_Tax_Query( 105 array( 106 '', 107 array( 108 'taxonomy' => 'post_tag', 109 'terms' => 'foo', 110 ), 111 ) 112 ); 99 113 100 114 $this->assertSame( 1, count( $q->queries ) ); … … 102 116 103 117 public function test_transform_query_terms_empty() { 104 $tq = new WP_Tax_Query( array( 105 array(), 106 ) ); 118 $tq = new WP_Tax_Query( 119 array( 120 array(), 121 ) 122 ); 107 123 $query = $tq->queries[0]; 108 124 … … 113 129 114 130 public function test_transform_query_field_same_as_resulting_field() { 115 $tq = new WP_Tax_Query( array( 116 array( 117 'field' => 'term_id', 118 ), 119 ) ); 131 $tq = new WP_Tax_Query( 132 array( 133 array( 134 'field' => 'term_id', 135 ), 136 ) 137 ); 120 138 $query = $tq->queries[0]; 121 139 … … 126 144 127 145 public function test_transform_query_resulting_field_sanitized() { 128 $t1 = self::factory()->category->create( array( 'slug' => 'foo' ,) );129 $t2 = self::factory()->category->create( array( 'slug' => 'bar' ,) );130 $p = self::factory()->post->create();146 $t1 = self::factory()->category->create( array( 'slug' => 'foo' ) ); 147 $t2 = self::factory()->category->create( array( 'slug' => 'bar' ) ); 148 $p = self::factory()->post->create(); 131 149 wp_set_post_categories( $p, $t1 ); 132 150 133 $tq1 = new WP_Tax_Query( array( 134 array( 135 'terms' => array( 'foo' ), 136 'field' => 'slug', 137 ), 138 ) ); 151 $tq1 = new WP_Tax_Query( 152 array( 153 array( 154 'terms' => array( 'foo' ), 155 'field' => 'slug', 156 ), 157 ) 158 ); 139 159 $tq1->transform_query( $tq1->queries[0], 'term_taxonomy_id' ); 140 160 141 $tq2 = new WP_Tax_Query( array( 142 array( 143 'terms' => array( 'foo' ), 144 'field' => 'slug', 145 ), 146 ) ); 161 $tq2 = new WP_Tax_Query( 162 array( 163 array( 164 'terms' => array( 'foo' ), 165 'field' => 'slug', 166 ), 167 ) 168 ); 147 169 $tq2->transform_query( $tq2->queries[0], 'TERM_ ta%xonomy_id' ); 148 170 … … 151 173 152 174 public function test_transform_query_field_slug() { 153 $t1 = self::factory()->category->create( array( 'slug' => 'foo',) );154 $p = self::factory()->post->create();175 $t1 = self::factory()->category->create( array( 'slug' => 'foo' ) ); 176 $p = self::factory()->post->create(); 155 177 $tt_ids = wp_set_post_categories( $p, $t1 ); 156 178 157 $tq = new WP_Tax_Query( array( 158 array( 159 'taxonomy' => 'category', 160 'terms' => array( 'foo' ), 161 'field' => 'slug', 162 ), 163 ) ); 179 $tq = new WP_Tax_Query( 180 array( 181 array( 182 'taxonomy' => 'category', 183 'terms' => array( 'foo' ), 184 'field' => 'slug', 185 ), 186 ) 187 ); 164 188 $tq->transform_query( $tq->queries[0], 'term_taxonomy_id' ); 165 189 … … 169 193 170 194 public function test_transform_query_field_name() { 171 $t1 = self::factory()->category->create( array( 'slug' => 'foo', 'name' => 'Foo', ) ); 172 $p = self::factory()->post->create(); 195 $t1 = self::factory()->category->create( 196 array( 197 'slug' => 'foo', 198 'name' => 'Foo', 199 ) 200 ); 201 $p = self::factory()->post->create(); 173 202 $tt_ids = wp_set_post_categories( $p, $t1 ); 174 203 175 $tq = new WP_Tax_Query( array( 176 array( 177 'taxonomy' => 'category', 178 'terms' => array( 'Foo' ), 179 'field' => 'name', 180 ), 181 ) ); 204 $tq = new WP_Tax_Query( 205 array( 206 array( 207 'taxonomy' => 'category', 208 'terms' => array( 'Foo' ), 209 'field' => 'name', 210 ), 211 ) 212 ); 182 213 $tq->transform_query( $tq->queries[0], 'term_taxonomy_id' ); 183 214 … … 187 218 188 219 public function test_transform_query_field_term_taxonomy_id() { 189 $t1 = self::factory()->category->create( array( 'slug' => 'foo', 'name' => 'Foo', ) ); 190 $p = self::factory()->post->create(); 220 $t1 = self::factory()->category->create( 221 array( 222 'slug' => 'foo', 223 'name' => 'Foo', 224 ) 225 ); 226 $p = self::factory()->post->create(); 191 227 $tt_ids = wp_set_post_categories( $p, $t1 ); 192 228 193 $tq = new WP_Tax_Query( array( 194 array( 195 'taxonomy' => 'category', 196 'terms' => $tt_ids, 197 'field' => 'term_taxonomy_id', 198 ), 199 ) ); 229 $tq = new WP_Tax_Query( 230 array( 231 array( 232 'taxonomy' => 'category', 233 'terms' => $tt_ids, 234 'field' => 'term_taxonomy_id', 235 ), 236 ) 237 ); 200 238 $tq->transform_query( $tq->queries[0], 'term_id' ); 201 239 … … 205 243 206 244 public function test_transform_query_field_term_taxonomy_default() { 207 $t1 = self::factory()->category->create( array( 'slug' => 'foo', 'name' => 'Foo', ) ); 208 $p = self::factory()->post->create(); 245 $t1 = self::factory()->category->create( 246 array( 247 'slug' => 'foo', 248 'name' => 'Foo', 249 ) 250 ); 251 $p = self::factory()->post->create(); 209 252 $tt_ids = wp_set_post_categories( $p, $t1 ); 210 253 211 $tq = new WP_Tax_Query( array( 212 array( 213 'taxonomy' => 'category', 214 'terms' => array( $t1 ), 215 'field' => 'foo', // Anything defaults to term_id 216 ), 217 ) ); 254 $tq = new WP_Tax_Query( 255 array( 256 array( 257 'taxonomy' => 'category', 258 'terms' => array( $t1 ), 259 'field' => 'foo', // Anything defaults to term_id 260 ), 261 ) 262 ); 218 263 $tq->transform_query( $tq->queries[0], 'term_taxonomy_id' ); 219 264 … … 223 268 224 269 public function test_transform_query_nonexistent_terms() { 225 $tq = new WP_Tax_Query( array( 226 array( 227 'terms' => array( 'foo' ), 228 'field' => 'slug', 229 'operator' => 'AND', 230 ), 231 ) ); 270 $tq = new WP_Tax_Query( 271 array( 272 array( 273 'terms' => array( 'foo' ), 274 'field' => 'slug', 275 'operator' => 'AND', 276 ), 277 ) 278 ); 232 279 $tq->transform_query( $tq->queries[0], 'term_taxonomy_id' ); 233 280 … … 241 288 register_taxonomy( 'wptests_tax', 'post' ); 242 289 243 $t1 = self::factory()->term->create( array( 244 'taxonomy' => 'wptests_tax', 245 ) ); 246 $t2 = self::factory()->term->create( array( 247 'taxonomy' => 'wptests_tax', 248 ) ); 249 $t3 = self::factory()->term->create( array( 250 'taxonomy' => 'wptests_tax', 251 ) ); 252 253 $tq = new WP_Tax_Query( array( 254 'relation' => 'OR', 255 array( 256 'taxonomy' => 'wptests_tax', 257 'field' => 'term_id', 258 'terms' => $t1, 259 ), 260 array( 261 'taxonomy' => 'wptests_tax', 262 'field' => 'term_id', 263 'terms' => $t2, 264 ), 265 array( 266 'taxonomy' => 'wptests_tax', 267 'field' => 'term_id', 268 'terms' => $t3, 269 ), 270 ) ); 290 $t1 = self::factory()->term->create( 291 array( 292 'taxonomy' => 'wptests_tax', 293 ) 294 ); 295 $t2 = self::factory()->term->create( 296 array( 297 'taxonomy' => 'wptests_tax', 298 ) 299 ); 300 $t3 = self::factory()->term->create( 301 array( 302 'taxonomy' => 'wptests_tax', 303 ) 304 ); 305 306 $tq = new WP_Tax_Query( 307 array( 308 'relation' => 'OR', 309 array( 310 'taxonomy' => 'wptests_tax', 311 'field' => 'term_id', 312 'terms' => $t1, 313 ), 314 array( 315 'taxonomy' => 'wptests_tax', 316 'field' => 'term_id', 317 'terms' => $t2, 318 ), 319 array( 320 'taxonomy' => 'wptests_tax', 321 'field' => 'term_id', 322 'terms' => $t3, 323 ), 324 ) 325 ); 271 326 272 327 global $wpdb; … … 285 340 register_taxonomy( 'wptests_tax', 'post' ); 286 341 287 $t1 = self::factory()->term->create( array( 288 'taxonomy' => 'wptests_tax', 289 ) ); 290 $t2 = self::factory()->term->create( array( 291 'taxonomy' => 'wptests_tax', 292 ) ); 293 $t3 = self::factory()->term->create( array( 294 'taxonomy' => 'wptests_tax', 295 ) ); 296 297 $tq = new WP_Tax_Query( array( 298 'relation' => 'AND', 299 array( 300 'taxonomy' => 'wptests_tax', 301 'field' => 'term_id', 302 'terms' => $t1, 303 ), 304 array( 305 'taxonomy' => 'wptests_tax', 306 'field' => 'term_id', 307 'terms' => $t2, 308 ), 309 array( 310 'taxonomy' => 'wptests_tax', 311 'field' => 'term_id', 312 'terms' => $t3, 313 ), 314 ) ); 342 $t1 = self::factory()->term->create( 343 array( 344 'taxonomy' => 'wptests_tax', 345 ) 346 ); 347 $t2 = self::factory()->term->create( 348 array( 349 'taxonomy' => 'wptests_tax', 350 ) 351 ); 352 $t3 = self::factory()->term->create( 353 array( 354 'taxonomy' => 'wptests_tax', 355 ) 356 ); 357 358 $tq = new WP_Tax_Query( 359 array( 360 'relation' => 'AND', 361 array( 362 'taxonomy' => 'wptests_tax', 363 'field' => 'term_id', 364 'terms' => $t1, 365 ), 366 array( 367 'taxonomy' => 'wptests_tax', 368 'field' => 'term_id', 369 'terms' => $t2, 370 ), 371 array( 372 'taxonomy' => 'wptests_tax', 373 'field' => 'term_id', 374 'terms' => $t3, 375 ), 376 ) 377 ); 315 378 316 379 global $wpdb; … … 328 391 register_taxonomy( 'wptests_tax', 'post' ); 329 392 330 $t1 = self::factory()->term->create( array(331 'taxonomy' => 'wptests_tax',332 ) );333 $t2 = self::factory()->term->create( array(334 'taxonomy' => 'wptests_tax',335 ) );336 $t3 = self::factory()->term->create(array(337 'taxonomy' => 'wptests_tax',338 ) );339 340 $t q = new WP_Tax_Query( array(341 'relation' => 'OR',342 array(343 'taxonomy' => 'wptests_tax',344 'field' => 'term_id',345 'terms' => $t1, 346 ),393 $t1 = self::factory()->term->create( 394 array( 395 'taxonomy' => 'wptests_tax', 396 ) 397 ); 398 $t2 = self::factory()->term->create( 399 array( 400 'taxonomy' => 'wptests_tax', 401 ) 402 ); 403 $t3 = self::factory()->term->create( 404 array( 405 'taxonomy' => 'wptests_tax', 406 ) 407 ); 408 409 $tq = new WP_Tax_Query( 347 410 array( 348 411 'relation' => 'OR', 349 412 array( 350 413 'taxonomy' => 'wptests_tax', 351 'field' => 'term_id', 352 'terms' => $t2, 353 ), 354 array( 355 'taxonomy' => 'wptests_tax', 356 'field' => 'term_id', 357 'terms' => $t3, 358 ), 359 ), 360 ) ); 414 'field' => 'term_id', 415 'terms' => $t1, 416 ), 417 array( 418 'relation' => 'OR', 419 array( 420 'taxonomy' => 'wptests_tax', 421 'field' => 'term_id', 422 'terms' => $t2, 423 ), 424 array( 425 'taxonomy' => 'wptests_tax', 426 'field' => 'term_id', 427 'terms' => $t3, 428 ), 429 ), 430 ) 431 ); 361 432 362 433 global $wpdb; … … 374 445 register_taxonomy( 'wptests_tax', 'post' ); 375 446 376 $tq = new WP_Tax_Query( array( 377 'relation' => 'OR', 378 array( 379 'taxonomy' => 'wptests_tax', 380 'field' => 'term_id', 381 'operator' => 'NOT IN', 382 'terms' => array(), 383 ), 384 ) ); 447 $tq = new WP_Tax_Query( 448 array( 449 'relation' => 'OR', 450 array( 451 'taxonomy' => 'wptests_tax', 452 'field' => 'term_id', 453 'operator' => 'NOT IN', 454 'terms' => array(), 455 ), 456 ) 457 ); 385 458 386 459 global $wpdb; 387 460 $expected = array( 388 'join' => '',461 'join' => '', 389 462 'where' => '', 390 463 ); … … 401 474 register_taxonomy( 'wptests_tax', 'post' ); 402 475 403 $tq = new WP_Tax_Query( array( 404 'relation' => 'OR', 405 array( 406 'taxonomy' => 'wptests_tax', 407 'field' => 'term_id', 408 'operator' => 'AND', 409 'terms' => array(), 410 ), 411 ) ); 476 $tq = new WP_Tax_Query( 477 array( 478 'relation' => 'OR', 479 array( 480 'taxonomy' => 'wptests_tax', 481 'field' => 'term_id', 482 'operator' => 'AND', 483 'terms' => array(), 484 ), 485 ) 486 ); 412 487 413 488 global $wpdb; 414 489 $expected = array( 415 'join' => '',490 'join' => '', 416 491 'where' => '', 417 492 );
Note: See TracChangeset
for help on using the changeset viewer.