Skip to content

Commit 4fd7ac5

Browse files
committed
script_tag: changelog, doc + test with default arg
1 parent a8d5b89 commit 4fd7ac5

4 files changed

Lines changed: 15 additions & 4 deletions

File tree

system/Helpers/html_helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ function doctype(string $type = 'html5'): string
189189
*
190190
* Generates link to a JS file
191191
*
192-
* @param mixed $src Script source or an array
193-
* @param bool $indexPage Should indexPage be added to the JS path
192+
* @param array|string $src Script source or an array of attributes
193+
* @param bool $indexPage Should indexPage be added to the JS path
194194
*/
195195
function script_tag($src = '', bool $indexPage = false): string
196196
{

tests/system/Helpers/HTMLHelperTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,16 @@ public function testScriptTagWithSrcAndAttributes()
269269
$this->assertSame($expected, script_tag($target));
270270
}
271271

272+
/**
273+
* This test has probably no real-world value but may help detecting
274+
* a change in the default behaviour.
275+
*/
276+
public function testScriptTagWithoutAnyArg()
277+
{
278+
$expected = '<script src="http://example.com/" type="text/javascript"></script>';
279+
$this->assertSame($expected, script_tag());
280+
}
281+
272282
public function testLinkTag()
273283
{
274284
$target = 'css/mystyles.css';

user_guide_src/source/changelogs/v4.2.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Enhancements
3838
- 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>"
3939
- Added support for webp files to **app/Config/Mimes.php**.
4040
- Added 4th parameter ``$includeDir`` to ``get_filenames()``. See :php:func:`get_filenames`.
41+
- 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`.
4142

4243
Changes
4344
*******

user_guide_src/source/helpers/html_helper.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ The following functions are available:
104104

105105
.. php:function:: script_tag([$src = ''[, $indexPage = false]])
106106
107-
:param mixed $src: The source name of a JavaScript file
108-
:param bool $indexPage: Whether to treat ``$src`` as a routed URI string
107+
:param array|string $src: The source name or URL of a JavaScript file, or an associative array specifying the attributes
108+
:param bool $indexPage: Whether to treat ``$src`` as a routed URI string
109109
:returns: HTML script tag
110110
:rtype: string
111111

0 commit comments

Comments
 (0)