get_meta should return empty array sometimes

This commit is contained in:
Claudiu Lodromanean 2017-03-02 11:16:49 -08:00
parent c76c2d1a8d
commit d5fd1e46ee
2 changed files with 16 additions and 1 deletions

View File

@ -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 ) {

View File

@ -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.
*/