Skip to content

Commit

Permalink
Yoast BC fix (don't commit with this in the PR)
Browse files Browse the repository at this point in the history
  • Loading branch information
costdev committed Oct 13, 2023
1 parent 7c28426 commit a41fd06
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/wp-includes/option.php
Original file line number Diff line number Diff line change
Expand Up @@ -2174,7 +2174,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 );
}

Expand Down
50 changes: 14 additions & 36 deletions tests/phpunit/tests/option/networkOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand All @@ -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.' );
}
}

0 comments on commit a41fd06

Please sign in to comment.