diff --git a/tests/phpunit/tests/functions/deprecatedFunction.php b/tests/phpunit/tests/functions/deprecatedFunction.php new file mode 100644 index 0000000000000..b83dfbd46b0a2 --- /dev/null +++ b/tests/phpunit/tests/functions/deprecatedFunction.php @@ -0,0 +1,90 @@ +expectDeprecation(); + $this->expectDeprecationMessage( 'Function function_name is deprecated since version 1! Use replacement_function instead.' ); + + $action = new MockAction(); + add_filter( 'deprecated_function_run', array( $action, 'action' ) ); + + _deprecated_function( 'function_name', 1, 'replacement_function' ); + + $this->assertSame( 1, $action->get_call_count() ); + } + + /** + * @ticket 60116 + * + * This method tests if the '_deprecated_function_trigger_error' filter is called + * when the _deprecated_function() function is invoked. + * + * It creates a mock action object and adds a filter to the '_deprecated_function_trigger_error' + * hook, using the mock action as the callback. Then, it calls the __deprecated_function() + * function with the specified function name, message, and error level. + * Finally, it asserts that the filter callback is called exactly once by checking + * the call count of the mock action object. + * + * @return void + */ + public function test_deprecated_function_filter_called() { + $this->expectDeprecation(); + $this->expectDeprecationMessage( 'Function function_name is deprecated since version 1! Use replacement_function instead.' ); + + $filter = new MockAction(); + add_filter( 'deprecated_function_trigger_error', array( $filter, 'filter' ) ); + + _deprecated_function( 'function_name', 1, 'replacement_function' ); + + $this->assertSame( 1, $filter->get_call_count() ); + } + + /** + * @ticket 60116 + * + * + * @return void + */ + public function test_deprecated_function_no_replacement() { + $this->expectDeprecation(); + $this->expectDeprecationMessage( 'Function function_name is deprecated since version 1 with no alternative available.' ); + + _deprecated_function( 'function_name', 1 ); + } +}