File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
tests/phpunit/tests/option Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -225,4 +225,41 @@ public function test_update_option_array_with_object() {
225
225
public function __return_foo () {
226
226
return 'foo ' ;
227
227
}
228
+
229
+ /**
230
+ * @ticket 26402
231
+ *
232
+ * @covers ::update_option
233
+ */
234
+ public function test_should_invalidate_cache_when_db_update_fails () {
235
+ global $ wpdb ;
236
+
237
+ $ option_name = 'test_option_update_fail ' ;
238
+ $ option_value = 'initial ' ;
239
+
240
+ add_option ( $ option_name , $ option_value );
241
+ $ this ->assertSame ( $ option_value , get_option ( $ option_name ) );
242
+
243
+ $ wpdb ->delete ( $ wpdb ->options , array ( 'option_name ' => $ option_name ) );
244
+
245
+ tests_add_filter (
246
+ 'query ' ,
247
+ function ( $ query ) use ( $ wpdb ) {
248
+ if ( stripos ( $ query , "update ` $ wpdb ->options ` " ) === 0 ) {
249
+ return false ; // Simulate DB update failure.
250
+ }
251
+ return $ query ;
252
+ }
253
+ );
254
+
255
+ $ result = update_option ( $ option_name , 'new_value ' );
256
+
257
+ $ this ->assertFalse ( $ result , 'Expected update_option() to fail when DB update fails. ' );
258
+ $ this ->assertFalse ( wp_cache_get ( $ option_name , 'options ' ) );
259
+
260
+ // Verify alloptions cache no longer contains the option.
261
+ $ alloptions = wp_cache_get ( 'alloptions ' , 'options ' );
262
+ $ this ->assertIsArray ( $ alloptions );
263
+ $ this ->assertArrayNotHasKey ( $ option_name , $ alloptions );
264
+ }
228
265
}
You can’t perform that action at this time.
0 commit comments