mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 07:40:07 +00:00
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. Merges [43729] to trunk. Props flixos90, spacedmonkey. Fixes #44467. git-svn-id: https://develop.svn.wordpress.org/trunk@43982 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -224,4 +224,41 @@ class Tests_Comment_Meta_Cache extends WP_UnitTestCase {
|
||||
$num_queries++;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 44467
|
||||
*/
|
||||
public function test_add_metadata_sets_comments_last_changed() {
|
||||
$comment_id = self::factory()->comment->create();
|
||||
|
||||
wp_cache_delete( 'last_changed', 'comment' );
|
||||
|
||||
$this->assertInternalType( 'integer', add_metadata( 'comment', $comment_id, 'foo', 'bar' ) );
|
||||
$this->assertNotFalse( wp_cache_get_last_changed( 'comment' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 44467
|
||||
*/
|
||||
public function test_update_metadata_sets_comments_last_changed() {
|
||||
$comment_id = self::factory()->comment->create();
|
||||
|
||||
wp_cache_delete( 'last_changed', 'comment' );
|
||||
|
||||
$this->assertInternalType( 'integer', update_metadata( 'comment', $comment_id, 'foo', 'bar' ) );
|
||||
$this->assertNotFalse( wp_cache_get_last_changed( 'comment' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 44467
|
||||
*/
|
||||
public function test_delete_metadata_sets_comments_last_changed() {
|
||||
$comment_id = self::factory()->comment->create();
|
||||
|
||||
update_metadata( 'comment', $comment_id, 'foo', 'bar' );
|
||||
wp_cache_delete( 'last_changed', 'comment' );
|
||||
|
||||
$this->assertTrue( delete_metadata( 'comment', $comment_id, 'foo' ) );
|
||||
$this->assertNotFalse( wp_cache_get_last_changed( 'comment' ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,4 +309,41 @@ class Tests_Post_Meta extends WP_UnitTestCase {
|
||||
array( '', 'registered_key3' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 44467
|
||||
*/
|
||||
public function test_add_metadata_sets_posts_last_changed() {
|
||||
$post_id = self::factory()->post->create();
|
||||
|
||||
wp_cache_delete( 'last_changed', 'posts' );
|
||||
|
||||
$this->assertInternalType( 'integer', add_metadata( 'post', $post_id, 'foo', 'bar' ) );
|
||||
$this->assertNotFalse( wp_cache_get_last_changed( 'posts' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 44467
|
||||
*/
|
||||
public function test_update_metadata_sets_posts_last_changed() {
|
||||
$post_id = self::factory()->post->create();
|
||||
|
||||
wp_cache_delete( 'last_changed', 'posts' );
|
||||
|
||||
$this->assertInternalType( 'integer', update_metadata( 'post', $post_id, 'foo', 'bar' ) );
|
||||
$this->assertNotFalse( wp_cache_get_last_changed( 'posts' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 44467
|
||||
*/
|
||||
public function test_delete_metadata_sets_posts_last_changed() {
|
||||
$post_id = self::factory()->post->create();
|
||||
|
||||
update_metadata( 'post', $post_id, 'foo', 'bar' );
|
||||
wp_cache_delete( 'last_changed', 'posts' );
|
||||
|
||||
$this->assertTrue( delete_metadata( 'post', $post_id, 'foo' ) );
|
||||
$this->assertNotFalse( wp_cache_get_last_changed( 'posts' ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -537,4 +537,62 @@ class Tests_Term_Meta extends WP_UnitTestCase {
|
||||
array( '', 'registered_key3' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 44467
|
||||
*/
|
||||
public function test_add_metadata_sets_terms_last_changed() {
|
||||
$term_id = self::factory()->term->create();
|
||||
|
||||
wp_cache_delete( 'last_changed', 'terms' );
|
||||
|
||||
$this->assertInternalType( 'integer', add_metadata( 'term', $term_id, 'foo', 'bar' ) );
|
||||
$this->assertNotFalse( wp_cache_get_last_changed( 'terms' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 44467
|
||||
*/
|
||||
public function test_update_metadata_sets_terms_last_changed() {
|
||||
$term_id = self::factory()->term->create();
|
||||
|
||||
wp_cache_delete( 'last_changed', 'terms' );
|
||||
|
||||
$this->assertInternalType( 'integer', update_metadata( 'term', $term_id, 'foo', 'bar' ) );
|
||||
$this->assertNotFalse( wp_cache_get_last_changed( 'terms' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 44467
|
||||
*/
|
||||
public function test_delete_metadata_sets_terms_last_changed() {
|
||||
$term_id = self::factory()->term->create();
|
||||
|
||||
update_metadata( 'term', $term_id, 'foo', 'bar' );
|
||||
wp_cache_delete( 'last_changed', 'terms' );
|
||||
|
||||
$this->assertTrue( delete_metadata( 'term', $term_id, 'foo' ) );
|
||||
$this->assertNotFalse( wp_cache_get_last_changed( 'terms' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 44467
|
||||
*/
|
||||
public function test_metadata_functions_respect_term_meta_support() {
|
||||
$term_id = self::factory()->term->create();
|
||||
|
||||
$meta_id = add_metadata( 'term', $term_id, 'foo', 'bar' );
|
||||
|
||||
// Set database version to last version before term meta support.
|
||||
update_option( 'db_version', 34369 );
|
||||
|
||||
$this->assertFalse( get_metadata( 'term', $term_id, 'foo', true ) );
|
||||
$this->assertFalse( add_metadata( 'term', $term_id, 'foo', 'bar' ) );
|
||||
$this->assertFalse( update_metadata( 'term', $term_id, 'foo', 'bar' ) );
|
||||
$this->assertFalse( delete_metadata( 'term', $term_id, 'foo' ) );
|
||||
$this->assertFalse( get_metadata_by_mid( 'term', $meta_id ) );
|
||||
$this->assertFalse( update_metadata_by_mid( 'term', $meta_id, 'baz' ) );
|
||||
$this->assertFalse( delete_metadata_by_mid( 'term', $meta_id ) );
|
||||
$this->assertFalse( update_meta_cache( 'term', array( $term_id ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user