mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Introduce description__like arg to get_terms(). Make description__like and name__like perform LIKEs with a wildcard on both sides of passed string. Previously, strings had to match the beginning of the name, so searching for burrito in This is a burrito would fail. Adds unit tests.
Props aaroncampbell for the original patch, 5 years ago. Fixes #8214. git-svn-id: https://develop.svn.wordpress.org/trunk@25241 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -150,4 +150,33 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
|
||||
$terms = get_terms( 'post_tag', array( 'hide_empty' => false, 'search' => 'bur', 'fields' => 'ids' ) );
|
||||
$this->assertEqualSets( array( $term_id1, $term_id2 ), $terms );
|
||||
}
|
||||
|
||||
function test_get_terms_like() {
|
||||
$term_id1 = $this->factory->tag->create( array( 'name' => 'burrito', 'description' => 'This is a burrito.' ) );
|
||||
$term_id2 = $this->factory->tag->create( array( 'name' => 'taco', 'description' => 'Burning man.' ) );
|
||||
|
||||
$terms = get_terms( 'post_tag', array( 'hide_empty' => false, 'name__like' => 'bur', 'fields' => 'ids' ) );
|
||||
$this->assertEqualSets( array( $term_id1 ), $terms );
|
||||
|
||||
$terms2 = get_terms( 'post_tag', array( 'hide_empty' => false, 'description__like' => 'bur', 'fields' => 'ids' ) );
|
||||
$this->assertEqualSets( array( $term_id1, $term_id2 ), $terms2 );
|
||||
|
||||
$terms3 = get_terms( 'post_tag', array( 'hide_empty' => false, 'name__like' => 'Bur', 'fields' => 'ids' ) );
|
||||
$this->assertEqualSets( array( $term_id1 ), $terms3 );
|
||||
|
||||
$terms4 = get_terms( 'post_tag', array( 'hide_empty' => false, 'description__like' => 'Bur', 'fields' => 'ids' ) );
|
||||
$this->assertEqualSets( array( $term_id1, $term_id2 ), $terms4 );
|
||||
|
||||
$terms5 = get_terms( 'post_tag', array( 'hide_empty' => false, 'name__like' => 'ENCHILADA', 'fields' => 'ids' ) );
|
||||
$this->assertEmpty( $terms5 );
|
||||
|
||||
$terms6 = get_terms( 'post_tag', array( 'hide_empty' => false, 'description__like' => 'ENCHILADA', 'fields' => 'ids' ) );
|
||||
$this->assertEmpty( $terms6 );
|
||||
|
||||
$terms7 = get_terms( 'post_tag', array( 'hide_empty' => false, 'name__like' => 'o', 'fields' => 'ids' ) );
|
||||
$this->assertEqualSets( array( $term_id1, $term_id2 ), $terms7 );
|
||||
|
||||
$terms8 = get_terms( 'post_tag', array( 'hide_empty' => false, 'description__like' => '.', 'fields' => 'ids' ) );
|
||||
$this->assertEqualSets( array( $term_id1, $term_id2 ), $terms8 );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user