Skip to content

Commit 1f7af9a

Browse files
committed
Options, Meta APIs: Test site transients stored correctly.
Adds unit tests to ensure that site transients are stored correctly: * in `wp_options` on single site installs, * in `wp_sitemeta` on multisite installs. Props peterwilsoncc, rollybueno. See #63167. git-svn-id: https://develop.svn.wordpress.org/trunk@60615 602fd350-edb4-49c9-b593-d223f7449a82
1 parent cc8cc8a commit 1f7af9a

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

tests/phpunit/tests/option/siteTransient.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,88 @@ public function test_set_site_transient_is_not_stored_as_autoload_option() {
7171

7272
$this->assertArrayNotHasKey( '_site_transient_' . $key, $options );
7373
}
74+
75+
/**
76+
* Ensure site transients are stored in the options table on single site installations.
77+
*
78+
* @group ms-excluded
79+
*
80+
* @covers ::set_site_transient
81+
*/
82+
public function test_site_transient_stored_in_options_on_single_site() {
83+
global $wpdb;
84+
$key = 'test_site_transient_stored_in_options_on_single_site';
85+
$value = 'Test Site Transient Value';
86+
87+
set_site_transient( $key, $value );
88+
89+
$option = $wpdb->get_row(
90+
$wpdb->prepare(
91+
"SELECT option_name, option_value from {$wpdb->options} WHERE option_name = %s",
92+
'_site_transient_' . $key
93+
)
94+
);
95+
$this->assertEquals(
96+
(object) array(
97+
'option_name' => '_site_transient_' . $key,
98+
'option_value' => $value,
99+
),
100+
$option,
101+
'Site transient should be stored in the options table on single site installations.'
102+
);
103+
}
104+
105+
/**
106+
* Ensure site transients are stored in the sitemeta table on multisite.
107+
*
108+
* @group ms-required
109+
*
110+
* @covers ::set_site_transient
111+
*/
112+
public function test_site_transients_stored_in_site_meta_on_ms() {
113+
global $wpdb;
114+
$key = 'test_site_transient_stored_in_site_meta_on_ms';
115+
$value = 'Test Site Transient Value';
116+
117+
set_site_transient( $key, $value );
118+
119+
$option = $wpdb->get_row(
120+
$wpdb->prepare(
121+
"SELECT meta_key, meta_value from {$wpdb->sitemeta} WHERE meta_key = %s",
122+
'_site_transient_' . $key
123+
)
124+
);
125+
$this->assertEquals(
126+
(object) array(
127+
'meta_key' => '_site_transient_' . $key,
128+
'meta_value' => $value,
129+
),
130+
$option,
131+
'Site transient should be stored in sitemeta table on multisite.'
132+
);
133+
}
134+
135+
/**
136+
* Ensure site transients are not stored in the options table on multisite.
137+
*
138+
* @group ms-required
139+
*
140+
* @covers ::set_site_transient
141+
*/
142+
public function test_site_transients_not_stored_in_options_table_on_ms() {
143+
global $wpdb;
144+
$key = 'test_site_transients_not_stored_in_options_table_on_ms';
145+
$value = 'Test Site Transient Value';
146+
147+
set_site_transient( $key, $value );
148+
149+
$option = $wpdb->get_row(
150+
$wpdb->prepare(
151+
"SELECT option_name, option_value from {$wpdb->options} WHERE option_name = %s",
152+
'_site_transient_' . $key
153+
)
154+
);
155+
156+
$this->assertNull( $option, 'Querying option table should not return transient on multisite.' );
157+
}
74158
}

0 commit comments

Comments
 (0)