Added tests
This commit is contained in:
parent
08b08e5619
commit
071d913b0f
|
@ -321,11 +321,11 @@ class DataStore extends ReportsDataStore implements DataStoreInterface {
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( ! empty( $query_args['filter_empty'] ) ) {
|
if ( ! empty( $query_args['filter_empty'] ) ) {
|
||||||
$fields_to_filter_by = array_intersect( $query_args['filter_empty'], $filter_empty_params );
|
$fields_to_filter_by = array_intersect( $query_args['filter_empty'], $filter_empty_params );
|
||||||
if ( in_array( 'name', $fields_to_filter_by, true ) ) {
|
if ( in_array( 'name', $fields_to_filter_by, true ) ) {
|
||||||
$fields_to_filter_by = array_diff( $fields_to_filter_by, array( 'name' ) );
|
$fields_to_filter_by = array_diff( $fields_to_filter_by, array( 'name' ) );
|
||||||
$fields_to_filter_by[] = "CONCAT_WS( ' ', first_name, last_name )";
|
$fields_to_filter_by[] = "CONCAT_WS( ' ', first_name, last_name )";
|
||||||
}
|
}
|
||||||
$fields_with_not_condition = array_map(
|
$fields_with_not_condition = array_map(
|
||||||
function ( $field ) {
|
function ( $field ) {
|
||||||
return $field . ' <> \'\'';
|
return $field . ' <> \'\'';
|
||||||
|
|
|
@ -334,6 +334,84 @@ class WC_Admin_Tests_API_Reports_Customers extends WC_REST_Unit_Test_Case {
|
||||||
$this->assertEquals( 200, $response->get_status() );
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
$this->assertCount( 1, $reports );
|
$this->assertCount( 1, $reports );
|
||||||
$this->assertEquals( $test_customers[0]->get_id(), $reports[0]['user_id'] );
|
$this->assertEquals( $test_customers[0]->get_id(), $reports[0]['user_id'] );
|
||||||
|
|
||||||
|
// Test filter_empty param by name
|
||||||
|
$request->set_query_params(
|
||||||
|
array(
|
||||||
|
'filter_empty' => array('name'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = $this->server->dispatch( $request );
|
||||||
|
$reports = $response->get_data();
|
||||||
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
$this->assertCount( 10, $reports );
|
||||||
|
|
||||||
|
// Test filter_empty param by name and email
|
||||||
|
$request->set_query_params(
|
||||||
|
array(
|
||||||
|
'filter_empty' => array('name', 'email'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
$this->assertCount( 10, $reports );
|
||||||
|
|
||||||
|
// Test filter_empty param by name and email
|
||||||
|
$request->set_query_params(
|
||||||
|
array(
|
||||||
|
'filter_empty' => array('name', 'country'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
$this->assertCount( 10, $reports );
|
||||||
|
|
||||||
|
// Test filter_empty param by state
|
||||||
|
$request->set_query_params(
|
||||||
|
array(
|
||||||
|
'filter_empty' => array('state')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
$this->assertCount( 10, $reports );
|
||||||
|
|
||||||
|
// Test filter_empty param by state
|
||||||
|
$request->set_query_params(
|
||||||
|
array(
|
||||||
|
'filter_empty' => array('postcode'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
$this->assertCount( 10, $reports );
|
||||||
|
|
||||||
|
$customer = WC_Helper_Customer::create_customer( "customer11", 'password', "" );
|
||||||
|
$customer->set_postcode(null);
|
||||||
|
$customer->save();
|
||||||
|
|
||||||
|
$request->set_query_params(
|
||||||
|
array(
|
||||||
|
'filter_empty' => array('postcode'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
$this->assertCount( 10, $reports );
|
||||||
|
|
||||||
|
// Test filter_empty param by email
|
||||||
|
$request->set_query_params(
|
||||||
|
array(
|
||||||
|
'filter_empty' => array('email'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
$this->assertCount( 10, $reports );
|
||||||
|
|
||||||
|
// Test filter_empty param by name
|
||||||
|
$request->set_query_params(
|
||||||
|
array(
|
||||||
|
'filter_empty' => array('name'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->assertEquals( 200, $response->get_status() );
|
||||||
|
$this->assertCount( 10, $reports );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue