Skip to content

Commit a59896a

Browse files
committed
Add a test case for double-processed options
1 parent ce2f341 commit a59896a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/phpunit/tests/option/updateOption.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,44 @@ public function test_update_option_array_with_object() {
219219
$this->assertSame( $num_queries_pre_update, get_num_queries() );
220220
}
221221

222+
/**
223+
* @ticket 21989
224+
*
225+
* @covers ::add_option
226+
* @covers ::add_filter
227+
* @covers ::update_option
228+
* @covers ::remove_filter
229+
* @covers ::get_option
230+
*/
231+
public function test_stored_sanitized_value_from_update_of_nonexistent_option_should_be_same_as_that_from_add_option() {
232+
$before = 'x';
233+
$sanitized = $this->_append_y( $before );
234+
235+
// Add the comparison option, it did not exist before this.
236+
add_filter( 'sanitize_option_doesnotexist_filtered_add', array( $this, '_append_y' ) );
237+
add_option( 'doesnotexist_filtered_add', $before );
238+
remove_filter( 'sanitize_option_doesnotexist_filtered_add', array( $this, '_append_y' ) );
239+
240+
// Add the option, it did not exist before this.
241+
add_filter( 'sanitize_option_doesnotexist_filtered_update', array( $this, '_append_y' ) );
242+
$added = update_option( 'doesnotexist_filtered_update', $before );
243+
remove_filter( 'sanitize_option_doesnotexist_filtered_update', array( $this, '_append_y' ) );
244+
245+
$after = get_option( 'doesnotexist_filtered_update' );
246+
247+
// Check all values match.
248+
$this->assertTrue( $added );
249+
$this->assertSame( get_option( 'doesnotexist_filtered_add' ), $after );
250+
$this->assertSame( $sanitized, $after );
251+
}
252+
253+
/**
254+
* `add_filter()` callback for test_stored_sanitized_value_from_update_of_nonexistent_option_should_be_same_as_that_from_add_option().
255+
*/
256+
public function _append_y( $value ) {
257+
return $value . '_y';
258+
}
259+
222260
/**
223261
* `add_filter()` callback for test_should_respect_default_option_filter_when_option_does_not_yet_exist_in_database().
224262
*/

0 commit comments

Comments
 (0)