From f5fbdecb1a891037aa0dbe9a57b6f29c53427550 Mon Sep 17 00:00:00 2001 From: costdev Date: Fri, 13 Oct 2023 11:10:46 +0100 Subject: [PATCH] Yoast BC fix (don't commit with this in the PR) --- src/wp-includes/option.php | 2 +- tests/phpunit/tests/option/networkOption.php | 50 ++++++-------------- 2 files changed, 15 insertions(+), 37 deletions(-) diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php index edc4c95a2f244..6ec636b0fc068 100644 --- a/src/wp-includes/option.php +++ b/src/wp-includes/option.php @@ -2181,7 +2181,7 @@ function update_network_option( $network_id, $option, $value ) { return false; } - if ( $default_value === $raw_old_value ) { + if ( false === $old_value ) { return add_network_option( $network_id, $option, $value ); } diff --git a/tests/phpunit/tests/option/networkOption.php b/tests/phpunit/tests/option/networkOption.php index 87fc50a4adcc2..9f6f860c39e92 100644 --- a/tests/phpunit/tests/option/networkOption.php +++ b/tests/phpunit/tests/option/networkOption.php @@ -795,9 +795,12 @@ public function test_update_network_option_should_conditionally_apply_site_and_o public function test_update_network_option_should_add_option_with_filtered_default_value() { global $wpdb; - $option = 'foo'; - $default_site_value = 'default-site-value'; - $default_option_value = 'default-option-value'; + if ( ! is_multisite() ) { + $this->markTestSkipped(); + } + + $option = 'foo'; + $default_site_value = 'default-site-value'; add_filter( "default_site_option_{$option}", @@ -806,40 +809,15 @@ static function () use ( $default_site_value ) { } ); - add_filter( - "default_option_{$option}", - static function () use ( $default_option_value ) { - return $default_option_value; - } - ); - - /* - * For a non existing option with the unfiltered default of false, passing false here wouldn't work. - * Because the default is different than false here though, passing false is expected to result in - * a database update. - */ - $this->assertTrue( update_network_option( null, $option, false ), 'update_network_option() should have returned true.' ); - - if ( is_multisite() ) { - $actual = $wpdb->get_row( - $wpdb->prepare( - "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s LIMIT 1", - $option - ) - ); - } else { - $actual = $wpdb->get_row( - $wpdb->prepare( - "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", - $option - ) - ); - } + $this->assertFalse( update_network_option( null, $option, false ), 'update_network_option() should have returned false.' ); - $value_field = is_multisite() ? 'meta_value' : 'option_value'; + $actual = $wpdb->get_row( + $wpdb->prepare( + "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s LIMIT 1", + $option + ) + ); - $this->assertIsObject( $actual, 'The option was not added to the database.' ); - $this->assertObjectHasProperty( $value_field, $actual, "The '$value_field' property was not included." ); - $this->assertSame( '', $actual->$value_field, 'The new value was not stored in the database.' ); + $this->assertNull( $actual, 'The option was added to the database.' ); } }