Pass all updated meta IDs to filters in update_metadata().

Props wonderboymusic.
Fixes #11683.

git-svn-id: https://develop.svn.wordpress.org/trunk@30140 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2014-11-01 02:38:19 +00:00
parent 17e9c6f403
commit 8dbaaf9927
2 changed files with 51 additions and 6 deletions

View File

@@ -4,6 +4,8 @@
* @group meta
*/
class Tests_Meta extends WP_UnitTestCase {
protected $updated_mids = array();
function setUp() {
parent::setUp();
$this->author = new WP_User( $this->factory->user->create( array( 'role' => 'author' ) ) );
@@ -76,6 +78,32 @@ class Tests_Meta extends WP_UnitTestCase {
$this->assertFalse( $first === $second );
}
/**
* @ticket 11683
*/
public function test_update_metadata_hooks_for_multiple_updated_rows() {
add_metadata( 'post', 1, 'test_key', 'value_1' );
add_metadata( 'post', 1, 'test_key', 'value_2' );
add_action( 'update_post_meta', array( $this, 'updated_meta' ) );
add_action( 'update_postmeta', array( $this, 'updated_meta' ) );
add_action( 'updated_post_meta', array( $this, 'updated_meta' ) );
add_action( 'updated_postmeta', array( $this, 'updated_meta' ) );
update_metadata( 'post', 1, 'test_key', 'value_3' );
remove_action( 'update_post_meta', array( $this, 'updated_meta' ) );
remove_action( 'update_postmeta', array( $this, 'updated_meta' ) );
remove_action( 'updated_post_meta', array( $this, 'updated_meta' ) );
remove_action( 'updated_postmeta', array( $this, 'updated_meta' ) );
$found = $this->updated_mids;
$this->updated_mids = array();
foreach ( $found as $action => $mids ) {
$this->assertSame( 2, count( $mids ) );
}
}
function test_metadata_exists() {
$this->assertFalse( metadata_exists( 'user', $this->author->ID, 'foobarbaz' ) );
$this->assertTrue( metadata_exists( 'user', $this->author->ID, 'meta_key' ) );
@@ -300,4 +328,10 @@ class Tests_Meta extends WP_UnitTestCase {
$this->assertSame( array( $data ), $found['foo'] );
}
/** Helpers **********************************************************/
public function updated_meta( $meta_id ) {
$this->updated_mids[ current_action() ][] = $meta_id;
}
}