forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateMetadata.php
More file actions
108 lines (89 loc) · 2.32 KB
/
updateMetadata.php
File metadata and controls
108 lines (89 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* @group meta
* @covers ::update_metadata
*/
class Tests_Meta_UpdateMetadata extends WP_UnitTestCase {
/**
* @ticket 35795
*/
public function test_slashed_key_for_new_metadata() {
update_metadata( 'post', 123, wp_slash( 'foo\foo' ), 'bar' );
$found = get_metadata( 'post', 123, 'foo\foo', true );
$this->assertSame( 'bar', $found );
}
/**
* @ticket 35795
*/
public function test_slashed_key_for_existing_metadata() {
global $wpdb;
add_metadata( 'post', 123, wp_slash( 'foo\foo' ), 'bar' );
update_metadata( 'post', 123, wp_slash( 'foo\foo' ), 'baz' );
$found = get_metadata( 'post', 123, 'foo\foo', true );
$this->assertSame( 'baz', $found );
}
/**
* @ticket 54316
*
* @group user
*
* @covers ::clean_user_cache
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
public function test_clear_user_metadata_caches() {
global $wpdb;
$user_id = self::factory()->user->create();
update_metadata( 'user', $user_id, 'key', 'value1' );
$found = get_metadata( 'user', $user_id, 'key', true );
$this->assertSame( 'value1', $found );
// Simulate updating the DB from outside of WordPress.
$wpdb->update(
$wpdb->usermeta,
array(
'meta_value' => 'value2',
),
array(
'user_id' => $user_id,
'meta_key' => 'key',
)
);
// Clear the user caches.
clean_user_cache( $user_id );
// Verify metadata cache was cleared.
$found = get_metadata( 'user', $user_id, 'key', true );
$this->assertSame( 'value2', $found );
}
/**
* @ticket 54316
*
* @group user
*
* @covers ::clean_user_cache
*
* @global wpdb $wpdb WordPress database abstraction object.
*/
public function test_clear_post_metadata_caches() {
global $wpdb;
$post_id = self::factory()->post->create();
update_metadata( 'post', $post_id, 'key', 'value1' );
$found = get_metadata( 'post', $post_id, 'key', true );
$this->assertSame( 'value1', $found );
// Simulate updating the DB from outside of WordPress.
$wpdb->update(
$wpdb->postmeta,
array(
'meta_value' => 'value2',
),
array(
'post_id' => $post_id,
'meta_key' => 'key',
)
);
// Clear the post caches.
clean_post_cache( $post_id );
// Verify metadata cache was cleared.
$found = get_metadata( 'post', $post_id, 'key', true );
$this->assertSame( 'value2', $found );
}
}