Make WordPress Core


Ignore:
Timestamp:
10/15/2018 11:45:16 AM (6 years ago)
Author:
flixos90
Message:

REST API: Move object type-specific metadata integrations from the wrapper functions to the low-level Meta API functions.

Object type-specific actions that should happen before or after modification of metadata have so far been part of the respective wrapper functions. By using action and filter hooks, this changeset ensures they are always executed, even when calling the lower-level Meta API functions directly, which the REST API does as a prime example.

Props flixos90, spacedmonkey.
Fixes #44467.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/tests/phpunit/tests/term/meta.php

    r43510 r43729  
    510510        );
    511511    }
     512
     513    /**
     514     * @ticket 44467
     515     */
     516    public function test_add_metadata_sets_terms_last_changed() {
     517        $term_id = self::factory()->term->create();
     518
     519        wp_cache_delete( 'last_changed', 'terms' );
     520
     521        $this->assertInternalType( 'integer', add_metadata( 'term', $term_id, 'foo', 'bar' ) );
     522        $this->assertNotFalse( wp_cache_get_last_changed( 'terms' ) );
     523    }
     524
     525    /**
     526     * @ticket 44467
     527     */
     528    public function test_update_metadata_sets_terms_last_changed() {
     529        $term_id = self::factory()->term->create();
     530
     531        wp_cache_delete( 'last_changed', 'terms' );
     532
     533        $this->assertInternalType( 'integer', update_metadata( 'term', $term_id, 'foo', 'bar' ) );
     534        $this->assertNotFalse( wp_cache_get_last_changed( 'terms' ) );
     535    }
     536
     537    /**
     538     * @ticket 44467
     539     */
     540    public function test_delete_metadata_sets_terms_last_changed() {
     541        $term_id = self::factory()->term->create();
     542
     543        update_metadata( 'term', $term_id, 'foo', 'bar' );
     544        wp_cache_delete( 'last_changed', 'terms' );
     545
     546        $this->assertTrue( delete_metadata( 'term', $term_id, 'foo' ) );
     547        $this->assertNotFalse( wp_cache_get_last_changed( 'terms' ) );
     548    }
     549
     550    /**
     551     * @ticket 44467
     552     */
     553    public function test_metadata_functions_respect_term_meta_support() {
     554        $term_id = self::factory()->term->create();
     555
     556        $meta_id = add_metadata( 'term', $term_id, 'foo', 'bar' );
     557
     558        // Set database version to last version before term meta support.
     559        update_option( 'db_version', 34369 );
     560
     561        $this->assertFalse( get_metadata( 'term', $term_id, 'foo', true ) );
     562        $this->assertFalse( add_metadata( 'term', $term_id, 'foo', 'bar' ) );
     563        $this->assertFalse( update_metadata( 'term', $term_id, 'foo', 'bar' ) );
     564        $this->assertFalse( delete_metadata( 'term', $term_id, 'foo' ) );
     565        $this->assertFalse( get_metadata_by_mid( 'term', $meta_id ) );
     566        $this->assertFalse( update_metadata_by_mid( 'term', $meta_id, 'baz' ) );
     567        $this->assertFalse( delete_metadata_by_mid( 'term', $meta_id ) );
     568        $this->assertFalse( update_meta_cache( 'term', array( $term_id ) ) );
     569    }
    512570}
Note: See TracChangeset for help on using the changeset viewer.