wordpress-develop/tests/phpunit/tests/functions/wpRefererField.php
Sergey Biryukov b1363cc7fe Code Modernization: Rename parameters that use reserved keywords in phpunit/tests/functions/wpRefererField.php.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.

This commit renames the `$echo` parameter to `$display` in `Tests_Functions_wpRefererField::test_wp_referer_field_should_respect_display_arg()`.

Follow-up to [54420], [54929].

Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.

git-svn-id: https://develop.svn.wordpress.org/trunk@55130 602fd350-edb4-49c9-b593-d223f7449a82
2023-01-24 15:53:46 +00:00

78 lines
2.0 KiB
PHP

<?php
/**
* Tests for the wp_referer_field() function.
*
* @since 6.1.0
*
* @group functions.php
* @covers ::wp_referer_field
*/
class Tests_Functions_wpRefererField extends WP_UnitTestCase {
/**
* @ticket 55578
*/
public function test_wp_referer_field() {
$_SERVER['REQUEST_URI'] = '/test/';
wp_referer_field();
$this->expectOutputString( '<input type="hidden" name="_wp_http_referer" value="/test/" />' );
}
/**
* @ticket 55578
*/
public function test_wp_referer_field_return() {
$_SERVER['REQUEST_URI'] = '/test/';
$this->assertSame( '<input type="hidden" name="_wp_http_referer" value="/test/" />', wp_referer_field( false ) );
}
/**
* Tests that the display argument is respected.
*
* @ticket 54106
*
* @dataProvider data_wp_referer_field_should_respect_display_arg
*
* @param mixed $display Whether to echo or return the referer field.
*/
public function test_wp_referer_field_should_respect_display_arg( $display ) {
$actual = $display ? get_echo( 'wp_referer_field' ) : wp_referer_field( false );
$this->assertSame( '<input type="hidden" name="_wp_http_referer" value="" />', $actual );
}
/**
* Data provider for test_wp_referer_field_should_respect_display_arg().
*
* @return array
*/
public function data_wp_referer_field_should_respect_display_arg() {
return array(
'true' => array( true ),
'(int) 1' => array( 1 ),
'(string) "1"' => array( '1' ),
'false' => array( false ),
'null' => array( null ),
'(int) 0' => array( 0 ),
'(string) "0"' => array( '0' ),
);
}
/**
* @ticket 54106
*/
public function test_wp_referer_field_with_referer() {
$old_request_uri = $_SERVER['REQUEST_URI'];
$_SERVER['REQUEST_URI'] = 'edit.php?_wp_http_referer=edit.php';
$actual = wp_referer_field( false );
$_SERVER['REQUEST_URI'] = $old_request_uri;
$this->assertSame( '<input type="hidden" name="_wp_http_referer" value="edit.php" />', $actual );
}
}