Make WordPress Core


Ignore:
Timestamp:
11/01/2014 02:38:19 AM (11 years ago)
Author:
boonebgorges
Message:

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

Props wonderboymusic.
Fixes #11683.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/meta.php

    r30115 r30140  
    55 */
    66class Tests_Meta extends WP_UnitTestCase {
     7    protected $updated_mids = array();
     8
    79    function setUp() {
    810        parent::setUp();
     
    7577        $second = get_user_meta( $meta->user_id, $meta->meta_key );
    7678        $this->assertFalse( $first === $second );
     79    }
     80
     81    /**
     82     * @ticket 11683
     83     */
     84    public function test_update_metadata_hooks_for_multiple_updated_rows() {
     85        add_metadata( 'post', 1, 'test_key', 'value_1' );
     86        add_metadata( 'post', 1, 'test_key', 'value_2' );
     87        add_action( 'update_post_meta', array( $this, 'updated_meta' ) );
     88        add_action( 'update_postmeta', array( $this, 'updated_meta' ) );
     89        add_action( 'updated_post_meta', array( $this, 'updated_meta' ) );
     90        add_action( 'updated_postmeta', array( $this, 'updated_meta' ) );
     91
     92        update_metadata( 'post', 1, 'test_key', 'value_3' );
     93
     94        remove_action( 'update_post_meta', array( $this, 'updated_meta' ) );
     95        remove_action( 'update_postmeta', array( $this, 'updated_meta' ) );
     96        remove_action( 'updated_post_meta', array( $this, 'updated_meta' ) );
     97        remove_action( 'updated_postmeta', array( $this, 'updated_meta' ) );
     98
     99        $found = $this->updated_mids;
     100        $this->updated_mids = array();
     101
     102        foreach ( $found as $action => $mids ) {
     103            $this->assertSame( 2, count( $mids ) );
     104        }
    77105    }
    78106
     
    301329        $this->assertSame( array( $data ), $found['foo'] );
    302330    }
     331
     332    /** Helpers **********************************************************/
     333
     334    public function updated_meta( $meta_id ) {
     335        $this->updated_mids[ current_action() ][] = $meta_id;
     336    }
    303337}
Note: See TracChangeset for help on using the changeset viewer.