Changeset 48937 for trunk/tests/phpunit/tests/meta/query.php
- Timestamp:
- 09/02/2020 12:35:36 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/meta/query.php
r47122 r48937 11 11 public function test_empty_meta_query_param() { 12 12 $query = new WP_Meta_Query(); 13 $this->assert Same( null,$query->relation );13 $this->assertNull( $query->relation ); 14 14 } 15 15 16 16 public function test_default_relation() { 17 17 $query = new WP_Meta_Query( array( array( 'key' => 'abc' ) ) ); 18 $this->assert Equals( 'AND', $query->relation );18 $this->assertSame( 'AND', $query->relation ); 19 19 } 20 20 … … 28 28 ); 29 29 30 $this->assert Equals( 'AND', $query->relation );30 $this->assertSame( 'AND', $query->relation ); 31 31 32 32 $query = new WP_Meta_Query( … … 37 37 ); 38 38 39 $this->assert Equals( 'OR', $query->relation );39 $this->assertSame( 'OR', $query->relation ); 40 40 } 41 41 … … 75 75 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID' ); 76 76 77 $this->assert Equals( 1, substr_count( $sql['join'], 'INNER JOIN' ) );77 $this->assertSame( 1, substr_count( $sql['join'], 'INNER JOIN' ) ); 78 78 79 79 // Also check mixing key and key => value. … … 93 93 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID' ); 94 94 95 $this->assert Equals( 1, substr_count( $sql['join'], 'INNER JOIN' ) );95 $this->assertSame( 1, substr_count( $sql['join'], 'INNER JOIN' ) ); 96 96 } 97 97 … … 121 121 'value' => 'baz', 122 122 ); 123 $this->assert Equals( $expected0, $query->queries[0] );123 $this->assertSame( $expected0, $query->queries[0] ); 124 124 125 125 $expected1 = array( 126 'relation' => 'OR',127 126 array( 128 127 'key' => 'foo1', … … 130 129 'value' => 'bar1', 131 130 ), 132 ); 133 $this->assertEquals( $expected1, $query->queries[1] ); 131 'relation' => 'OR', 132 ); 133 $this->assertSame( $expected1, $query->queries[1] ); 134 134 } 135 135 … … 177 177 // Just meta_value. 178 178 $expected = array( 179 array( 180 'key' => 'abc', 181 ), 179 182 'relation' => 'OR', 180 array(181 'key' => 'abc',182 ),183 183 ); 184 184 $query->parse_query_vars( … … 187 187 ) 188 188 ); 189 $this->assert Equals( $expected, $query->queries );189 $this->assertSame( $expected, $query->queries ); 190 190 191 191 // meta_key & meta_value. 192 192 $expected = array( 193 'relation' => 'OR',194 193 array( 195 194 'key' => 'abc', 196 195 'value' => 'def', 197 196 ), 197 'relation' => 'OR', 198 198 ); 199 199 $query->parse_query_vars( … … 203 203 ) 204 204 ); 205 $this->assert Equals( $expected, $query->queries );205 $this->assertSame( $expected, $query->queries ); 206 206 207 207 // meta_compare. 208 208 $expected = array( 209 'relation' => 'OR',210 209 array( 211 210 'key' => 'abc', 212 211 'compare' => '=>', 213 212 ), 213 'relation' => 'OR', 214 214 ); 215 215 $query->parse_query_vars( … … 219 219 ) 220 220 ); 221 $this->assert Equals( $expected, $query->queries );221 $this->assertSame( $expected, $query->queries ); 222 222 } 223 223 … … 227 227 public function test_get_cast_for_type() { 228 228 $query = new WP_Meta_Query(); 229 $this->assert Equals( 'BINARY', $query->get_cast_for_type( 'BINARY' ) );230 $this->assert Equals( 'CHAR', $query->get_cast_for_type( 'CHAR' ) );231 $this->assert Equals( 'DATE', $query->get_cast_for_type( 'DATE' ) );232 $this->assert Equals( 'DATETIME', $query->get_cast_for_type( 'DATETIME' ) );233 $this->assert Equals( 'SIGNED', $query->get_cast_for_type( 'SIGNED' ) );234 $this->assert Equals( 'UNSIGNED', $query->get_cast_for_type( 'UNSIGNED' ) );235 $this->assert Equals( 'TIME', $query->get_cast_for_type( 'TIME' ) );236 $this->assert Equals( 'SIGNED', $query->get_cast_for_type( 'NUMERIC' ) );237 $this->assert Equals( 'NUMERIC(10)', $query->get_cast_for_type( 'NUMERIC(10)' ) );238 $this->assert Equals( 'CHAR', $query->get_cast_for_type( 'NUMERIC( 10)' ) );239 $this->assert Equals( 'CHAR', $query->get_cast_for_type( 'NUMERIC( 10 )' ) );240 $this->assert Equals( 'NUMERIC(10, 5)', $query->get_cast_for_type( 'NUMERIC(10, 5)' ) );241 $this->assert Equals( 'CHAR', $query->get_cast_for_type( 'NUMERIC(10, 5)' ) );242 $this->assert Equals( 'NUMERIC(10,5)', $query->get_cast_for_type( 'NUMERIC(10,5)' ) );243 $this->assert Equals( 'CHAR', $query->get_cast_for_type( 'NUMERIC( 10, 5 )' ) );244 $this->assert Equals( 'CHAR', $query->get_cast_for_type( 'NUMERIC(10, 5 )' ) );245 $this->assert Equals( 'DECIMAL', $query->get_cast_for_type( 'DECIMAL' ) );246 $this->assert Equals( 'DECIMAL(10)', $query->get_cast_for_type( 'DECIMAL(10)' ) );247 $this->assert Equals( 'CHAR', $query->get_cast_for_type( 'DECIMAL( 10 )' ) );248 $this->assert Equals( 'CHAR', $query->get_cast_for_type( 'DECIMAL( 10)' ) );249 $this->assert Equals( 'CHAR', $query->get_cast_for_type( 'DECIMAL(10 )' ) );250 $this->assert Equals( 'DECIMAL(10, 5)', $query->get_cast_for_type( 'DECIMAL(10, 5)' ) );251 $this->assert Equals( 'DECIMAL(10,5)', $query->get_cast_for_type( 'DECIMAL(10,5)' ) );252 $this->assert Equals( 'CHAR', $query->get_cast_for_type( 'DECIMAL(10, 5)' ) );253 254 $this->assert Equals( 'CHAR', $query->get_cast_for_type() );255 $this->assert Equals( 'CHAR', $query->get_cast_for_type( 'ANYTHING ELSE' ) );229 $this->assertSame( 'BINARY', $query->get_cast_for_type( 'BINARY' ) ); 230 $this->assertSame( 'CHAR', $query->get_cast_for_type( 'CHAR' ) ); 231 $this->assertSame( 'DATE', $query->get_cast_for_type( 'DATE' ) ); 232 $this->assertSame( 'DATETIME', $query->get_cast_for_type( 'DATETIME' ) ); 233 $this->assertSame( 'SIGNED', $query->get_cast_for_type( 'SIGNED' ) ); 234 $this->assertSame( 'UNSIGNED', $query->get_cast_for_type( 'UNSIGNED' ) ); 235 $this->assertSame( 'TIME', $query->get_cast_for_type( 'TIME' ) ); 236 $this->assertSame( 'SIGNED', $query->get_cast_for_type( 'NUMERIC' ) ); 237 $this->assertSame( 'NUMERIC(10)', $query->get_cast_for_type( 'NUMERIC(10)' ) ); 238 $this->assertSame( 'CHAR', $query->get_cast_for_type( 'NUMERIC( 10)' ) ); 239 $this->assertSame( 'CHAR', $query->get_cast_for_type( 'NUMERIC( 10 )' ) ); 240 $this->assertSame( 'NUMERIC(10, 5)', $query->get_cast_for_type( 'NUMERIC(10, 5)' ) ); 241 $this->assertSame( 'CHAR', $query->get_cast_for_type( 'NUMERIC(10, 5)' ) ); 242 $this->assertSame( 'NUMERIC(10,5)', $query->get_cast_for_type( 'NUMERIC(10,5)' ) ); 243 $this->assertSame( 'CHAR', $query->get_cast_for_type( 'NUMERIC( 10, 5 )' ) ); 244 $this->assertSame( 'CHAR', $query->get_cast_for_type( 'NUMERIC(10, 5 )' ) ); 245 $this->assertSame( 'DECIMAL', $query->get_cast_for_type( 'DECIMAL' ) ); 246 $this->assertSame( 'DECIMAL(10)', $query->get_cast_for_type( 'DECIMAL(10)' ) ); 247 $this->assertSame( 'CHAR', $query->get_cast_for_type( 'DECIMAL( 10 )' ) ); 248 $this->assertSame( 'CHAR', $query->get_cast_for_type( 'DECIMAL( 10)' ) ); 249 $this->assertSame( 'CHAR', $query->get_cast_for_type( 'DECIMAL(10 )' ) ); 250 $this->assertSame( 'DECIMAL(10, 5)', $query->get_cast_for_type( 'DECIMAL(10, 5)' ) ); 251 $this->assertSame( 'DECIMAL(10,5)', $query->get_cast_for_type( 'DECIMAL(10,5)' ) ); 252 $this->assertSame( 'CHAR', $query->get_cast_for_type( 'DECIMAL(10, 5)' ) ); 253 254 $this->assertSame( 'CHAR', $query->get_cast_for_type() ); 255 $this->assertSame( 'CHAR', $query->get_cast_for_type( 'ANYTHING ELSE' ) ); 256 256 } 257 257 258 258 public function test_sanitize_query_single_query() { 259 259 $expected = array( 260 'relation' => 'OR',261 260 array( 262 261 'key' => 'foo', 263 262 'value' => 'bar', 264 263 ), 264 'relation' => 'OR', 265 265 ); 266 266 … … 275 275 ); 276 276 277 $this->assert Equals( $expected, $found );277 $this->assertSame( $expected, $found ); 278 278 } 279 279 280 280 public function test_sanitize_query_multiple_first_order_queries_relation_default() { 281 281 $expected = array( 282 'relation' => 'AND',283 282 array( 284 283 'key' => 'foo', … … 289 288 'value' => 'bar2', 290 289 ), 290 'relation' => 'AND', 291 291 ); 292 292 … … 305 305 ); 306 306 307 $this->assert Equals( $expected, $found );307 $this->assertSame( $expected, $found ); 308 308 } 309 309 310 310 public function test_sanitize_query_multiple_first_order_queries_relation_or() { 311 311 $expected = array( 312 'relation' => 'OR',313 312 array( 314 313 'key' => 'foo', … … 319 318 'value' => 'bar2', 320 319 ), 320 'relation' => 'OR', 321 321 ); 322 322 … … 324 324 $found = $q->sanitize_query( 325 325 array( 326 'relation' => 'OR',327 326 array( 328 327 'key' => 'foo', … … 333 332 'value' => 'bar2', 334 333 ), 335 ) 336 ); 337 338 $this->assertEquals( $expected, $found ); 334 'relation' => 'OR', 335 ) 336 ); 337 338 $this->assertSame( $expected, $found ); 339 339 } 340 340 341 341 public function test_sanitize_query_multiple_first_order_queries_relation_or_lowercase() { 342 342 $expected = array( 343 'relation' => 'OR',344 343 array( 345 344 'key' => 'foo', … … 350 349 'value' => 'bar2', 351 350 ), 351 'relation' => 'OR', 352 352 ); 353 353 … … 355 355 $found = $q->sanitize_query( 356 356 array( 357 'relation' => 'or',358 357 array( 359 358 'key' => 'foo', … … 364 363 'value' => 'bar2', 365 364 ), 366 ) 367 ); 368 369 $this->assertEquals( $expected, $found ); 365 'relation' => 'or', 366 ) 367 ); 368 369 $this->assertSame( $expected, $found ); 370 370 } 371 371 372 372 public function test_sanitize_query_multiple_first_order_queries_invalid_relation() { 373 373 $expected = array( 374 'relation' => 'AND',375 374 array( 376 375 'key' => 'foo', … … 381 380 'value' => 'bar2', 382 381 ), 382 'relation' => 'AND', 383 383 ); 384 384 … … 386 386 $found = $q->sanitize_query( 387 387 array( 388 'relation' => 'FOO',389 388 array( 390 389 'key' => 'foo', … … 395 394 'value' => 'bar2', 396 395 ), 397 ) 398 ); 399 400 $this->assertEquals( $expected, $found ); 396 'relation' => 'FOO', 397 ) 398 ); 399 400 $this->assertSame( $expected, $found ); 401 401 } 402 402 403 403 public function test_sanitize_query_single_query_which_is_a_nested_query() { 404 404 $expected = array( 405 'relation' => 'OR', 406 array( 407 'relation' => 'AND', 405 array( 408 406 array( 409 407 'key' => 'foo', … … 414 412 'value' => 'bar2', 415 413 ), 416 ), 414 'relation' => 'AND', 415 ), 416 'relation' => 'OR', 417 417 ); 418 418 … … 433 433 ); 434 434 435 $this->assert Equals( $expected, $found );435 $this->assertSame( $expected, $found ); 436 436 } 437 437 438 438 public function test_sanitize_query_multiple_nested_queries() { 439 439 $expected = array( 440 'relation' => 'OR', 441 array( 442 'relation' => 'AND', 440 array( 443 441 array( 444 442 'key' => 'foo', … … 449 447 'value' => 'bar2', 450 448 ), 451 ),452 array(453 449 'relation' => 'AND', 450 ), 451 array( 454 452 array( 455 453 'key' => 'foo3', … … 460 458 'value' => 'bar4', 461 459 ), 462 ), 460 'relation' => 'AND', 461 ), 462 'relation' => 'OR', 463 463 ); 464 464 … … 466 466 $found = $q->sanitize_query( 467 467 array( 468 'relation' => 'OR',469 468 array( 470 469 array( … … 487 486 ), 488 487 ), 489 ) 490 ); 491 492 $this->assertEquals( $expected, $found ); 488 'relation' => 'OR', 489 ) 490 ); 491 492 $this->assertSame( $expected, $found ); 493 493 } 494 494 … … 529 529 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); 530 530 531 $this->assert Equals( 3, substr_count( $sql['join'], 'JOIN' ) );531 $this->assertSame( 3, substr_count( $sql['join'], 'JOIN' ) ); 532 532 } 533 533 … … 549 549 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); 550 550 551 $this->assert Equals( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_value = ''" ) );551 $this->assertSame( 1, substr_count( $sql['where'], "$wpdb->postmeta.meta_value = ''" ) ); 552 552 } 553 553 … … 561 561 $query1 = new WP_Meta_Query( 562 562 array( 563 'relation' => 'OR',564 565 563 // Empty 'compare'. 566 564 array( … … 590 588 'value' => 'bar', 591 589 ), 590 591 'relation' => 'OR', 592 592 ) 593 593 ); … … 605 605 $query2 = new WP_Meta_Query( 606 606 array( 607 'relation' => 'AND',608 609 607 // Empty 'compare'. 610 608 array( … … 617 615 'compare' => '<', 618 616 ), 617 618 'relation' => 'AND', 619 619 ) 620 620 ); … … 888 888 $query = new WP_Meta_Query( 889 889 array( 890 'relation' => 'OR',891 890 array( 892 891 'key' => 'exclude', … … 898 897 'value' => '1', 899 898 ), 899 'relation' => 'OR', 900 900 ) 901 901 ); … … 911 911 $query = new WP_Meta_Query( 912 912 array( 913 'relation' => 'OR',914 913 array( 915 914 'key' => 'exclude', … … 921 920 'value' => '1', 922 921 ), 922 'relation' => 'OR', 923 923 ) 924 924 ); … … 937 937 $q = new WP_Meta_Query( 938 938 array( 939 'relation' => 'AND',940 939 array( 941 940 'key' => 'foo', … … 953 952 ), 954 953 ), 954 'relation' => 'AND', 955 955 ) 956 956 ); … … 965 965 $q = new WP_Meta_Query( 966 966 array( 967 'relation' => 'OR',968 967 array( 969 968 'key' => 'foo', … … 981 980 ), 982 981 ), 982 'relation' => 'OR', 983 983 ) 984 984 ); … … 993 993 $q = new WP_Meta_Query( 994 994 array( 995 'relation' => 'AND',996 995 array( 997 996 'key' => 'foo', … … 1009 1008 ), 1010 1009 ), 1010 'relation' => 'AND', 1011 1011 ) 1012 1012 );
Note: See TracChangeset
for help on using the changeset viewer.