diff --git a/tests/phpunit/tests/option/registration.php b/tests/phpunit/tests/option/registration.php new file mode 100644 index 0000000000..29958035db --- /dev/null +++ b/tests/phpunit/tests/option/registration.php @@ -0,0 +1,55 @@ +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' ); + } +}