WordPress.org

Make WordPress Core

Changeset 51817


Ignore:
Timestamp:
09/15/2021 09:21:58 PM (5 weeks ago)
Author:
hellofromTonya
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/option/option.php

    r48996 r51817  
    9090    /**
    9191     * @ticket 23289
     92     *
     93     * @dataProvider data_bad_option_names
     94     *
     95     * @param mixed $option_name Option name.
    9296     */
    93     function test_bad_option_names() {
    94         foreach ( array( '', '0', ' ', 0, false, null ) as $empty ) {
    95             $this->assertFalse( get_option( $empty ) );
    96             $this->assertFalse( add_option( $empty, '' ) );
    97             $this->assertFalse( update_option( $empty, '' ) );
    98             $this->assertFalse( delete_option( $empty ) );
    99         }
     97    public function test_get_option_bad_option_name( $option_name ) {
     98        $this->assertFalse( get_option( $option_name ) );
     99    }
     100
     101    /**
     102     * @ticket 23289
     103     *
     104     * @dataProvider data_bad_option_names
     105     *
     106     * @param mixed $option_name Option name.
     107     */
     108    public function test_add_option_bad_option_name( $option_name ) {
     109        $this->assertFalse( add_option( $option_name, '' ) );
     110    }
     111
     112    /**
     113     * @ticket 23289
     114     *
     115     * @dataProvider data_bad_option_names
     116     *
     117     * @param mixed $option_name Option name.
     118     */
     119    public function test_update_option_bad_option_name( $option_name ) {
     120        $this->assertFalse( update_option( $option_name, '' ) );
     121    }
     122
     123    /**
     124     * @ticket 23289
     125     *
     126     * @dataProvider data_bad_option_names
     127     *
     128     * @param mixed $option_name Option name.
     129     */
     130    public function test_delete_option_bad_option_name( $option_name ) {
     131        $this->assertFalse( delete_option( $option_name ) );
     132    }
     133
     134    /**
     135     * Data provider.
     136     *
     137     * @return array
     138     */
     139    public function data_bad_option_names() {
     140        return array(
     141            'empty string'        => array( '' ),
     142            'string 0'            => array( '0' ),
     143            'string single space' => array( ' ' ),
     144            'integer 0'           => array( 0 ),
     145            'float 0.0'           => array( 0.0 ),
     146            'boolean false'       => array( false ),
     147            'null'                => array( null ),
     148        );
    100149    }
    101150
Note: See TracChangeset for help on using the changeset viewer.