WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/07/2017 01:37:39 PM (3 years ago)
Author:
johnbillion
Message:

Build/Test tools: Remove occurrences of create_function() in unit tests.

Props desrosj

See #37082

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/setting.php

    r40036 r40392  
    4949    }
    5050
     51    /**
     52     * A test validate callback function.
     53     *
     54     * @param mixed                $value   The setting value.
     55     * @param WP_Customize_Setting $setting The setting object.
     56     */
     57    public function validate_callback_for_tests( $value, $setting ) {
     58        return $value . ':validate_callback';
     59    }
     60
     61    /**
     62     * A test sanitize callback function.
     63     *
     64     * @param mixed                $value   The setting value.
     65     * @param WP_Customize_Setting $setting The setting object.
     66     */
     67    public function sanitize_callback_for_tests( $value, $setting ) {
     68        return $value . ':sanitize_callback';
     69    }
     70
     71    /**
     72     * A test sanitize JS callback function.
     73     *
     74     * @param mixed                $value   The setting value.
     75     * @param WP_Customize_Setting $setting The setting object.
     76     */
     77    public function sanitize_js_callback_for_tests( $value, $setting ) {
     78        return $value . ':sanitize_js_callback';
     79    }
     80
     81    /**
     82     * Sanitize JS callback for base64 encoding.
     83     *
     84     * @param mixed                $value   The setting value.
     85     * @param WP_Customize_Setting $setting The setting object.
     86     */
     87    function sanitize_js_callback_base64_for_testing( $value, $setting ) {
     88        return base64_encode( $value );
     89    }
     90
    5191    function test_constructor_with_args() {
    5292        $args = array(
     
    5696            'default' => 'barbar',
    5797            'transport' => 'postMessage',
    58             'validate_callback' => create_function( '$value', 'return $value . ":validate_callback";' ),
    59             'sanitize_callback' => create_function( '$value', 'return $value . ":sanitize_callback";' ),
    60             'sanitize_js_callback' => create_function( '$value', 'return $value . ":sanitize_js_callback";' ),
     98            'validate_callback' => array( $this, 'validate_callback_for_tests' ),
     99            'sanitize_callback' => array( $this, 'sanitize_callback_for_tests' ),
     100            'sanitize_js_callback' => array( $this, 'sanitize_js_callback_for_tests' ),
    61101        );
    62102        $setting = new WP_Customize_Setting( $this->manager, 'bar', $args );
     
    616656            'transport' => 'postMessage',
    617657            'dirty' => true,
    618             'sanitize_js_callback' => create_function( '$value', 'return base64_encode( $value );' ),
     658            'sanitize_js_callback' => array( $this, 'sanitize_js_callback_base64_for_testing' ),
    619659        );
    620660        $setting = new WP_Customize_Setting( $this->manager, 'name', $args );
Note: See TracChangeset for help on using the changeset viewer.