fix: tests
This commit is contained in:
parent
0b562f0797
commit
c45d539852
|
@ -129,7 +129,7 @@ class Search_Engine {
|
||||||
} else {
|
} else {
|
||||||
$searchQuery .= "{$seperator}($wpdb->posts.post_title LIKE {$esc_term} OR $wpdb->posts.post_content LIKE {$esc_term})";
|
$searchQuery .= "{$seperator}($wpdb->posts.post_title LIKE {$esc_term} OR $wpdb->posts.post_content LIKE {$esc_term})";
|
||||||
}
|
}
|
||||||
$seperator = ' AND ';
|
$seperator = ' OR ';
|
||||||
}
|
}
|
||||||
return empty($searchQuery) ? false : "($searchQuery)";
|
return empty($searchQuery) ? false : "($searchQuery)";
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ class Search_Engine {
|
||||||
foreach ( $terms as $term ) {
|
foreach ( $terms as $term ) {
|
||||||
$esc_term = $wpdb->prepare("%s", $not_exact ? "%".$term."%" : $term);
|
$esc_term = $wpdb->prepare("%s", $not_exact ? "%".$term."%" : $term);
|
||||||
$search_tax_query .= "{$seperator}(tter.name LIKE {$esc_term})";
|
$search_tax_query .= "{$seperator}(tter.name LIKE {$esc_term})";
|
||||||
$seperator = ' AND ';
|
$seperator = ' OR ';
|
||||||
}
|
}
|
||||||
if (empty($search_tax_query)) return '';
|
if (empty($search_tax_query)) return '';
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ class Search_Engine {
|
||||||
foreach ( $terms as $term ) {
|
foreach ( $terms as $term ) {
|
||||||
$esc_term = $wpdb->prepare("%s", $not_exact ? "%".$term."%" : $term);
|
$esc_term = $wpdb->prepare("%s", $not_exact ? "%".$term."%" : $term);
|
||||||
$search_meta_query .= "{$seperator}(m.meta_value LIKE {$esc_term})";
|
$search_meta_query .= "{$seperator}(m.meta_value LIKE {$esc_term})";
|
||||||
$seperator = ' AND ';
|
$seperator = ' OR ';
|
||||||
}
|
}
|
||||||
if ( empty($search_meta_query) ) return '';
|
if ( empty($search_meta_query) ) return '';
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ class Search_Engine {
|
||||||
return "EXISTS (
|
return "EXISTS (
|
||||||
SELECT m.post_id
|
SELECT m.post_id
|
||||||
FROM $wpdb->postmeta m $join
|
FROM $wpdb->postmeta m $join
|
||||||
WHERE ( $wpdb->posts.ID = m.post_id AND $search_meta_query )
|
WHERE ( $wpdb->posts.ID = m.post_id AND ($search_meta_query) )
|
||||||
)";
|
)";
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
|
|
|
@ -172,7 +172,7 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase {
|
||||||
$this->assertEquals($collectionB->get_name(), $data1[0]['name']);
|
$this->assertEquals($collectionB->get_name(), $data1[0]['name']);
|
||||||
|
|
||||||
// Search collection with a specific keyword and not other keyword
|
// Search collection with a specific keyword and not other keyword
|
||||||
$search_query = ['search' => 'Collection -A'];
|
$search_query = ['search' => 'Collection -A', 'sentence' => false];
|
||||||
|
|
||||||
$search_request = new \WP_REST_Request('GET', $this->namespace . '/collections');
|
$search_request = new \WP_REST_Request('GET', $this->namespace . '/collections');
|
||||||
|
|
||||||
|
|
|
@ -217,7 +217,15 @@ class TAINACAN_REST_Search extends TAINACAN_UnitApiTestCase {
|
||||||
public function test_search() {
|
public function test_search() {
|
||||||
|
|
||||||
$search_collection_poemas = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $this->collection_poemas->get_id() . '/items');
|
$search_collection_poemas = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $this->collection_poemas->get_id() . '/items');
|
||||||
$search_query = ['search' => '"Vinícius de Moraes"'];
|
$search_query = ['search' => '"Vinícius de Moraes"', 'sentence' => false];
|
||||||
|
$search_collection_poemas->set_query_params($search_query);
|
||||||
|
$search_response = $this->server->dispatch($search_collection_poemas);
|
||||||
|
$items = $search_response->get_data()['items'];
|
||||||
|
|
||||||
|
$this->assertCount(2, $items);
|
||||||
|
|
||||||
|
$search_collection_poemas = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $this->collection_poemas->get_id() . '/items');
|
||||||
|
$search_query = ['search' => 'Vinícius de Moraes', 'sentence' => true];
|
||||||
$search_collection_poemas->set_query_params($search_query);
|
$search_collection_poemas->set_query_params($search_query);
|
||||||
$search_response = $this->server->dispatch($search_collection_poemas);
|
$search_response = $this->server->dispatch($search_collection_poemas);
|
||||||
$items = $search_response->get_data()['items'];
|
$items = $search_response->get_data()['items'];
|
||||||
|
@ -225,7 +233,15 @@ class TAINACAN_REST_Search extends TAINACAN_UnitApiTestCase {
|
||||||
$this->assertCount(2, $items);
|
$this->assertCount(2, $items);
|
||||||
|
|
||||||
$search_collection_frase = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $this->collection_frases->get_id() . '/items');
|
$search_collection_frase = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $this->collection_frases->get_id() . '/items');
|
||||||
$search_query = ['search' => '"Guimarães Rosa"'];
|
$search_query = ['search' => '"Guimarães Rosa"', 'sentence' => false];
|
||||||
|
$search_collection_frase->set_query_params($search_query);
|
||||||
|
$search_response = $this->server->dispatch($search_collection_frase);
|
||||||
|
$items = $search_response->get_data()['items'];
|
||||||
|
|
||||||
|
$this->assertCount(2, $items);
|
||||||
|
|
||||||
|
$search_collection_frase = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $this->collection_frases->get_id() . '/items');
|
||||||
|
$search_query = ['search' => 'Guimarães Rosa', 'sentence' => true];
|
||||||
$search_collection_frase->set_query_params($search_query);
|
$search_collection_frase->set_query_params($search_query);
|
||||||
$search_response = $this->server->dispatch($search_collection_frase);
|
$search_response = $this->server->dispatch($search_collection_frase);
|
||||||
$items = $search_response->get_data()['items'];
|
$items = $search_response->get_data()['items'];
|
||||||
|
@ -234,7 +250,7 @@ class TAINACAN_REST_Search extends TAINACAN_UnitApiTestCase {
|
||||||
|
|
||||||
|
|
||||||
$search_items = new \WP_REST_Request('GET', $this->namespace . '/items');
|
$search_items = new \WP_REST_Request('GET', $this->namespace . '/items');
|
||||||
$search_query = ['search' => 'texto'];
|
$search_query = ['search' => 'texto', 'sentence' => false];
|
||||||
$search_items->set_query_params($search_query);
|
$search_items->set_query_params($search_query);
|
||||||
$search_response = $this->server->dispatch($search_items);
|
$search_response = $this->server->dispatch($search_items);
|
||||||
$items = $search_response->get_data()['items'];
|
$items = $search_response->get_data()['items'];
|
||||||
|
@ -242,7 +258,7 @@ class TAINACAN_REST_Search extends TAINACAN_UnitApiTestCase {
|
||||||
$this->assertCount(4, $items);
|
$this->assertCount(4, $items);
|
||||||
|
|
||||||
$search_items = new \WP_REST_Request('GET', $this->namespace . '/items');
|
$search_items = new \WP_REST_Request('GET', $this->namespace . '/items');
|
||||||
$search_query = ['search' => 'texto poesia'];
|
$search_query = ['search' => 'texto poesia', 'sentence' => false];
|
||||||
$search_items->set_query_params($search_query);
|
$search_items->set_query_params($search_query);
|
||||||
$search_response = $this->server->dispatch($search_items);
|
$search_response = $this->server->dispatch($search_items);
|
||||||
$items = $search_response->get_data()['items'];
|
$items = $search_response->get_data()['items'];
|
||||||
|
@ -250,7 +266,7 @@ class TAINACAN_REST_Search extends TAINACAN_UnitApiTestCase {
|
||||||
$this->assertCount(4, $items);
|
$this->assertCount(4, $items);
|
||||||
|
|
||||||
$search_items = new \WP_REST_Request('GET', $this->namespace . '/items');
|
$search_items = new \WP_REST_Request('GET', $this->namespace . '/items');
|
||||||
$search_query = ['search' => '"texto poesia"'];
|
$search_query = ['search' => '"texto poesia"', 'sentence' => false];
|
||||||
$search_items->set_query_params($search_query);
|
$search_items->set_query_params($search_query);
|
||||||
$search_response = $this->server->dispatch($search_items);
|
$search_response = $this->server->dispatch($search_items);
|
||||||
$items = $search_response->get_data()['items'];
|
$items = $search_response->get_data()['items'];
|
||||||
|
@ -258,15 +274,15 @@ class TAINACAN_REST_Search extends TAINACAN_UnitApiTestCase {
|
||||||
$this->assertCount(1, $items);
|
$this->assertCount(1, $items);
|
||||||
|
|
||||||
$search_items = new \WP_REST_Request('GET', $this->namespace . '/items');
|
$search_items = new \WP_REST_Request('GET', $this->namespace . '/items');
|
||||||
$search_query = ['search' => '"texto poesia" sagarana'];
|
$search_query = ['search' => '"texto poesia" sagarana', 'sentence' => false];
|
||||||
$search_items->set_query_params($search_query);
|
$search_items->set_query_params($search_query);
|
||||||
$search_response = $this->server->dispatch($search_items);
|
$search_response = $this->server->dispatch($search_items);
|
||||||
$items = $search_response->get_data()['items'];
|
$items = $search_response->get_data()['items'];
|
||||||
|
|
||||||
$this->assertCount(2, $items);
|
$this->assertCount(2, $items);
|
||||||
|
|
||||||
|
|
||||||
$search_items = new \WP_REST_Request('GET', $this->namespace . '/items');
|
$search_items = new \WP_REST_Request('GET', $this->namespace . '/items');
|
||||||
$search_query = ['search' => 'infinito dure'];
|
$search_query = ['search' => 'infinito dure', 'sentence' => false];
|
||||||
$search_items->set_query_params($search_query);
|
$search_items->set_query_params($search_query);
|
||||||
$search_response = $this->server->dispatch($search_items);
|
$search_response = $this->server->dispatch($search_items);
|
||||||
$items = $search_response->get_data()['items'];
|
$items = $search_response->get_data()['items'];
|
||||||
|
|
Loading…
Reference in New Issue