Skip to content

Commit

Permalink
Add unit tests for pre filter check
Browse files Browse the repository at this point in the history
  • Loading branch information
mukeshpanchal27 authored Oct 9, 2023
1 parent 2671d63 commit cedb654
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/phpunit/tests/option/networkOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,4 +688,58 @@ public function data_stored_as_empty_string() {
'null' => array( null ),
);
}

/**
* Tests that a non-existent option is added even when its pre filter returns a value.
*
* @ticket 59360
*
* @covers ::update_network_option
*/
public function test_update_network_option_with_pre_filter_adds_missing_option() {
// Force a return value of integer 0.
add_filter( 'pre_site_option_foo', '__return_zero' );

/*
* This should succeed, since the 'foo' option does not exist in the database.
* The default value is false, so it differs from 0.
*/
$this->assertTrue( update_network_option( null, 'foo', 0 ) );
}

/**
* Tests that an existing option is updated even when its pre filter returns the same value.
*
* @ticket 59360
*
* @covers ::update_network_option
*/
public function test_update_network_option_with_pre_filter_updates_option_with_different_value() {
// Add the option with a value of 1 to the database.
update_network_option( null, 'foo', 1 );

// Force a return value of integer 0.
add_filter( 'pre_site_option_foo', '__return_zero' );

/*
* This should succeed, since the 'foo' option has a value of 1 in the database.
* Therefore it differs from 0 and should be updated.
*/
$this->assertTrue( update_network_option( null, 'foo', 0 ) );
}

/**
* Tests that calling update_network_option() does not permanently remove pre filters.
*
* @ticket 59360
*
* @covers ::update_network_option
*/
public function test_update_network_option_maintains_pre_filters() {
add_filter( 'pre_site_option_foo', '__return_zero' );
update_network_option( null, 'foo', 0 );

// Assert that the filter is still present.
$this->assertSame( 10, has_filter( 'pre_site_option_foo', '__return_zero' ) );
}
}

0 comments on commit cedb654

Please sign in to comment.