Build/Test Tools: Reworks Tests_Option_Option::test_bad_option_names() into data provider.

The existing tests were running multiple functions through a `foreach()`. If any test failed, it would bail out and not test against the other scenarios.

This commit:

- Moves the scenarios to a data provider with named data sets, i.e. to ensure all scenarios are run and tested regardless if any fail.
- Splits each function under test into individual test methods.
- Adds a float scenario.
- Adds method visibility modifiers.

Follow-up to [25002].

Props jrf, hellofromTonya, pbearne.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51817 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Tonya Mork 2021-09-15 21:21:58 +00:00
parent c0b328a74d
commit 07a7b4262b

View File

@ -89,14 +89,63 @@ class Tests_Option_Option extends WP_UnitTestCase {
/**
* @ticket 23289
*
* @dataProvider data_bad_option_names
*
* @param mixed $option_name Option name.
*/
function test_bad_option_names() {
foreach ( array( '', '0', ' ', 0, false, null ) as $empty ) {
$this->assertFalse( get_option( $empty ) );
$this->assertFalse( add_option( $empty, '' ) );
$this->assertFalse( update_option( $empty, '' ) );
$this->assertFalse( delete_option( $empty ) );
}
public function test_get_option_bad_option_name( $option_name ) {
$this->assertFalse( get_option( $option_name ) );
}
/**
* @ticket 23289
*
* @dataProvider data_bad_option_names
*
* @param mixed $option_name Option name.
*/
public function test_add_option_bad_option_name( $option_name ) {
$this->assertFalse( add_option( $option_name, '' ) );
}
/**
* @ticket 23289
*
* @dataProvider data_bad_option_names
*
* @param mixed $option_name Option name.
*/
public function test_update_option_bad_option_name( $option_name ) {
$this->assertFalse( update_option( $option_name, '' ) );
}
/**
* @ticket 23289
*
* @dataProvider data_bad_option_names
*
* @param mixed $option_name Option name.
*/
public function test_delete_option_bad_option_name( $option_name ) {
$this->assertFalse( delete_option( $option_name ) );
}
/**
* Data provider.
*
* @return array
*/
public function data_bad_option_names() {
return array(
'empty string' => array( '' ),
'string 0' => array( '0' ),
'string single space' => array( ' ' ),
'integer 0' => array( 0 ),
'float 0.0' => array( 0.0 ),
'boolean false' => array( false ),
'null' => array( null ),
);
}
/**