Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
9.71% covered (danger)
9.71%
10 / 103
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_textformatter_s9e_bbcode_merger_test
9.71% covered (danger)
9.71%
10 / 103
50.00% covered (danger)
50.00%
1 / 2
4.94
0.00% covered (danger)
0.00%
0 / 1
 test_merge_bbcodes
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
1
 get_merge_bbcodes_tests
0.00% covered (danger)
0.00%
0 / 93
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14class phpbb_textformatter_s9e_bbcode_merger_test extends phpbb_test_case
15{
16    /**
17    * @dataProvider get_merge_bbcodes_tests
18    */
19    public function test_merge_bbcodes($usage_without, $template_without, $usage_with, $template_with, $expected_usage, $expected_template)
20    {
21        $container     = $this->get_test_case_helpers()->set_s9e_services();
22        $factory       = $container->get('text_formatter.s9e.factory');
23        $bbcode_merger = new \phpbb\textformatter\s9e\bbcode_merger($factory);
24
25        $without = ['usage' => $usage_without, 'template' => $template_without];
26        $with    = ['usage' => $usage_with,    'template' => $template_with];
27        $merged  = $bbcode_merger->merge_bbcodes($without, $with);
28
29        // Normalize the expected template's whitespace to match the default indentation
30        $expected_template = str_replace("\n\t\t\t\t", "\n", $expected_template);
31        $expected_template = str_replace("\t",         '  ', $expected_template);
32
33        $this->assertSame($expected_usage,    $merged['usage']);
34        $this->assertSame($expected_template, $merged['template']);
35    }
36
37    public static function get_merge_bbcodes_tests()
38    {
39        return [
40            [
41                '[x]{TEXT}[/x]',
42                '<b>{TEXT}</b>',
43
44                '[x={TEXT1}]{TEXT}[/x]',
45                '<b title="{TEXT1}">{TEXT}</b>',
46
47                '[x={TEXT1?}]{TEXT}[/x]',
48                '<b>
49                    <xsl:if test="@x">
50                        <xsl:attribute name="title">
51                            <xsl:value-of select="@x"/>
52                        </xsl:attribute>
53                    </xsl:if>
54                    <xsl:apply-templates/>
55                </b>'
56            ],
57            [
58                // The tokens' numbering differs between versions
59                '[x]{TEXT}[/x]',
60                '<b>{TEXT}</b>',
61
62                '[x={TEXT1}]{TEXT2}[/x]',
63                '<b title="{TEXT1}">{TEXT2}</b>',
64
65                '[x={TEXT1?}]{TEXT2}[/x]',
66                '<b>
67                    <xsl:if test="@x">
68                        <xsl:attribute name="title">
69                            <xsl:value-of select="@x"/>
70                        </xsl:attribute>
71                    </xsl:if>
72                    <xsl:apply-templates/>
73                </b>'
74            ],
75            [
76                '[x]{URL}[/x]',
77                '<a href="{URL}">{URL}</a>',
78
79                '[x={URL}]{TEXT}[/x]',
80                '<a href="{URL}">{TEXT}</a>',
81
82                '[x={URL;useContent}]{TEXT}[/x]',
83                '<a href="{@x}">
84                    <xsl:apply-templates/>
85                </a>'
86            ],
87            [
88                '[x]{URL}[/x]',
89                '<a href="{URL}">{L_GO_TO}: {URL}</a>',
90
91                '[x={URL}]{TEXT}[/x]',
92                '<a href="{URL}">{L_GO_TO}: {TEXT}</a>',
93
94                '[x={URL;useContent}]{TEXT}[/x]',
95                '<a href="{@x}">{L_GO_TO}: <xsl:apply-templates/></a>'
96            ],
97            [
98                // Test that unsafe BBCodes can still be merged
99                '[script]{TEXT}[/script]',
100                '<script>{TEXT}</script>',
101
102                '[script={TEXT1}]{TEXT2}[/script]',
103                '<script type="{TEXT1}">{TEXT2}</script>',
104
105                '[script={TEXT1?}]{TEXT2}[/script]',
106                '<script>
107                    <xsl:if test="@script">
108                        <xsl:attribute name="type">
109                            <xsl:value-of select="@script"/>
110                        </xsl:attribute>
111                    </xsl:if>
112                    <xsl:apply-templates/>
113                </script>'
114            ],
115            [
116                // https://www.phpbb.com/community/viewtopic.php?p=14848281#p14848281
117                '[note]{TEXT}[/note]',
118                '<span class="prime_bbcode_note_spur" onmouseover="show_note(this);" onmouseout="hide_note(this);" onclick="lock_note(this);"></span><span class="prime_bbcode_note">{TEXT}</span>',
119
120                '[note={TEXT1}]{TEXT2}[/note]',
121                '<span class="prime_bbcode_note_text" onmouseover="show_note(this);" onmouseout="hide_note(this);" onclick="lock_note(this);">{TEXT1}</span><span class="prime_bbcode_note_spur" onmouseover="show_note(this);" onmouseout="hide_note(this);" onclick="lock_note(this);"></span><span class="prime_bbcode_note">{TEXT2}</span>',
122
123                '[note={TEXT1?}]{TEXT2}[/note]',
124                '<xsl:if test="@note">
125                    <span class="prime_bbcode_note_text" onmouseover="show_note(this);" onmouseout="hide_note(this);" onclick="lock_note(this);">
126                        <xsl:value-of select="@note"/>
127                    </span>
128                </xsl:if>
129                <span class="prime_bbcode_note_spur" onmouseover="show_note(this);" onmouseout="hide_note(this);" onclick="lock_note(this);"/>
130                <span class="prime_bbcode_note">
131                    <xsl:apply-templates/>
132                </span>'
133            ],
134            [
135                // https://www.phpbb.com/community/viewtopic.php?p=14768441#p14768441
136                '[MI]{TEXT}[/MI]',
137                '<span style="color:red">MI:</span> <span style="color:#f6efe2">{TEXT}</span>',
138
139                '[MI={TEXT2}]{TEXT1}[/MI]',
140                '<span style="color:red">MI for: "{TEXT2}":</span> <span style="color:#f6efe2">{TEXT1}</span>',
141
142                '[MI={TEXT2?}]{TEXT1}[/MI]',
143                '<span style="color:red">MI<xsl:if test="@mi"> for: "<xsl:value-of select="@mi"/>"</xsl:if>:</span>
144                <xsl:text> </xsl:text>
145                <span style="color:#f6efe2">
146                    <xsl:apply-templates/>
147                </span>'
148            ],
149            [
150                // https://www.phpbb.com/community/viewtopic.php?p=14700506#p14700506
151                '[spoiler]{TEXT}[/spoiler]',
152                '<span class="spoiler"> {TEXT}</span>',
153
154                '[spoiler={TEXT1}]{TEXT2}[/spoiler]',
155                '<div class="spoiler"><small> {TEXT1}</small>{TEXT2}</div>',
156
157                '[spoiler={TEXT1?}]{TEXT2}[/spoiler]',
158                '<xsl:choose>
159                    <xsl:when test="@spoiler">
160                        <div class="spoiler">
161                            <small>
162                                <xsl:text> </xsl:text>
163                                <xsl:value-of select="@spoiler"/>
164                            </small>
165                            <xsl:apply-templates/>
166                        </div>
167                    </xsl:when>
168                    <xsl:otherwise>
169                        <span class="spoiler">
170                            <xsl:text> </xsl:text>
171                            <xsl:apply-templates/>
172                        </span>
173                    </xsl:otherwise>
174                </xsl:choose>'
175            ],
176            [
177                // https://www.phpbb.com/community/viewtopic.php?p=14859676#p14859676
178                '[AE]{TEXT}[/AE]',
179                '<table width="100%" border="1">
180                    <tr><td width="100%" align="center">
181                    <table width="100%" border="0">
182                      <tr>
183                        <td width="100%" bgcolor="#E1E4F2">
184                          <table width="100%" border="0" bgcolor="#F5F5FF">
185                            <tr>
186                              <td width="1%" bgcolor="#000000" nowrap align="left">
187                                <font color="#FFFFFF" face="Arial"><font size="1"><b>&nbsp;ACTIVE EFFECTS & CONDITIONS&nbsp;</b></font></font></td>
188                              <td width="99%">&nbsp;</td>
189                            </tr>
190                            <tr>
191                              <td width="100%" bgcolor="#FFE5BA" colspan="2">
192                                <table width="100%" cellpadding="2">
193                                  <tr>
194                                    <td width="100%" align="left" valign="top">
195                                      {TEXT}
196                                    </td>
197                                  </tr>
198                                </table>
199                              </td>
200                            </tr>
201                          </table>
202                        </td>
203                      </tr>
204                    </table>
205                </td></tr>
206                </table>
207                <p>&nbsp;</p>',
208
209                '[AE={TEXT1}]{TEXT2}[/AE]',
210                '<table width="100%" border="1">
211                    <tr><td width="100%" align="center">
212                    <table width="100%" border="0">
213                      <tr>
214                        <td width="100%" bgcolor="#E1E4F2">
215                          <table width="100%" border="0" bgcolor="#F5F5FF">
216                            <tr>
217                              <td width="1%" bgcolor="#000000" nowrap align="left">
218                                <font color="#FFFFFF" face="Arial"><font size="1"><b>&nbsp; {TEXT1}&nbsp;</b></font></font></td>
219                              <td width="99%">&nbsp;</td>
220                            </tr>
221                            <tr>
222                              <td width="100%" bgcolor="#FFE5BA" colspan="2">
223                                <table width="100%" cellpadding="2">
224                                  <tr>
225                                    <td width="100%" align="left" valign="top">
226                                      {TEXT2}
227                                    </td>
228                                  </tr>
229                                </table>
230                              </td>
231                            </tr>
232                          </table>
233                        </td>
234                      </tr>
235                    </table>
236                    </td></tr>
237                </table>
238                <p>&nbsp;</p>',
239
240                '[AE={TEXT1?}]{TEXT2}[/AE]',
241                '<table width="100%" border="1">
242                    <tr>
243                        <td width="100%" align="center">
244                            <table width="100%" border="0">
245                                <tr>
246                                    <td width="100%" bgcolor="#E1E4F2">
247                                        <table width="100%" border="0" bgcolor="#F5F5FF">
248                                            <tr>
249                                                <td width="1%" bgcolor="#000000" nowrap="nowrap" align="left">
250                                                    <font color="#FFFFFF" face="Arial">
251                                                        <font size="1">
252                                                            <b> <xsl:choose><xsl:when test="@ae"><xsl:text> </xsl:text><xsl:value-of select="@ae"/></xsl:when><xsl:otherwise>ACTIVE EFFECTS &amp; CONDITIONS</xsl:otherwise></xsl:choose> </b>
253                                                        </font>
254                                                    </font>
255                                                </td>
256                                                <td width="99%"> </td>
257                                            </tr>
258                                            <tr>
259                                                <td width="100%" bgcolor="#FFE5BA" colspan="2">
260                                                    <table width="100%" cellpadding="2">
261                                                        <tr>
262                                                            <td width="100%" align="left" valign="top">
263                                                                <xsl:apply-templates/>
264                                                            </td>
265                                                        </tr>
266                                                    </table>
267                                                </td>
268                                            </tr>
269                                        </table>
270                                    </td>
271                                </tr>
272                            </table>
273                        </td>
274                    </tr>
275                </table>
276                <p> </p>'
277            ],
278            [
279                // https://www.phpbb.com/community/viewtopic.php?f=438&t=2530451
280                '[issue]{NUMBER}[/issue]',
281                '<a href="/default/issues/{NUMBER}"> Issue #{NUMBER}</a>',
282
283                '[issue={SIMPLETEXT}]{NUMBER}[/issue]',
284                '<a href="/{SIMPLETEXT}/issues/{NUMBER}"> Issue #{NUMBER} ({SIMPLETEXT})</a>',
285
286                '[issue={SIMPLETEXT?}]{NUMBER}[/issue]',
287                '<a>
288                    <xsl:choose>
289                        <xsl:when test="@issue"><xsl:attribute name="href">/<xsl:value-of select="@issue"/>/issues/<xsl:value-of select="@content"/></xsl:attribute> Issue #<xsl:value-of select="@content"/> (<xsl:value-of select="@issue"/>)</xsl:when>
290                        <xsl:otherwise><xsl:attribute name="href">/default/issues/<xsl:value-of select="@content"/></xsl:attribute> Issue #<xsl:value-of select="@content"/></xsl:otherwise>
291                    </xsl:choose>
292                </a>'
293            ],
294        ];
295    }
296}