Make WordPress Core


Ignore:
Timestamp:
07/13/2023 12:27:06 AM (19 months ago)
Author:
peterwilsoncc
Message:

General: Introduce all development mode.

Introduce the development mode all as a a cover-all mode for the existing theme, plugin and core development modes. Developers can use the all mode if they are developing both themes and plugins, for example.

Introduce the utility function wp_in_development_mode() allowing developers to detect the mode via a parameter. If the development mode is set to all this function will always return true. If the development mode is specific then only the chosen mode will return true.

Follow up to [56079,56042].

Props flixos90.
Fixes #57487.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/load/wpGetDevelopmentMode.php

    r56042 r56223  
    99 * @group load.php
    1010 * @covers ::wp_get_development_mode
     11 * @covers ::wp_in_development_mode
    1112 */
    1213class Test_WP_Get_Development_Mode extends WP_UnitTestCase {
     
    4445        $this->assertSame( '', wp_get_development_mode() );
    4546    }
     47
     48    /**
     49     * Tests that `wp_in_development_mode()` returns expected results.
     50     *
     51     * @ticket 57487
     52     * @dataProvider data_wp_in_development_mode
     53     */
     54    public function test_wp_in_development_mode( $current, $given, $expected ) {
     55        global $_wp_tests_development_mode;
     56
     57        $_wp_tests_development_mode = $current;
     58
     59        if ( $expected ) {
     60            $this->assertTrue( wp_in_development_mode( $given ), "{$given} is expected to pass in {$current} mode" );
     61        } else {
     62            $this->assertFalse( wp_in_development_mode( $given ), "{$given} is expected to fail in {$current} mode" );
     63        }
     64    }
     65
     66    /**
     67     * Data provider that returns test scenarios for the `test_wp_in_development_mode()` method.
     68     *
     69     * @return array[]
     70     */
     71    public function data_wp_in_development_mode() {
     72        return array(
     73            'core mode, testing for core'              => array(
     74                'core',
     75                'core',
     76                true,
     77            ),
     78            'plugin mode, testing for plugin'          => array(
     79                'plugin',
     80                'plugin',
     81                true,
     82            ),
     83            'theme mode, testing for theme'            => array(
     84                'theme',
     85                'theme',
     86                true,
     87            ),
     88            'core mode, testing for plugin'            => array(
     89                'core',
     90                'plugin',
     91                false,
     92            ),
     93            'core mode, testing for theme'             => array(
     94                'core',
     95                'theme',
     96                false,
     97            ),
     98            'plugin mode, testing for core'            => array(
     99                'plugin',
     100                'core',
     101                false,
     102            ),
     103            'plugin mode, testing for theme'           => array(
     104                'plugin',
     105                'theme',
     106                false,
     107            ),
     108            'theme mode, testing for core'             => array(
     109                'theme',
     110                'core',
     111                false,
     112            ),
     113            'theme mode, testing for plugin'           => array(
     114                'theme',
     115                'plugin',
     116                false,
     117            ),
     118            'all mode, testing for core'               => array(
     119                'all',
     120                'core',
     121                true,
     122            ),
     123            'all mode, testing for plugin'             => array(
     124                'all',
     125                'plugin',
     126                true,
     127            ),
     128            'all mode, testing for theme'              => array(
     129                'all',
     130                'theme',
     131                true,
     132            ),
     133            'all mode, testing for all'                => array(
     134                'all',
     135                'all',
     136                true,
     137            ),
     138            'all mode, testing for non-standard value' => array(
     139                'all',
     140                'random',
     141                true,
     142            ),
     143            'invalid mode, testing for core'           => array(
     144                'invalid',
     145                'core',
     146                false,
     147            ),
     148            'invalid mode, testing for plugin'         => array(
     149                'invalid',
     150                'plugin',
     151                false,
     152            ),
     153            'invalid mode, testing for theme'          => array(
     154                'invalid',
     155                'theme',
     156                false,
     157            ),
     158        );
     159    }
    46160}
Note: See TracChangeset for help on using the changeset viewer.