mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Editor: Backport build_query_vars_from_query_block changes from Gutenberg repository.
This changeset backports changes from the following Gutenberg pull requests: - [https://github.com/WordPress/gutenberg/pull/43590 gutenberg#43590] Add a filter to `build_query_vars_from_query_block` - [https://github.com/WordPress/gutenberg/pull/40933 gutenberg#40933] Block Library - Query Loop: Add parents filter Props ntsekouras, bernhard-reiter. See #56467. git-svn-id: https://develop.svn.wordpress.org/trunk@54175 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -437,6 +437,7 @@ class Tests_Blocks_wpBlock extends WP_UnitTestCase {
|
||||
'categoryIds' => array( 56 ),
|
||||
'orderBy' => 'title',
|
||||
'tagIds' => array( 3, 11, 10 ),
|
||||
'parents' => array( 1, 2 ),
|
||||
),
|
||||
);
|
||||
$block = new WP_Block( $parsed_block, $context, $this->registry );
|
||||
@@ -445,11 +446,11 @@ class Tests_Blocks_wpBlock extends WP_UnitTestCase {
|
||||
$this->assertSame(
|
||||
$query,
|
||||
array(
|
||||
'post_type' => 'page',
|
||||
'order' => 'DESC',
|
||||
'orderby' => 'title',
|
||||
'post__not_in' => array( 1, 2 ),
|
||||
'tax_query' => array(
|
||||
'post_type' => 'page',
|
||||
'order' => 'DESC',
|
||||
'orderby' => 'title',
|
||||
'post__not_in' => array( 1, 2 ),
|
||||
'tax_query' => array(
|
||||
array(
|
||||
'taxonomy' => 'category',
|
||||
'terms' => array( 56 ),
|
||||
@@ -461,6 +462,7 @@ class Tests_Blocks_wpBlock extends WP_UnitTestCase {
|
||||
'include_children' => false,
|
||||
),
|
||||
),
|
||||
'post_parent__in' => array( 1, 2 ),
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -584,6 +586,42 @@ class Tests_Blocks_wpBlock extends WP_UnitTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 56467
|
||||
*/
|
||||
public function test_query_loop_block_query_vars_filter() {
|
||||
$this->registry->register(
|
||||
'core/example',
|
||||
array( 'uses_context' => array( 'query' ) )
|
||||
);
|
||||
|
||||
$parsed_blocks = parse_blocks( '<!-- wp:example {"ok":true} -->a<!-- wp:example /-->b<!-- /wp:example -->' );
|
||||
$parsed_block = $parsed_blocks[0];
|
||||
$context = array(
|
||||
'query' => array(
|
||||
'postType' => 'page',
|
||||
'orderBy' => 'title',
|
||||
),
|
||||
);
|
||||
$block = new WP_Block( $parsed_block, $context, $this->registry );
|
||||
function filterQuery( $query, $block, $page ) {
|
||||
$query['post_type'] = 'book';
|
||||
return $query;
|
||||
}
|
||||
add_filter( 'query_loop_block_query_vars', 'filterQuery', 10, 3 );
|
||||
$query = build_query_vars_from_query_block( $block, 1 );
|
||||
remove_filter( 'query_loop_block_query_vars', 'filterQuery' );
|
||||
$this->assertSame(
|
||||
$query,
|
||||
array(
|
||||
'post_type' => 'book',
|
||||
'order' => 'DESC',
|
||||
'orderby' => 'title',
|
||||
'post__not_in' => array(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 52991
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user