[ticket/16237] fix errors

PHPBB3-16237
This commit is contained in:
hanakin 2020-05-06 16:28:14 -10:00
parent c32a1b1278
commit 02fcfe5700
6 changed files with 19 additions and 18 deletions

View file

@ -164,7 +164,7 @@ class icon extends \Twig\Extension\AbstractExtension
'CLASSES' => (string) $classes, 'CLASSES' => (string) $classes,
'ICON' => (string) $icon, 'ICON' => (string) $icon,
'SOURCE' => (string) $source, 'SOURCE' => (string) $source,
'TITLE' => (string) $title, 'TITLE' => (string) $title && $type === 'svg' ? unique_id() : '',
'VIEW_BOX' => (string) $view_box, 'VIEW_BOX' => (string) $view_box,
'S_HIDDEN' => (bool) $hidden, 'S_HIDDEN' => (bool) $hidden,
]); ]);
@ -258,7 +258,7 @@ class icon extends \Twig\Extension\AbstractExtension
* 'lock': topicrow.S_TOPIC_LOCKED, * 'lock': topicrow.S_TOPIC_LOCKED,
* 'fire': topicrow.S_TOPIC_HOT, * 'fire': topicrow.S_TOPIC_HOT,
* 'file': true, * 'file': true,
* }, 'MY_TITLE', true) }} * }, lang('MY_TITLE'), true) }}
* *
* @param array $icons Array of icons and their booleans * @param array $icons Array of icons and their booleans
* @return string The first 'true' icon * @return string The first 'true' icon

View file

@ -1,3 +1,4 @@
{% apply spaceless %} {% apply spaceless %}
<i class="iconify o-icon-src-{{ SOURCE }} o-icon{{ CLASSES ? ' ' ~ CLASSES }}"{% if S_HIDDEN %}{% if TITLE %} title="{{ TITLE }}"{% endif %} aria-hidden="true"{% endif %} data-icon="{{ ICON }}" data-inline="true"{{ ATTRIBUTES }}></i>{% if TITLE %}<span{% if S_HIDDEN %} class="sr-only"{% endif %}>{{ lang(TITLE) }}</span>{% endif %} <i class="iconify o-icon-src-{{ SOURCE }} o-icon{{ CLASSES ? ' ' ~ CLASSES }}"{% if S_HIDDEN %}{% if TITLE %} title="{{ TITLE }}"{% endif %} aria-hidden="true"{% endif %} data-icon="{{ ICON }}" data-inline="true"{{ ATTRIBUTES }}></i>
{% if TITLE %}<span{% if S_HIDDEN %} class="sr-only"{% endif %}>{{ TITLE }}</span>{% endif %}
{% endapply %} {% endapply %}

View file

@ -1,6 +1,4 @@
{% apply spaceless %} {% apply spaceless %}
{% set TITLE_ID = TITLE ? TITLE|lower|replace({' ': '_'}) ~ '-' ~ random() %}
<svg class="o-icon o-icon-svg svg-{{ ICON ~ (CLASSES ? ' ' ~ CLASSES) }}" xmlns="http://www.w3.org/2000/svg" viewBox="{{ VIEW_BOX }}"{% if TITLE %}{% if S_HIDDEN %} aria-hidden="true"{% endif %} aria-labelledby="{{ TITLE_ID }}"{% endif %} role="img"{{ ATTRIBUTES }}> <svg class="o-icon o-icon-svg svg-{{ ICON ~ (CLASSES ? ' ' ~ CLASSES) }}" xmlns="http://www.w3.org/2000/svg" viewBox="{{ VIEW_BOX }}"{% if TITLE %}{% if S_HIDDEN %} aria-hidden="true"{% endif %} aria-labelledby="{{ TITLE_ID }}"{% endif %} role="img"{{ ATTRIBUTES }}>
{% if TITLE %}<title id="{{ TITLE_ID }}">{{ TITLE }}</title>{% endif %} {% if TITLE %}<title id="{{ TITLE_ID }}">{{ TITLE }}</title>{% endif %}

View file

@ -87,14 +87,14 @@
<!-- IF U_ACP --> <!-- IF U_ACP -->
<li data-last-responsive="true"> <li data-last-responsive="true">
<a href="{U_ACP}" title="{L_ACP}" role="menuitem"> <a href="{U_ACP}" title="{L_ACP}" role="menuitem">
{{ Icon('iconify', 'fa:cogs', '', false) }}<span>{{ lang('ACP_SHORT') }}</span> {{ Icon('iconify', 'fa:cogs', lang('ACP_SHORT'), false) }}
</a> </a>
</li> </li>
<!-- ENDIF --> <!-- ENDIF -->
<!-- IF U_MCP --> <!-- IF U_MCP -->
<li data-last-responsive="true"> <li data-last-responsive="true">
<a href="{U_MCP}" title="{L_MCP}" role="menuitem"> <a href="{U_MCP}" title="{L_MCP}" role="menuitem">
{{ Icon('iconify', 'fa:gavel', '', false) }}<span>{{ lang('MCP_SHORT') }}</span> {{ Icon('iconify', 'fa:gavel', lang('MCP_SHORT'), false) }}
</a> </a>
</li> </li>
<!-- ENDIF --> <!-- ENDIF -->

View file

@ -431,8 +431,8 @@ class phpbb_template_extension_test extends phpbb_template_template_test_case
[ [
'ICON_USER' => 'User icon', 'ICON_USER' => 'User icon',
], ],
'<svg class="o-icon o-icon-svg svg-404 my-class" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" aria-labelledby="icon_user-123456789" role="img"> '<svg class="o-icon o-icon-svg svg-404 my-class" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" aria-labelledby="{unique_id}" role="img">
<title id="icon_user-123456789">User icon</title> <title id="{unique_id}">User icon</title>
<g fill="none" fill-rule="evenodd"> <g fill="none" fill-rule="evenodd">
<path fill="#D8D8D8" d="M0 0h512v512H0z"></path> <path fill="#D8D8D8" d="M0 0h512v512H0z"></path>
<path fill="#979797" fill-rule="nonzero" d="M8 6.586l496 496v2.828L8 9.414z"></path> <path fill="#979797" fill-rule="nonzero" d="M8 6.586l496 496v2.828L8 9.414z"></path>
@ -453,8 +453,8 @@ class phpbb_template_extension_test extends phpbb_template_template_test_case
[ [
'ICON_PHONE' => 'Phone icon', 'ICON_PHONE' => 'Phone icon',
], ],
'<svg class="o-icon o-icon-svg svg-phone" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-labelledby="icon_phone-123456789" role="img"> '<svg class="o-icon o-icon-svg svg-phone" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-labelledby="{unique_id}" role="img">
<title id="icon_phone-123456789">Phone icon</title> <title id="{unique_id}">Phone icon</title>
<path fill="none" d="M0 0h24v24H0z"></path> <path fill="none" d="M0 0h24v24H0z"></path>
<path d="M20.01 15.38c-1.23 0-2.42-.2-3.53-.56-.35-.12-.74-.03-1.01.24l-1.57 1.97c-2.83-1.35-5.48-3.9-6.89-6.83l1.95-1.66c.27-.28.35-.67.24-1.02-.37-1.11-.56-2.3-.56-3.53 0-.54-.45-.99-.99-.99H4.19C3.65 3 3 3.24 3 3.99 3 13.28 10.73 21 20.01 21c.71 0 .99-.63.99-1.18v-3.45c0-.54-.45-.99-.99-.99z"></path> <path d="M20.01 15.38c-1.23 0-2.42-.2-3.53-.56-.35-.12-.74-.03-1.01.24l-1.57 1.97c-2.83-1.35-5.48-3.9-6.89-6.83l1.95-1.66c.27-.28.35-.67.24-1.02-.37-1.11-.56-2.3-.56-3.53 0-.54-.45-.99-.99-.99H4.19C3.65 3 3 3.24 3 3.99 3 13.28 10.73 21 20.01 21c.71 0 .99-.63.99-1.18v-3.45c0-.54-.45-.99-.99-.99z"></path>
</svg>', </svg>',
@ -474,8 +474,8 @@ class phpbb_template_extension_test extends phpbb_template_template_test_case
[ [
'ICON_PENCIL' => 'Pencil icon', 'ICON_PENCIL' => 'Pencil icon',
], ],
'<svg class="o-icon o-icon-svg svg-pencil my-svg-class" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" aria-labelledby="icon_pencil-123456789" role="img" data-ajax="my_ajax_callback"> '<svg class="o-icon o-icon-svg svg-pencil my-svg-class" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" aria-labelledby="{unique_id}" role="img" data-ajax="my_ajax_callback">
<title id="icon_pencil-123456789">Pencil icon</title> <title id="{unique_id}">Pencil icon</title>
<path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"></path> <path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"></path>
<path d="M0 0h24v24H0z" fill="none"></path> <path d="M0 0h24v24H0z" fill="none"></path>
</svg>', </svg>',
@ -491,8 +491,8 @@ class phpbb_template_extension_test extends phpbb_template_template_test_case
'attributes' => [], 'attributes' => [],
], ],
[], [],
'<svg class="o-icon o-icon-svg svg-404" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" aria-labelledby="just_a_title-123456789" role="img"> '<svg class="o-icon o-icon-svg svg-404" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" aria-labelledby="{unique_id}" role="img">
<title id="just_a_title-123456789">Just a title</title> <title id="{unique_id}">Just a title</title>
<g fill="none" fill-rule="evenodd"> <g fill="none" fill-rule="evenodd">
<path fill="#D8D8D8" d="M0 0h512v512H0z"></path> <path fill="#D8D8D8" d="M0 0h512v512H0z"></path>
<path fill="#979797" fill-rule="nonzero" d="M8 6.586l496 496v2.828L8 9.414z"></path> <path fill="#979797" fill-rule="nonzero" d="M8 6.586l496 496v2.828L8 9.414z"></path>
@ -545,8 +545,10 @@ class phpbb_template_extension_test extends phpbb_template_template_test_case
*/ */
if ($vars['type'] === 'svg' || $vars['icon'] === 'user') if ($vars['type'] === 'svg' || $vars['icon'] === 'user')
{ {
$prefix = strtolower(str_replace(' ', '_', $vars['title'])) . '-'; if (preg_match('#<title id="([a-z0-9]+)">#', $output, $unique_id))
$output = preg_replace('/' . $prefix . '\d+/', $prefix . '123456789', $output); {
$expected = str_replace('{unique_id}', $unique_id[1], $expected);
}
} }
$this->assertEquals($expected, $output, "Testing {$file}"); $this->assertEquals($expected, $output, "Testing {$file}");

View file

@ -1 +1 @@
{{ Icon(type, icon, title, hidden, classes, attributes) }} {{ Icon(type, icon, lang(title), hidden, classes, attributes) }}