Changeset 50944
- Timestamp:
- 05/21/2021 06:28:59 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/blocks/block.php
r50450 r50944 414 414 } 415 415 416 /** 417 * @ticket 52991 418 */ 419 public function test_build_query_vars_from_query_block() { 420 $this->registry->register( 421 'core/example', 422 array( 'uses_context' => array( 'query' ) ) 423 ); 424 425 $parsed_blocks = parse_blocks( '<!-- wp:example {"ok":true} -->a<!-- wp:example /-->b<!-- /wp:example -->' ); 426 $parsed_block = $parsed_blocks[0]; 427 $context = array( 428 'query' => array( 429 'postType' => 'page', 430 'exclude' => array( 1, 2 ), 431 'categoryIds' => array( 56 ), 432 'orderBy' => 'title', 433 'tagIds' => array( 3, 11, 10 ), 434 ), 435 ); 436 $block = new WP_Block( $parsed_block, $context, $this->registry ); 437 $query = construct_wp_query_args( $block, 1 ); 438 439 $this->assertSame( 440 $query, 441 array( 442 'post_type' => 'page', 443 'order' => 'DESC', 444 'orderby' => 'title', 445 'post__not_in' => array( 1, 2 ), 446 'category__in' => array( 56 ), 447 'tag__in' => array( 3, 11, 10 ), 448 ) 449 ); 450 } 451 452 /** 453 * @ticket 52991 454 */ 455 public function test_build_query_vars_from_query_block_no_context() { 456 $this->registry->register( 'core/example', array() ); 457 458 $parsed_blocks = parse_blocks( '<!-- wp:example {"ok":true} -->a<!-- wp:example /-->b<!-- /wp:example -->' ); 459 $parsed_block = $parsed_blocks[0]; 460 $block_no_context = new WP_Block( $parsed_block, array(), $this->registry ); 461 $query = construct_wp_query_args( $block_no_context, 1 ); 462 463 $this->assertSame( 464 $query, 465 array( 466 'post_type' => 'post', 467 'order' => 'DESC', 468 'orderby' => 'date', 469 'post__not_in' => array(), 470 ) 471 ); 472 } 473 474 /** 475 * @ticket 52991 476 */ 477 public function test_build_query_vars_from_query_block_first_page() { 478 $this->registry->register( 479 'core/example', 480 array( 'uses_context' => array( 'query' ) ) 481 ); 482 483 $parsed_blocks = parse_blocks( '<!-- wp:example {"ok":true} -->a<!-- wp:example /-->b<!-- /wp:example -->' ); 484 $parsed_block = $parsed_blocks[0]; 485 $context = array( 486 'query' => array( 487 'perPage' => 2, 488 'offset' => 0, 489 ), 490 ); 491 $block = new WP_Block( $parsed_block, $context, $this->registry ); 492 $query = construct_wp_query_args( $block, 1 ); 493 494 $this->assertSame( 495 $query, 496 array( 497 'post_type' => 'post', 498 'order' => 'DESC', 499 'orderby' => 'date', 500 'post__not_in' => array(), 501 'offset' => 0, 502 'posts_per_page' => 2, 503 ) 504 ); 505 } 506 507 /** 508 * @ticket 52991 509 */ 510 public function test_build_query_vars_from_query_block_page_no_offset() { 511 $this->registry->register( 512 'core/example', 513 array( 'uses_context' => array( 'query' ) ) 514 ); 515 516 $parsed_blocks = parse_blocks( '<!-- wp:example {"ok":true} -->a<!-- wp:example /-->b<!-- /wp:example -->' ); 517 $parsed_block = $parsed_blocks[0]; 518 $context = array( 519 'query' => array( 520 'perPage' => 5, 521 'offset' => 0, 522 ), 523 ); 524 $block = new WP_Block( $parsed_block, $context, $this->registry ); 525 $query = construct_wp_query_args( $block, 3 ); 526 $this->assertSame( 527 $query, 528 array( 529 'post_type' => 'post', 530 'order' => 'DESC', 531 'orderby' => 'date', 532 'post__not_in' => array(), 533 'offset' => 10, 534 'posts_per_page' => 5, 535 ) 536 ); 537 } 538 539 /** 540 * @ticket 52991 541 */ 542 public function test_build_query_vars_from_query_block_page_with_offset() { 543 $this->registry->register( 544 'core/example', 545 array( 'uses_context' => array( 'query' ) ) 546 ); 547 548 $parsed_blocks = parse_blocks( '<!-- wp:example {"ok":true} -->a<!-- wp:example /-->b<!-- /wp:example -->' ); 549 $parsed_block = $parsed_blocks[0]; 550 $context = array( 551 'query' => array( 552 'perPage' => 5, 553 'offset' => 2, 554 ), 555 ); 556 $block = new WP_Block( $parsed_block, $context, $this->registry ); 557 $query = construct_wp_query_args( $block, 3 ); 558 $this->assertSame( 559 $query, 560 array( 561 'post_type' => 'post', 562 'order' => 'DESC', 563 'orderby' => 'date', 564 'post__not_in' => array(), 565 'offset' => 12, 566 'posts_per_page' => 5, 567 ) 568 ); 569 } 416 570 }
Note: See TracChangeset
for help on using the changeset viewer.