WordPress.org

Make WordPress Core

Changeset 40392


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

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

Props desrosj

See #37082

Location:
trunk/tests/phpunit/tests
Files:
2 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 );
  • trunk/tests/phpunit/tests/image/editor.php

    r36616 r40392  
    4747
    4848    /**
     49     * Return integer of 95 for testing.
     50     */
     51    public function return_integer_95() {
     52        return 95;
     53    }
     54
     55    /**
     56     * Return integer of 100 for testing.
     57     */
     58    public function return_integer_100() {
     59        return 100;
     60    }
     61
     62    /**
    4963     * Test test_quality
    5064     * @ticket 6821
     
    6074
    6175        // Ensure the quality filters do not have precedence if created after editor instantiation.
    62         $func_100_percent = create_function( '', "return 100;" );
     76        $func_100_percent = array( $this, 'return_integer_100' );
    6377        add_filter( 'wp_editor_set_quality', $func_100_percent );
    6478        $this->assertEquals( 82, $editor->get_quality() );
    6579
    66         $func_95_percent = create_function( '', "return 95;" );
     80        $func_95_percent = array( $this, 'return_integer_95' );
    6781        add_filter( 'jpeg_quality', $func_95_percent );
    6882        $this->assertEquals( 82, $editor->get_quality() );
Note: See TracChangeset for help on using the changeset viewer.