<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[51586] trunk: Code Modernization: Rename the `readonly()` function to `wp_readonly()`.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/51586">51586</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/51586","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>SergeyBiryukov</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-08-09 17:19:21 +0000 (Mon, 09 Aug 2021)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Code Modernization: Rename the `readonly()` function to `wp_readonly()`.

Since PHP 8.1, `readonly` is a reserved keyword and cannot be used as a function name.

In order to avoid PHP parser errors, the `readonly()` function was extracted to a separate file and is now only included conditionally on PHP < 8.1.

This commit also:
* Moves the tests for the `__checked_selected_helper()` function and all the related functions to their own file.
* Switches to named data providers. This makes the output when using the `--testdox` option more descriptive and is helpful when trying to debug which data set from a data provider failed the test.
* Improves the tests in question to make them feature-complete and expand test coverage.

Props jrf, ayeshrajans, haosun, knutsp, swissspidy, SergeyBiryukov.
Fixes <a href="https://core.trac.wordpress.org/ticket/53858">#53858</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkphpunitxmldist">trunk/phpunit.xml.dist</a></li>
<li><a href="#trunksrcwpincludesgeneraltemplatephp">trunk/src/wp-includes/general-template.php</a></li>
<li><a href="#trunktestsphpunitmultisitexml">trunk/tests/phpunit/multisite.xml</a></li>
<li><a href="#trunktestsphpunittestsgeneraltemplatephp">trunk/tests/phpunit/tests/general/template.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>trunk/src/wp-includes/php-compat/</li>
<li><a href="#trunksrcwpincludesphpcompatreadonlyphp">trunk/src/wp-includes/php-compat/readonly.php</a></li>
<li><a href="#trunktestsphpunittestsgeneraltemplate_CheckedSelectedHelperphp">trunk/tests/phpunit/tests/general/template_CheckedSelectedHelper.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkphpunitxmldist"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/phpunit.xml.dist</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/phpunit.xml.dist    2021-08-09 14:51:05 UTC (rev 51585)
+++ trunk/phpunit.xml.dist      2021-08-09 17:19:21 UTC (rev 51586)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5,6 +5,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                backupGlobals="false"
</span><span class="cx" style="display: block; padding: 0 10px">                colors="true"
</span><span class="cx" style="display: block; padding: 0 10px">                beStrictAboutTestsThatDoNotTestAnything="true"
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                beStrictAboutOutputDuringTests="true"
</ins><span class="cx" style="display: block; padding: 0 10px">                 >
</span><span class="cx" style="display: block; padding: 0 10px">        <testsuites>
</span><span class="cx" style="display: block; padding: 0 10px">                <!-- Default test suite to run all tests. -->
</span></span></pre></div>
<a id="trunksrcwpincludesgeneraltemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/general-template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/general-template.php        2021-08-09 14:51:05 UTC (rev 51585)
+++ trunk/src/wp-includes/general-template.php  2021-08-09 17:19:21 UTC (rev 51586)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4813,7 +4813,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * Compares the first two arguments and if identical marks as readonly
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 4.9.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 5.9.0
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @param mixed $readonly One of the values to compare
</span><span class="cx" style="display: block; padding: 0 10px">  * @param mixed $current  (true) The other value to compare if not just true
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4820,10 +4820,20 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * @param bool  $echo     Whether to echo or just return the string
</span><span class="cx" style="display: block; padding: 0 10px">  * @return string HTML attribute or empty string
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function readonly( $readonly, $current = true, $echo = true ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_readonly( $readonly, $current = true, $echo = true ) {
</ins><span class="cx" style="display: block; padding: 0 10px">         return __checked_selected_helper( $readonly, $current, $echo, 'readonly' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/*
+ * Include a compat `readonly()` function on PHP < 8.1. Since PHP 8.1,
+ * `readonly` is a reserved keyword and cannot be used as a function name.
+ * In order to avoid PHP parser errors, this function was extracted
+ * to a separate file and is only included conditionally on PHP < 8.1.
+ */
+if ( PHP_VERSION_ID < 80100 ) {
+       require_once __DIR__ . '/php-compat/readonly.php';
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px">  * Private helper function for checked, selected, disabled and readonly.
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span></span></pre></div>
<a id="trunksrcwpincludesphpcompatreadonlyphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/src/wp-includes/php-compat/readonly.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/php-compat/readonly.php                             (rev 0)
+++ trunk/src/wp-includes/php-compat/readonly.php       2021-08-09 17:19:21 UTC (rev 51586)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,35 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Conditionally declares a `readonly()` function, which was renamed
+ * to `wp_readonly()` in WordPress 5.9.0.
+ *
+ * In order to avoid PHP parser errors, this function was extracted
+ * to this separate file and is only included conditionally on PHP 8.1.
+ *
+ * Including this file on PHP >= 8.1 results in a fatal error.
+ *
+ * @package WordPress
+ * @since 5.9.0
+ */
+
+/**
+ * Outputs the HTML readonly attribute.
+ *
+ * Compares the first two arguments and if identical marks as readonly
+ *
+ * This function is deprecated, and cannot be used on PHP >= 8.1.
+ *
+ * @since 4.9.0
+ * @deprecated 5.9.0 Use `wp_readonly` introduced in 5.9.0.
+ *
+ * @see wp_readonly()
+ *
+ * @param mixed $readonly One of the values to compare
+ * @param mixed $current  (true) The other value to compare if not just true
+ * @param bool  $echo     Whether to echo or just return the string
+ * @return string HTML attribute or empty string
+ */
+function readonly( $readonly, $current = true, $echo = true ) {
+       _deprecated_function( __FUNCTION__, '5.9.0', 'wp_readonly()' );
+       return wp_readonly( $readonly, $current, $echo );
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/src/wp-includes/php-compat/readonly.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunitmultisitexml"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/multisite.xml</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/multisite.xml 2021-08-09 14:51:05 UTC (rev 51585)
+++ trunk/tests/phpunit/multisite.xml   2021-08-09 17:19:21 UTC (rev 51586)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5,6 +5,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                backupGlobals="false"
</span><span class="cx" style="display: block; padding: 0 10px">                colors="true"
</span><span class="cx" style="display: block; padding: 0 10px">                beStrictAboutTestsThatDoNotTestAnything="true"
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                beStrictAboutOutputDuringTests="true"
</ins><span class="cx" style="display: block; padding: 0 10px">                 >
</span><span class="cx" style="display: block; padding: 0 10px">        <php>
</span><span class="cx" style="display: block; padding: 0 10px">                <const name="WP_TESTS_MULTISITE" value="1" />
</span></span></pre></div>
<a id="trunktestsphpunittestsgeneraltemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/general/template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/general/template.php    2021-08-09 14:51:05 UTC (rev 51585)
+++ trunk/tests/phpunit/tests/general/template.php      2021-08-09 17:19:21 UTC (rev 51586)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -572,55 +572,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @ticket 9862
-        * @ticket 51166
-        * @dataProvider data_selected_and_checked_with_equal_values
-        *
-        * @covers ::selected
-        * @covers ::checked
-        */
-       function test_selected_and_checked_with_equal_values( $selected, $current ) {
-               $this->assertSame( " selected='selected'", selected( $selected, $current, false ) );
-               $this->assertSame( " checked='checked'", checked( $selected, $current, false ) );
-       }
-
-       function data_selected_and_checked_with_equal_values() {
-               return array(
-                       array( 'foo', 'foo' ),
-                       array( '1', 1 ),
-                       array( '1', true ),
-                       array( 1, 1 ),
-                       array( 1, true ),
-                       array( true, true ),
-                       array( '0', 0 ),
-                       array( 0, 0 ),
-                       array( '', false ),
-                       array( false, false ),
-               );
-       }
-
-       /**
-        * @ticket 9862
-        * @ticket 51166
-        * @dataProvider data_selected_and_checked_with_non_equal_values
-        *
-        * @covers ::selected
-        * @covers ::checked
-        */
-       function test_selected_and_checked_with_non_equal_values( $selected, $current ) {
-               $this->assertSame( '', selected( $selected, $current, false ) );
-               $this->assertSame( '', checked( $selected, $current, false ) );
-       }
-
-       function data_selected_and_checked_with_non_equal_values() {
-               return array(
-                       array( '0', '' ),
-                       array( 0, '' ),
-                       array( 0, false ),
-               );
-       }
-
-       /**
</del><span class="cx" style="display: block; padding: 0 10px">          * @ticket 44183
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @covers ::get_the_archive_title
</span></span></pre></div>
<a id="trunktestsphpunittestsgeneraltemplate_CheckedSelectedHelperphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/tests/general/template_CheckedSelectedHelper.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/general/template_CheckedSelectedHelper.php                              (rev 0)
+++ trunk/tests/phpunit/tests/general/template_CheckedSelectedHelper.php        2021-08-09 17:19:21 UTC (rev 51586)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,246 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * A set of unit tests for the __checked_selected_helper() and associated functions in wp-includes/general-template.php.
+ *
+ * @group general
+ */
+
+class Tests_General_Template_CheckedSelectedHelper extends WP_UnitTestCase {
+
+       /**
+        * List of functions using the __checked_selected_helper() function.
+        *
+        * Doesn't list the conditionally available `readonly` function on purpose.
+        *
+        * @var array
+        */
+       private $child_functions = array(
+               'selected'    => true,
+               'checked'     => true,
+               'disabled'    => true,
+               'wp_readonly' => true,
+       );
+
+       /**
+        * Tests that the return value for selected() is as expected with equal values.
+        *
+        * @ticket 53858
+        * @covers ::selected
+        */
+       public function test_selected_with_equal_values() {
+               $this->assertSame( " selected='selected'", selected( 'foo', 'foo', false ) );
+       }
+
+       /**
+        * Tests that the return value for checked() is as expected with equal values.
+        *
+        * @ticket 53858
+        * @covers ::checked
+        */
+       public function test_checked_with_equal_values() {
+               $this->assertSame( " checked='checked'", checked( 'foo', 'foo', false ) );
+       }
+
+       /**
+        * Tests that the return value for disabled() is as expected with equal values.
+        *
+        * @ticket 53858
+        * @covers ::disabled
+        */
+       public function test_disabled_with_equal_values() {
+               $this->assertSame( " disabled='disabled'", disabled( 'foo', 'foo', false ) );
+       }
+
+       /**
+        * Tests that the return value for readonly() is as expected with equal values.
+        *
+        * @ticket 53858
+        * @covers ::readonly
+        */
+       public function test_readonly_with_equal_values() {
+               if ( ! function_exists( 'readonly' ) ) {
+                       $this->markTestSkipped( 'readonly() function is not available on PHP 8.1' );
+               }
+
+               $this->setExpectedDeprecated( 'readonly' );
+
+               // Call the function via a variable to prevent a parse error for this file on PHP 8.1.
+               $fn = 'readonly';
+               $this->assertSame( " readonly='readonly'", $fn( 'foo', 'foo', false ) );
+       }
+
+       /**
+        * Tests that the return value for wp_readonly() is as expected with equal values.
+        *
+        * @ticket 53858
+        * @covers ::wp_readonly
+        */
+       public function test_wp_readonly_with_equal_values() {
+               $this->assertSame( " readonly='readonly'", wp_readonly( 'foo', 'foo', false ) );
+       }
+
+       /**
+        * @dataProvider data_equal_values
+        *
+        * @ticket 9862
+        * @ticket 51166
+        * @ticket 53858
+        * @covers ::__checked_selected_helper
+        *
+        * @param mixed $helper  One of the values to compare.
+        * @param mixed $current The other value to compare.
+        */
+       public function test_checked_selected_helper_with_equal_values( $helper, $current ) {
+               $this->assertSame( " test='test'", __checked_selected_helper( $helper, $current, false, 'test' ) );
+       }
+
+       /**
+        * Data provider.
+        *
+        * @return array
+        */
+       public function data_equal_values() {
+               return array(
+                       'same value, "foo"; 1: string; 2: string'   => array( 'foo', 'foo' ),
+                       'same value, 1; 1: string; 2: int'          => array( '1', 1 ),
+                       'same value, 1; 1: string; 2: float'        => array( '1', 1.0 ),
+                       'same value, 1; 1: string; 2: bool true'    => array( '1', true ),
+                       'same value, 1; 1: int; 2: int'             => array( 1, 1 ),
+                       'same value, 1; 1: int; 2: float'           => array( 1, 1.0 ),
+                       'same value, 1; 1: int; 2: bool true'       => array( 1, true ),
+                       'same value, 1; 1: float; 2: bool true'     => array( 1.0, true ),
+                       'same value, 1; 1: bool true; 2: bool true' => array( true, true ),
+                       'same value, 1; 1: float 1.0; 2: float calculation 1.0' => array( 1.0, 3 / 3 ),
+                       'same value, 0; 1: string; 2: int'          => array( '0', 0 ),
+                       'same value, 0; 1: string; 2: float'        => array( '0', 0.0 ),
+                       'same value, 0; 1: int; 2: int'             => array( 0, 0 ),
+                       'same value, 0; 1: int; 2: float'           => array( 0, 0.0 ),
+                       'same value, empty string; 1: string; 2: string' => array( '', '' ),
+                       'same value, empty string; 1: empty string; 2: bool false' => array( '', false ),
+                       'same value, empty string; 1: bool false; 2: bool false' => array( false, false ),
+                       'same value, empty string; 1: empty string; 2: null' => array( '', null ),
+                       'same value, empty string; 1: bool false; 2: null' => array( false, null ),
+                       'same value, null; 1: null; 2: null'        => array( null, null ),
+               );
+       }
+
+       /**
+        * @dataProvider data_non_equal_values
+        *
+        * @ticket 9862
+        * @ticket 51166
+        * @ticket 53858
+        * @covers ::__checked_selected_helper
+        *
+        * @param mixed $helper  One of the values to compare.
+        * @param mixed $current The other value to compare.
+        */
+       public function test_checked_selected_helper_with_non_equal_values( $helper, $current ) {
+               $this->assertSame( '', __checked_selected_helper( $helper, $current, false, 'test' ) );
+       }
+
+       /**
+        * Data provider.
+        *
+        * @return array
+        */
+       public function data_non_equal_values() {
+               return array(
+                       '1: string foo; 2: string bar' => array( 'foo', 'bar' ),
+                       '1: string 0; 2: empty string' => array( '0', '' ),
+                       '1: string 0; 2: null'         => array( '0', null ),
+                       '1: int 0; 2: empty string'    => array( 0, '' ),
+                       '1: int 0; 2: bool true'       => array( 0, true ),
+                       '1: int 0; 2: bool false'      => array( 0, false ),
+                       '1: int 0; 2: null'            => array( 0, null ),
+                       '1: float 0; 2: empty string'  => array( 0.0, '' ),
+                       '1: float 0; 2: bool true'     => array( 0.0, true ),
+                       '1: float 0; 2: bool false'    => array( 0.0, false ),
+                       '1: float 0; 2: null'          => array( 0.0, null ),
+                       '1: null; 2: bool true'        => array( null, true ),
+                       '1: null 0; 2: string "foo"'   => array( null, 'foo' ),
+                       '1: int 1; 2: float 1.5'       => array( 1, 1.5 ),
+               );
+       }
+
+       /**
+        * Tests that the `$echo` parameter is handled correctly and that even when the output is echoed out,
+        * the text is also returned.
+        *
+        * @ticket 53858
+        * @covers ::__checked_selected_helper
+        */
+       public function test_checked_selected_helper_echoes_result_by_default() {
+               $expected = " disabled='disabled'";
+               $this->expectOutputString( $expected );
+               $this->assertSame( $expected, disabled( 'foo', 'foo' ) );
+       }
+
+       /**
+        * Tests that the function compares against `true` when the second parameter is not passed.
+        *
+        * @dataProvider data_checked_selected_helper_default_value_for_second_parameter
+        *
+        * @ticket 53858
+        * @covers ::__checked_selected_helper
+        * @covers ::selected
+        * @covers ::checked
+        * @covers ::disabled
+        * @covers ::wp_readonly
+        *
+        * @param mixed $input         Input value
+        * @param mixed $expect_output Optional. Whether output is expected. Defaults to false.
+        */
+       public function test_checked_selected_helper_default_value_for_second_parameter( $input, $expect_output = false ) {
+               $fn       = array_rand( $this->child_functions );
+               $expected = '';
+
+               if ( false !== $expect_output ) {
+                       $expected = " {$fn}='{$fn}'";
+                       if ( 'wp_readonly' === $fn ) {
+                               // Account for the function name not matching the expected output string.
+                               $expected = " readonly='readonly'";
+                       }
+
+                       // Only set output expectation when output is expected, so the test will fail on unexpected output.
+                       $this->expectOutputString( $expected );
+               }
+
+               // Function will always return the value, even when echoing it out.
+               $this->assertSame( $expected, $fn( $input ) );
+       }
+
+       /**
+        * Data provider.
+        *
+        * @return array
+        */
+       public function data_checked_selected_helper_default_value_for_second_parameter() {
+               return array(
+                       'truthy; boolean true'          => array(
+                               'input'         => true,
+                               'expect_output' => true,
+                       ),
+                       'truthy; int 1'                 => array(
+                               'input'         => 1,
+                               'expect_output' => true,
+                       ),
+                       'truthy; string 1'              => array(
+                               'input'         => '1',
+                               'expect_output' => true,
+                       ),
+                       'truthy, but not equal to true' => array(
+                               'input' => 'foo',
+                       ),
+                       'falsy; null'                   => array(
+                               'input' => null,
+                       ),
+                       'falsy; bool false'             => array(
+                               'input' => false,
+                       ),
+                       'falsy; int 0'                  => array(
+                               'input' => 0,
+                       ),
+               );
+       }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/tests/general/template_CheckedSelectedHelper.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span></div>

</body>
</html>