mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 07:40:07 +00:00
Query: Validate relation in WP_Date_Query.
Props dd32, johnjamesjacoby, martinkrcho, ehtis, paulkevan, peterwilsoncc. git-svn-id: https://develop.svn.wordpress.org/trunk@54530 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -335,6 +335,7 @@ class Tests_Term_Tax_Query extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* @ticket 18105
|
||||
* @covers WP_Tax_Query::get_sql
|
||||
*/
|
||||
public function test_get_sql_relation_and_operator_in() {
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
@@ -381,11 +382,17 @@ class Tests_Term_Tax_Query extends WP_UnitTestCase {
|
||||
|
||||
$this->assertSame( 3, substr_count( $sql['join'], 'JOIN' ) );
|
||||
|
||||
// Checking number of occurrences of AND while skipping the one at the beginning.
|
||||
$this->assertSame( 2, substr_count( substr( $sql['where'], 5 ), 'AND' ), 'SQL query does not contain expected number conditions joined by operator AND.' );
|
||||
|
||||
$this->assertStringNotContainsString( 'OR', $sql['where'], 'SQL query contains conditions joined by operator OR.' );
|
||||
|
||||
_unregister_taxonomy( 'wptests_tax' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 18105
|
||||
* @covers WP_Tax_Query::get_sql
|
||||
*/
|
||||
public function test_get_sql_nested_relation_or_operator_in() {
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
@@ -434,6 +441,8 @@ class Tests_Term_Tax_Query extends WP_UnitTestCase {
|
||||
$sql = $tq->get_sql( $wpdb->posts, 'ID' );
|
||||
|
||||
$this->assertSame( 2, substr_count( $sql['join'], 'JOIN' ) );
|
||||
$this->assertSame( 2, substr_count( $sql['where'], 'OR' ), 'SQL query does not contain expected number conditions joined by operator OR.' );
|
||||
$this->assertStringNotContainsString( 'AND', substr( $sql['where'], 5 ), 'SQL query contains conditions joined by operator AND.' );
|
||||
|
||||
_unregister_taxonomy( 'wptests_tax' );
|
||||
}
|
||||
@@ -495,4 +504,60 @@ class Tests_Term_Tax_Query extends WP_UnitTestCase {
|
||||
|
||||
_unregister_taxonomy( 'wptests_tax' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 18105
|
||||
* @covers WP_Tax_Query::get_sql
|
||||
*/
|
||||
public function test_get_sql_relation_unsupported() {
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
|
||||
$t1 = self::factory()->term->create(
|
||||
array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
)
|
||||
);
|
||||
$t2 = self::factory()->term->create(
|
||||
array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
)
|
||||
);
|
||||
$t3 = self::factory()->term->create(
|
||||
array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
)
|
||||
);
|
||||
|
||||
$tq = new WP_Tax_Query(
|
||||
array(
|
||||
'relation' => 'UNSUPPORTED',
|
||||
array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
'field' => 'term_id',
|
||||
'terms' => $t1,
|
||||
),
|
||||
array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
'field' => 'term_id',
|
||||
'terms' => $t2,
|
||||
),
|
||||
array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
'field' => 'term_id',
|
||||
'terms' => $t3,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
global $wpdb;
|
||||
$sql = $tq->get_sql( $wpdb->posts, 'ID' );
|
||||
|
||||
// Checking number of occurrences of AND while skipping the one at the beginning.
|
||||
$this->assertSame( 2, substr_count( substr( $sql['where'], 5 ), 'AND' ), 'SQL query does not contain expected number conditions joined by operator AND.' );
|
||||
|
||||
$this->assertStringNotContainsString( 'UNSUPPORTED', $sql['where'], 'SQL query contains unsupported relation operator.' );
|
||||
$this->assertStringNotContainsString( 'OR', $sql['where'], 'SQL query contains conditions joined by operator OR.' );
|
||||
|
||||
_unregister_taxonomy( 'wptests_tax' );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user