mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Tests: Make sure the correct query is tested for term limits in taxonomy queries.
By hooking into `terms_pre_query` after the fixture posts and terms are created but before the actual taxonomy query runs, we ensure that the correct SQL query from `WP_Term_Query::get_terms()` is tested for requested term limits, rather than the one initiated from `wp_insert_post()` or `wp_insert_term()` via `term_exists()`. Follow-up to [52921], [53037]. Props david.binda. Fixes #57342. git-svn-id: https://develop.svn.wordpress.org/trunk@55460 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
8417a97deb
commit
6eeeeaaea5
@ -1628,8 +1628,6 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase {
|
||||
* @covers WP_Tax_Query::transform_query
|
||||
*/
|
||||
public function test_tax_terms_should_limit_query() {
|
||||
$filter = new MockAction();
|
||||
add_filter( 'terms_pre_query', array( $filter, 'filter' ), 10, 2 );
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
$name = 'foobar';
|
||||
$t = self::factory()->term->create(
|
||||
@ -1642,6 +1640,9 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase {
|
||||
$p = self::factory()->post->create();
|
||||
wp_set_object_terms( $p, array( $t ), 'wptests_tax' );
|
||||
|
||||
$filter = new MockAction();
|
||||
add_filter( 'terms_pre_query', array( $filter, 'filter' ), 10, 2 );
|
||||
|
||||
$q = new WP_Query(
|
||||
array(
|
||||
'fields' => 'ids',
|
||||
@ -1656,7 +1657,7 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$filter_args = $filter->get_args();
|
||||
$query = $filter_args[1][1]->request;
|
||||
$query = $filter_args[0][1]->request;
|
||||
|
||||
$this->assertSameSets( array( $p ), $q->posts );
|
||||
$this->assertStringContainsString( 'LIMIT 1', $query );
|
||||
@ -1668,8 +1669,6 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase {
|
||||
* @covers WP_Tax_Query::transform_query
|
||||
*/
|
||||
public function test_tax_terms_should_limit_query_to_one() {
|
||||
$filter = new MockAction();
|
||||
add_filter( 'terms_pre_query', array( $filter, 'filter' ), 10, 2 );
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
$name = 'foobar';
|
||||
$t = self::factory()->term->create(
|
||||
@ -1682,6 +1681,9 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase {
|
||||
$p = self::factory()->post->create();
|
||||
wp_set_object_terms( $p, array( $t ), 'wptests_tax' );
|
||||
|
||||
$filter = new MockAction();
|
||||
add_filter( 'terms_pre_query', array( $filter, 'filter' ), 10, 2 );
|
||||
|
||||
$q = new WP_Query(
|
||||
array(
|
||||
'fields' => 'ids',
|
||||
@ -1696,7 +1698,7 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$filter_args = $filter->get_args();
|
||||
$query = $filter_args[1][1]->request;
|
||||
$query = $filter_args[0][1]->request;
|
||||
|
||||
$this->assertSameSets( array( $p ), $q->posts );
|
||||
$this->assertStringContainsString( 'LIMIT 1', $query );
|
||||
@ -1708,8 +1710,6 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase {
|
||||
* @covers WP_Tax_Query::transform_query
|
||||
*/
|
||||
public function test_hierarchical_taxonomies_do_not_limit_query() {
|
||||
$filter = new MockAction();
|
||||
add_filter( 'terms_pre_query', array( $filter, 'filter' ), 10, 2 );
|
||||
register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );
|
||||
$name = 'foobar';
|
||||
$t = self::factory()->term->create(
|
||||
@ -1722,6 +1722,9 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase {
|
||||
$p = self::factory()->post->create();
|
||||
wp_set_object_terms( $p, array( $t ), 'wptests_tax' );
|
||||
|
||||
$filter = new MockAction();
|
||||
add_filter( 'terms_pre_query', array( $filter, 'filter' ), 10, 2 );
|
||||
|
||||
$q = new WP_Query(
|
||||
array(
|
||||
'fields' => 'ids',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user