Options: Add Unit tests for register_setting.

Test `register_setting` with old and new style of arguments.

Props rmccue.
Fixes #37885.


git-svn-id: https://develop.svn.wordpress.org/trunk@38690 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Joe Hoyle 2016-09-30 20:23:33 +00:00
parent 4c6d7c8498
commit 2da297eeaf
1 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,55 @@
<?php
/**
* @group option
*/
class Tests_Option_Registration extends WP_UnitTestCase {
public function test_register() {
register_setting( 'test_group', 'test_option' );
$registered = get_registered_settings();
$this->assertArrayHasKey( 'test_option', $registered );
$args = $registered['test_option'];
$this->assertEquals( 'test_group', $args['group'] );
// Check defaults.
$this->assertEquals( 'string', $args['type'] );
$this->assertEquals( false, $args['show_in_rest'] );
$this->assertEquals( '', $args['description'] );
}
public function test_register_with_callback() {
register_setting( 'test_group', 'test_option', array( $this, 'filter_registered_setting' ) );
$filtered = apply_filters( 'sanitize_option_test_option', 'smart', 'test_option', 'smart' );
$this->assertEquals( 'S-M-R-T', $filtered );
}
public function test_register_with_array() {
register_setting( 'test_group', 'test_option', array(
'sanitize_callback' => array( $this, 'filter_registered_setting' ),
));
$filtered = apply_filters( 'sanitize_option_test_option', 'smart', 'test_option', 'smart' );
$this->assertEquals( 'S-M-R-T', $filtered );
}
public function filter_registered_setting() {
return 'S-M-R-T';
}
/**
* @expectedDeprecated register_setting
*/
public function test_register_deprecated_group_misc() {
register_setting( 'misc', 'test_option' );
}
/**
* @expectedDeprecated register_setting
*/
public function test_register_deprecated_group_privacy() {
register_setting( 'privacy', 'test_option' );
}
}