Multisite: Add search column support to WP_Site_Query.

`domain` and/or `path` can be used to specify which column(s) should be searched.

See #35791.


git-svn-id: https://develop.svn.wordpress.org/trunk@37735 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jeremy Felt
2016-06-16 23:08:30 +00:00
parent 0cda9e306c
commit 3d56328372
2 changed files with 110 additions and 5 deletions

View File

@@ -470,6 +470,84 @@ class Tests_Multisite_Site_Query extends WP_UnitTestCase {
$this->assertEquals( $expected, $found );
}
public function test_wp_site_query_by_search_with_text_in_path_exclude_domain_from_search() {
$q = new WP_Site_Query();
$found = $q->query( array(
'fields' => 'ids',
'search' => 'make',
'search_columns' => array( 'path' ),
) );
$expected = array(
self::$site_ids['www.w.org/make/'],
);
$this->assertEquals( $expected, $found );
}
public function test_wp_site_query_by_search_with_text_in_domain_exclude_path_from_search() {
$q = new WP_Site_Query();
$found = $q->query( array(
'fields' => 'ids',
'search' => 'make',
'search_columns' => array( 'domain' ),
) );
$expected = array(
self::$site_ids['make.wordpress.org/'],
self::$site_ids['make.wordpress.org/foo/'],
);
$this->assertEquals( $expected, $found );
}
public function test_wp_site_query_by_search_with_wildcard_in_text() {
$q = new WP_Site_Query();
$found = $q->query( array(
'fields' => 'ids',
'search' => 'm*ke',
) );
$expected = array(
self::$site_ids['www.w.org/make/'],
self::$site_ids['make.wordpress.org/'],
self::$site_ids['make.wordpress.org/foo/'],
);
$this->assertEqualSets( $expected, $found );
}
public function test_wp_site_query_by_search_with_wildcard_in_text_exclude_path_from_search() {
$q = new WP_Site_Query();
$found = $q->query( array(
'fields' => 'ids',
'search' => 'm*ke',
'search_columns' => array( 'domain' ),
) );
$expected = array(
self::$site_ids['make.wordpress.org/'],
self::$site_ids['make.wordpress.org/foo/'],
);
$this->assertEqualSets( $expected, $found );
}
public function test_wp_site_query_by_search_with_wildcard_in_text_exclude_domain_from_search() {
$q = new WP_Site_Query();
$found = $q->query( array(
'fields' => 'ids',
'search' => 'm*ke',
'search_columns' => array( 'path' ),
) );
$expected = array(
self::$site_ids['www.w.org/make/'],
);
$this->assertEqualSets( $expected, $found );
}
}
endif;