get_meta should return empty array sometimes
This commit is contained in:
parent
c76c2d1a8d
commit
d5fd1e46ee
|
@ -239,7 +239,7 @@ abstract class WC_Data {
|
|||
public function get_meta( $key = '', $single = true, $context = 'view' ) {
|
||||
$this->maybe_read_meta_data();
|
||||
$array_keys = array_keys( wp_list_pluck( $this->get_meta_data(), 'key' ), $key );
|
||||
$value = '';
|
||||
$value = $single ? '' : array();
|
||||
|
||||
if ( ! empty( $array_keys ) ) {
|
||||
if ( $single ) {
|
||||
|
|
|
@ -120,6 +120,21 @@ class WC_Tests_CRUD_Data extends WC_Unit_Test_Case {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting meta that hasn't been set
|
||||
*/
|
||||
function test_get_meta_no_meta() {
|
||||
$object = $this->create_test_post();
|
||||
$object_id = $object->get_id();
|
||||
$object = new WC_Mock_WC_Data( $object_id );
|
||||
|
||||
$single_on = $object->get_meta( 'doesnt-exist', true );
|
||||
$single_off = $object->get_meta( 'also-doesnt-exist', false );
|
||||
|
||||
$this->assertEquals( '', $single_on );
|
||||
$this->assertEquals( array(), $single_off );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setting meta.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue