Skip to content

Commit 54c35ce

Browse files
Tests: Add a unit test for get_metadata() with a non-existing object ID.
Follow-up to [48658], [50641], [58962]. Props rodrigosprimo, jrf. See #61530, #61608. git-svn-id: https://develop.svn.wordpress.org/trunk@58968 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d46466f commit 54c35ce

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/phpunit/tests/meta.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,34 @@ public function test_get_metadata_with_empty_key_nested_array_value() {
419419
$this->assertSame( array( $value ), $found['foo'] );
420420
}
421421

422+
/**
423+
* @dataProvider data_get_metadata_with_non_existent_object_id
424+
*/
425+
public function test_get_metadata_with_non_existent_object_id( $expected, $args ) {
426+
$this->assertSame( $expected, get_metadata( 'user', ...$args ) );
427+
}
428+
429+
public function data_get_metadata_with_non_existent_object_id() {
430+
return array(
431+
'should return empty array for default `$meta_key` and `$single` values' => array(
432+
'expected' => array(),
433+
'args' => array( PHP_INT_MAX ),
434+
),
435+
'should return empty array for default `$single` value' => array(
436+
'expected' => array(),
437+
'args' => array( PHP_INT_MAX, 'meta_key' ),
438+
),
439+
'should return empty array when `$single` is `false`' => array(
440+
'expected' => array(),
441+
'args' => array( PHP_INT_MAX, 'meta_key', false ),
442+
),
443+
'should return empty string when `$single` is `true`' => array(
444+
'expected' => '',
445+
'args' => array( PHP_INT_MAX, 'meta_key', true ),
446+
),
447+
);
448+
}
449+
422450
/** Helpers */
423451

424452
public function updated_meta( $meta_id ) {

0 commit comments

Comments
 (0)