Build/Test tools: Remove occurrences of `create_function()` in unit tests.
Props desrosj See #37082 git-svn-id: https://develop.svn.wordpress.org/trunk@40392 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
4fbac9b3a7
commit
2a261f0d7c
|
@ -48,6 +48,46 @@ class Tests_WP_Customize_Setting extends WP_UnitTestCase {
|
||||||
$this->assertEquals( false, $setting->dirty );
|
$this->assertEquals( false, $setting->dirty );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A test validate callback function.
|
||||||
|
*
|
||||||
|
* @param mixed $value The setting value.
|
||||||
|
* @param WP_Customize_Setting $setting The setting object.
|
||||||
|
*/
|
||||||
|
public function validate_callback_for_tests( $value, $setting ) {
|
||||||
|
return $value . ':validate_callback';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A test sanitize callback function.
|
||||||
|
*
|
||||||
|
* @param mixed $value The setting value.
|
||||||
|
* @param WP_Customize_Setting $setting The setting object.
|
||||||
|
*/
|
||||||
|
public function sanitize_callback_for_tests( $value, $setting ) {
|
||||||
|
return $value . ':sanitize_callback';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A test sanitize JS callback function.
|
||||||
|
*
|
||||||
|
* @param mixed $value The setting value.
|
||||||
|
* @param WP_Customize_Setting $setting The setting object.
|
||||||
|
*/
|
||||||
|
public function sanitize_js_callback_for_tests( $value, $setting ) {
|
||||||
|
return $value . ':sanitize_js_callback';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitize JS callback for base64 encoding.
|
||||||
|
*
|
||||||
|
* @param mixed $value The setting value.
|
||||||
|
* @param WP_Customize_Setting $setting The setting object.
|
||||||
|
*/
|
||||||
|
function sanitize_js_callback_base64_for_testing( $value, $setting ) {
|
||||||
|
return base64_encode( $value );
|
||||||
|
}
|
||||||
|
|
||||||
function test_constructor_with_args() {
|
function test_constructor_with_args() {
|
||||||
$args = array(
|
$args = array(
|
||||||
'type' => 'option',
|
'type' => 'option',
|
||||||
|
@ -55,9 +95,9 @@ class Tests_WP_Customize_Setting extends WP_UnitTestCase {
|
||||||
'theme_supports' => 'widgets',
|
'theme_supports' => 'widgets',
|
||||||
'default' => 'barbar',
|
'default' => 'barbar',
|
||||||
'transport' => 'postMessage',
|
'transport' => 'postMessage',
|
||||||
'validate_callback' => create_function( '$value', 'return $value . ":validate_callback";' ),
|
'validate_callback' => array( $this, 'validate_callback_for_tests' ),
|
||||||
'sanitize_callback' => create_function( '$value', 'return $value . ":sanitize_callback";' ),
|
'sanitize_callback' => array( $this, 'sanitize_callback_for_tests' ),
|
||||||
'sanitize_js_callback' => create_function( '$value', 'return $value . ":sanitize_js_callback";' ),
|
'sanitize_js_callback' => array( $this, 'sanitize_js_callback_for_tests' ),
|
||||||
);
|
);
|
||||||
$setting = new WP_Customize_Setting( $this->manager, 'bar', $args );
|
$setting = new WP_Customize_Setting( $this->manager, 'bar', $args );
|
||||||
$this->assertEquals( 'bar', $setting->id );
|
$this->assertEquals( 'bar', $setting->id );
|
||||||
|
@ -615,7 +655,7 @@ class Tests_WP_Customize_Setting extends WP_UnitTestCase {
|
||||||
'default' => $default,
|
'default' => $default,
|
||||||
'transport' => 'postMessage',
|
'transport' => 'postMessage',
|
||||||
'dirty' => true,
|
'dirty' => true,
|
||||||
'sanitize_js_callback' => create_function( '$value', 'return base64_encode( $value );' ),
|
'sanitize_js_callback' => array( $this, 'sanitize_js_callback_base64_for_testing' ),
|
||||||
);
|
);
|
||||||
$setting = new WP_Customize_Setting( $this->manager, 'name', $args );
|
$setting = new WP_Customize_Setting( $this->manager, 'name', $args );
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,20 @@ class Tests_Image_Editor extends WP_Image_UnitTestCase {
|
||||||
WP_Image_Editor_Mock::$load_return = true;
|
WP_Image_Editor_Mock::$load_return = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return integer of 95 for testing.
|
||||||
|
*/
|
||||||
|
public function return_integer_95() {
|
||||||
|
return 95;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return integer of 100 for testing.
|
||||||
|
*/
|
||||||
|
public function return_integer_100() {
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test test_quality
|
* Test test_quality
|
||||||
* @ticket 6821
|
* @ticket 6821
|
||||||
|
@ -59,11 +73,11 @@ class Tests_Image_Editor extends WP_Image_UnitTestCase {
|
||||||
$this->assertEquals( 82, $editor->get_quality() );
|
$this->assertEquals( 82, $editor->get_quality() );
|
||||||
|
|
||||||
// Ensure the quality filters do not have precedence if created after editor instantiation.
|
// Ensure the quality filters do not have precedence if created after editor instantiation.
|
||||||
$func_100_percent = create_function( '', "return 100;" );
|
$func_100_percent = array( $this, 'return_integer_100' );
|
||||||
add_filter( 'wp_editor_set_quality', $func_100_percent );
|
add_filter( 'wp_editor_set_quality', $func_100_percent );
|
||||||
$this->assertEquals( 82, $editor->get_quality() );
|
$this->assertEquals( 82, $editor->get_quality() );
|
||||||
|
|
||||||
$func_95_percent = create_function( '', "return 95;" );
|
$func_95_percent = array( $this, 'return_integer_95' );
|
||||||
add_filter( 'jpeg_quality', $func_95_percent );
|
add_filter( 'jpeg_quality', $func_95_percent );
|
||||||
$this->assertEquals( 82, $editor->get_quality() );
|
$this->assertEquals( 82, $editor->get_quality() );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue