script_tag: changelog, doc + test with default arg

This commit is contained in:
Chl 2022-04-18 16:43:20 +02:00
parent a8d5b894c9
commit 4fd7ac5830
No known key found for this signature in database
GPG Key ID: 80012B734F21B934
4 changed files with 15 additions and 4 deletions

View File

@ -189,8 +189,8 @@ if (! function_exists('script_tag')) {
*
* Generates link to a JS file
*
* @param mixed $src Script source or an array
* @param bool $indexPage Should indexPage be added to the JS path
* @param array|string $src Script source or an array of attributes
* @param bool $indexPage Should indexPage be added to the JS path
*/
function script_tag($src = '', bool $indexPage = false): string
{

View File

@ -269,6 +269,16 @@ final class HTMLHelperTest extends CIUnitTestCase
$this->assertSame($expected, script_tag($target));
}
/**
* This test has probably no real-world value but may help detecting
* a change in the default behaviour.
*/
public function testScriptTagWithoutAnyArg()
{
$expected = '<script src="http://example.com/" type="text/javascript"></script>';
$this->assertSame($expected, script_tag());
}
public function testLinkTag()
{
$target = 'css/mystyles.css';

View File

@ -38,6 +38,7 @@ Enhancements
- The log format has also changed. If users are depending on the log format in their apps, the new log format is "<1-based count> <cleaned filepath>(<line>): <class><function><args>"
- Added support for webp files to **app/Config/Mimes.php**.
- Added 4th parameter ``$includeDir`` to ``get_filenames()``. See :php:func:`get_filenames`.
- HTML helper ``script_tag()`` now uses ``null`` values to write boolean attributes in minimized form: ``<script src="..." defer />``. See the sample code for :php:func:`script_tag`.
Changes
*******

View File

@ -104,8 +104,8 @@ The following functions are available:
.. php:function:: script_tag([$src = ''[, $indexPage = false]])
:param mixed $src: The source name of a JavaScript file
:param bool $indexPage: Whether to treat ``$src`` as a routed URI string
:param array|string $src: The source name or URL of a JavaScript file, or an associative array specifying the attributes
:param bool $indexPage: Whether to treat ``$src`` as a routed URI string
:returns: HTML script tag
:rtype: string