Files
wordpress-develop/tests/phpunit/tests/general/wpRequiredFieldIndicator.php
Jb Audras 0ad353d250 Comments: Make wp_required_field_indicator() and wp_required_field_message() output filterable.
This changeset introduces two new hooks:

- `wp_required_field_indicator` allows developers to filter the HTML output of the `wp_required_field_indicator()` function.
- `wp_required_field_message` does the same for the `wp_required_field_message()` function.

The changeset also adds new phpunit tests for these filters.

Follow-up to [53888], [54136].

Props kebbet, audrasjb, sabernhardt, costdev, mukesh27.
Fixes #56389.
See #54394.


git-svn-id: https://develop.svn.wordpress.org/trunk@54137 602fd350-edb4-49c9-b593-d223f7449a82
2022-09-12 22:29:02 +00:00

46 lines
1.3 KiB
PHP

<?php
/**
* Test wp_required_field_indicator().
*
* @group general
* @group template
*
* @covers ::wp_required_field_indicator
*/
class Tests_General_wpRequiredFieldIndicator extends WP_UnitTestCase {
/**
* Tests that `wp_required_field_indicator()` returns the expected default value.
*
* @ticket 56389
*/
public function test_wp_required_field_indicator_should_return_default_value() {
$this->assertSame( '<span class="required">*</span>', wp_required_field_indicator() );
}
/**
* Tests that `wp_required_field_indicator()` applies 'wp_required_field_indicator' filters.
*
* @ticket 56389
*/
public function test_wp_required_field_indicator_should_apply_wp_required_field_indicator_filters() {
$filter = new MockAction();
add_filter( 'wp_required_field_indicator', array( &$filter, 'filter' ) );
wp_required_field_indicator();
$this->assertSame( 1, $filter->get_call_count() );
}
/**
* Tests that the final return value of `wp_required_field_indicator()` is the result of
* 'wp_required_field_indicator' filters.
*
* @ticket 56389
*/
public function test_wp_required_field_indicator_should_return_wp_required_field_indicator_filters() {
add_filter( 'wp_required_field_indicator', '__return_empty_string' );
$this->assertSame( '', wp_required_field_indicator() );
}
}