Tests_Formatting_WPTexturize::data_whole_posts()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @group formatting
5
 */
6
class Tests_Formatting_WPTexturize extends WP_UnitTestCase
7
{
8
    function test_dashes() 
9
    {
10
        $this->assertEquals('Hey &#8212; boo?', wptexturize('Hey -- boo?'));
11
        $this->assertEquals('<a href="http://xx--xx">Hey &#8212; boo?</a>', wptexturize('<a href="http://xx--xx">Hey -- boo?</a>'));
12
    }
13
14
    function test_disable() 
15
    {
16
        $this->assertEquals('<pre>---&</pre>', wptexturize('<pre>---&</pre>'));
17
        $this->assertEquals('<pre><code></code>--&</pre>', wptexturize('<pre><code></code>--&</pre>'));
18
19
        $this->assertEquals('<code>---&</code>',     wptexturize('<code>---&</code>'));
20
        $this->assertEquals('<kbd>---&</kbd>',       wptexturize('<kbd>---&</kbd>'));
21
        $this->assertEquals('<style>---&</style>',   wptexturize('<style>---&</style>'));
22
        $this->assertEquals('<script>---&</script>', wptexturize('<script>---&</script>'));
23
        $this->assertEquals('<tt>---&</tt>',         wptexturize('<tt>---&</tt>'));
24
25
        $this->assertEquals('<code>href="baba"</code> &#8220;baba&#8221;', wptexturize('<code>href="baba"</code> "baba"'));
26
27
        $enabled_tags_inside_code = '<code>curl -s <a href="http://x/">baba</a> | grep sfive | cut -d "\"" -f 10 &gt; topmp3.txt</code>';
28
        $this->assertEquals($enabled_tags_inside_code, wptexturize($enabled_tags_inside_code));
29
30
        $double_nest = '<pre>"baba"<code>"baba"<pre></pre></code>"baba"</pre>';
31
        $this->assertEquals($double_nest, wptexturize($double_nest));
32
33
        $invalid_nest = '<pre></code>"baba"</pre>';
34
        $this->assertEquals($invalid_nest, wptexturize($invalid_nest));
35
36
    }
37
38
    //WP Ticket #1418
39
    function test_bracketed_quotes_1418() 
40
    {
41
        $this->assertEquals('(&#8220;test&#8221;)', wptexturize('("test")'));
42
        $this->assertEquals('(&#8216;test&#8217;)', wptexturize("('test')"));
43
        $this->assertEquals('(&#8217;twas)', wptexturize("('twas)"));
44
    }
45
46
    //WP Ticket #3810
47
    function test_bracketed_quotes_3810() 
48
    {
49
        $this->assertEquals('A dog (&#8220;Hubertus&#8221;) was sent out.', wptexturize('A dog ("Hubertus") was sent out.'));
50
    }
51
52
    //WP Ticket #4539
53 View Code Duplication
    function test_basic_quotes() 
54
    {
55
        $this->assertEquals('test&#8217;s', wptexturize('test\'s'));
56
57
        $this->assertEquals('&#8216;quoted&#8217;', wptexturize('\'quoted\''));
58
        $this->assertEquals('&#8220;quoted&#8221;', wptexturize('"quoted"'));
59
60
        $this->assertEquals('space before &#8216;quoted&#8217; space after', wptexturize('space before \'quoted\' space after'));
61
        $this->assertEquals('space before &#8220;quoted&#8221; space after', wptexturize('space before "quoted" space after'));
62
63
        $this->assertEquals('(&#8216;quoted&#8217;)', wptexturize('(\'quoted\')'));
64
        $this->assertEquals('{&#8220;quoted&#8221;}', wptexturize('{"quoted"}'));
65
66
        $this->assertEquals('&#8216;qu(ot)ed&#8217;', wptexturize('\'qu(ot)ed\''));
67
        $this->assertEquals('&#8220;qu{ot}ed&#8221;', wptexturize('"qu{ot}ed"'));
68
69
        $this->assertEquals(' &#8216;test&#8217;s quoted&#8217; ', wptexturize(' \'test\'s quoted\' '));
70
        $this->assertEquals(' &#8220;test&#8217;s quoted&#8221; ', wptexturize(' "test\'s quoted" '));
71
    }
72
73
    /**
74
     * @ticket 4539
75
     * @ticket 15241
76
     */
77
    function test_full_sentences_with_unmatched_single_quotes() 
78
    {
79
        $this->assertEquals(
80
            'That means every moment you&#8217;re working on something without it being in the public it&#8217;s actually dying.',
81
            wptexturize("That means every moment you're working on something without it being in the public it's actually dying.")
82
        );
83
    }
84
85
    /**
86
     * @ticket 4539
87
     */
88
    function test_quotes() 
89
    {
90
        $this->assertEquals('&#8220;Quoted String&#8221;', wptexturize('"Quoted String"'));
91
        //$this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"'));
92
        //$this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link and a period</a>&#8221;.', wptexturize('Here is "<a href="http://example.com">a test with a link and a period</a>".'));
93
        $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221; and a space.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>" and a space.'));
94
        $this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a> and some text quoted&#8221;', wptexturize('Here is "<a href="http://example.com">a test with a link</a> and some text quoted"'));
95
        //$this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;, and a comma.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>", and a comma.'));
96
        //$this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;; and a semi-colon.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"; and a semi-colon.'));
97
        //$this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;- and a dash.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"- and a dash.'));
98
        //$this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;&#8230; and ellipses.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"... and ellipses.'));
99
        //$this->assertEquals('Here is &#8220;a test <a href="http://example.com">with a link</a>&#8221;.', wptexturize('Here is "a test <a href="http://example.com">with a link</a>".'));
100
        //$this->assertEquals('Here is &#8220;<a href="http://example.com">a test with a link</a>&#8221;and a work stuck to the end.', wptexturize('Here is "<a href="http://example.com">a test with a link</a>"and a work stuck to the end.'));
101
        $this->assertEquals('A test with a finishing number, &#8220;like 23&#8221;.', wptexturize('A test with a finishing number, "like 23".'));
102
        $this->assertEquals('A test with a number, &#8220;like 62&#8221;, is nice to have.', wptexturize('A test with a number, "like 62", is nice to have.'));
103
    }
104
105
    /**
106
     * @ticket 4539
107
     */
108
    function test_quotes_before_s() 
109
    {
110
        $this->assertEquals('test&#8217;s', wptexturize("test's"));
111
        $this->assertEquals('&#8216;test&#8217;s', wptexturize("'test's"));
112
        $this->assertEquals('&#8216;test&#8217;s&#8217;', wptexturize("'test's'"));
113
        $this->assertEquals('&#8216;string&#8217;', wptexturize("'string'"));
114
        $this->assertEquals('&#8216;string&#8217;s&#8217;', wptexturize("'string's'"));
115
    }
116
117
    /**
118
     * @ticket 4539
119
     */
120
    function test_quotes_before_numbers() 
121
    {
122
        $this->assertEquals('Class of &#8217;99', wptexturize("Class of '99"));
123
        $this->assertEquals('Class of &#8217;99&#8217;s', wptexturize("Class of '99's"));
124
        $this->assertEquals('&#8216;Class of &#8217;99&#8217;', wptexturize("'Class of '99'"));
125
        $this->assertEquals('&#8216;Class of &#8217;99&#8217; ', wptexturize("'Class of '99' "));
126
        $this->assertEquals('&#8216;Class of &#8217;99&#8217;.', wptexturize("'Class of '99'."));
127
        $this->assertEquals('&#8216;Class of &#8217;99&#8217;, she said', wptexturize("'Class of '99', she said"));
128
        $this->assertEquals('&#8216;Class of &#8217;99&#8217;:', wptexturize("'Class of '99':"));
129
        $this->assertEquals('&#8216;Class of &#8217;99&#8217;;', wptexturize("'Class of '99';"));
130
        $this->assertEquals('&#8216;Class of &#8217;99&#8217;!', wptexturize("'Class of '99'!"));
131
        $this->assertEquals('&#8216;Class of &#8217;99&#8217;?', wptexturize("'Class of '99'?"));
132
        $this->assertEquals('&#8216;Class of &#8217;99&#8217;s&#8217;', wptexturize("'Class of '99's'"));
133
        $this->assertEquals('&#8216;Class of &#8217;99&#8217;s&#8217;', wptexturize("'Class of '99&#8217;s'"));
134
        $this->assertEquals('&#8220;Class of 99&#8221;', wptexturize("\"Class of 99\""));
135
        $this->assertEquals('&#8220;Class of &#8217;99&#8221;', wptexturize("\"Class of '99\""));
136
        $this->assertEquals('{&#8220;Class of &#8217;99&#8221;}', wptexturize("{\"Class of '99\"}"));
137
        $this->assertEquals(' &#8220;Class of &#8217;99&#8221; ', wptexturize(" \"Class of '99\" "));
138
        $this->assertEquals(' &#8220;Class of &#8217;99&#8221;.', wptexturize(" \"Class of '99\"."));
139
        $this->assertEquals(' &#8220;Class of &#8217;99&#8221;, she said', wptexturize(" \"Class of '99\", she said"));
140
        $this->assertEquals(' &#8220;Class of &#8217;99&#8221;:', wptexturize(" \"Class of '99\":"));
141
        $this->assertEquals(' &#8220;Class of &#8217;99&#8221;;', wptexturize(" \"Class of '99\";"));
142
        $this->assertEquals(' &#8220;Class of &#8217;99&#8221;!', wptexturize(" \"Class of '99\"!"));
143
        $this->assertEquals(' &#8220;Class of &#8217;99&#8221;?', wptexturize(" \"Class of '99\"?"));
144
        $this->assertEquals('}&#8221;Class of &#8217;99&#8243;{', wptexturize("}\"Class of '99\"{")); // Not a quotation, may be between two other quotations.
145
    }
146
147
    function test_quotes_after_numbers() 
148
    {
149
        $this->assertEquals('Class of &#8217;99', wptexturize("Class of '99"));
150
    }
151
152
    /**
153
     * @ticket 4539
154
     * @ticket 15241
155
     */
156
    function test_other_html() 
157
    {
158
        $this->assertEquals('&#8216;<strong>', wptexturize("'<strong>"));
159
        //$this->assertEquals('&#8216;<strong>Quoted Text</strong>&#8217;,', wptexturize("'<strong>Quoted Text</strong>',"));
160
        //$this->assertEquals('&#8220;<strong>Quoted Text</strong>&#8221;,', wptexturize('"<strong>Quoted Text</strong>",'));
161
    }
162
163
    function test_x() 
164
    {
165
        $this->assertEquals('14&#215;24', wptexturize("14x24"));
166
    }
167
168 View Code Duplication
    function test_minutes_seconds() 
169
    {
170
        $this->assertEquals('9&#8242;', wptexturize('9\''));
171
        $this->assertEquals('9&#8243;', wptexturize("9\""));
172
173
        $this->assertEquals('a 9&#8242; b', wptexturize('a 9\' b'));
174
        $this->assertEquals('a 9&#8243; b', wptexturize("a 9\" b"));
175
176
        $this->assertEquals('&#8220;a 9&#8242; b&#8221;', wptexturize('"a 9\' b"'));
177
        $this->assertEquals('&#8216;a 9&#8243; b&#8217;', wptexturize("'a 9\" b'"));
178
    }
179
180
    /**
181
     * @ticket 8775
182
     */
183
    function test_wptexturize_quotes_around_numbers() 
184
    {
185
        $this->assertEquals('&#8220;12345&#8221;', wptexturize('"12345"'));
186
        $this->assertEquals('&#8216;12345&#8217;', wptexturize('\'12345\''));
187
        $this->assertEquals('&#8220;a 9&#8242; plus a &#8216;9&#8217;, maybe a 9&#8242; &#8216;9&#8217;&#8221;', wptexturize('"a 9\' plus a \'9\', maybe a 9\' \'9\'"'));
188
        $this->assertEquals('<p>&#8217;99<br />&#8216;123&#8217;<br />&#8217;tis<br />&#8216;s&#8217;</p>', wptexturize('<p>\'99<br />\'123\'<br />\'tis<br />\'s\'</p>'));
189
    }
190
191
    /**
192
     * @ticket 8912
193
     */
194
    function test_wptexturize_html_comments() 
195
    {
196
        $this->assertEquals('<!--[if !IE]>--><!--<![endif]-->', wptexturize('<!--[if !IE]>--><!--<![endif]-->'));
197
        $this->assertEquals('<!--[if !IE]>"a 9\' plus a \'9\', maybe a 9\' \'9\' "<![endif]-->', wptexturize('<!--[if !IE]>"a 9\' plus a \'9\', maybe a 9\' \'9\' "<![endif]-->'));
198
        $this->assertEquals('<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>', wptexturize('<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>'));
199
    }
200
201
    /**
202
     * @ticket 4539
203
     * @ticket 15241
204
     */
205
    function test_entity_quote_cuddling() 
206
    {
207
        $this->assertEquals('&nbsp;&#8220;Testing&#8221;', wptexturize('&nbsp;"Testing"'));
208
        //$this->assertEquals('&#38;&#8220;Testing&#8221;', wptexturize('&#38;"Testing"'));
209
    }
210
211
    /**
212
     * @ticket 22823
213
     */
214
    function test_apostrophes_before_primes() 
215
    {
216
        $this->assertEquals('WordPress 3.5&#8217;s release date', wptexturize("WordPress 3.5's release date"));
217
    }
218
219
    /**
220
     * @ticket 23185
221
     */
222
    function test_spaces_around_hyphens() 
223
    {
224
        $nbsp = "\xC2\xA0";
225
226
        $this->assertEquals(' &#8211; ', wptexturize(' - '));
227
        $this->assertEquals('&nbsp;&#8211;&nbsp;', wptexturize('&nbsp;-&nbsp;'));
228
        $this->assertEquals(' &#8211;&nbsp;', wptexturize(' -&nbsp;'));
229
        $this->assertEquals('&nbsp;&#8211; ', wptexturize('&nbsp;- '));
230
        $this->assertEquals("$nbsp&#8211;$nbsp", wptexturize("$nbsp-$nbsp"));
231
        $this->assertEquals(" &#8211;$nbsp", wptexturize(" -$nbsp"));
232
        $this->assertEquals("$nbsp&#8211; ", wptexturize("$nbsp- "));
233
234
        $this->assertEquals(' &#8212; ', wptexturize(' -- '));
235
        $this->assertEquals('&nbsp;&#8212;&nbsp;', wptexturize('&nbsp;--&nbsp;'));
236
        $this->assertEquals(' &#8212;&nbsp;', wptexturize(' --&nbsp;'));
237
        $this->assertEquals('&nbsp;&#8212; ', wptexturize('&nbsp;-- '));
238
        $this->assertEquals("$nbsp&#8212;$nbsp", wptexturize("$nbsp--$nbsp"));
239
        $this->assertEquals(" &#8212;$nbsp", wptexturize(" --$nbsp"));
240
        $this->assertEquals("$nbsp&#8212; ", wptexturize("$nbsp-- "));
241
    }
242
243
    /**
244
     * @ticket 31030
245
     */
246 View Code Duplication
    function test_hyphens_at_start_and_end() 
247
    {
248
        $this->assertEquals('&#8211; ', wptexturize('- '));
249
        $this->assertEquals('&#8211; &#8211;', wptexturize('- -'));
250
        $this->assertEquals(' &#8211;', wptexturize(' -'));
251
252
        $this->assertEquals('&#8212; ', wptexturize('-- '));
253
        $this->assertEquals('&#8212; &#8212;', wptexturize('-- --'));
254
        $this->assertEquals(' &#8212;', wptexturize(' --'));
255
    }
256
257
    /**
258
     * Test spaces around quotes.
259
     *
260
     * These should never happen, even if the desired output changes some day.
261
     *
262
     * @ticket 22692
263
     */
264
    function test_spaces_around_quotes_never() 
265
    {
266
        $nbsp = "\xC2\xA0";
267
268
        $problem_input  = "$nbsp\"A";
269
        $problem_output = "$nbsp&#8221;A";
270
271
        $this->assertNotEquals($problem_output, wptexturize($problem_input));
272
    }
273
274
    /**
275
     * Test spaces around quotes.
276
     *
277
     * These are desirable outputs for the current design.
278
     *
279
     * @ticket       22692
280
     * @dataProvider data_spaces_around_quotes
281
     */
282
    function test_spaces_around_quotes( $input, $output ) 
283
    {
284
        return $this->assertEquals($output, wptexturize($input));
285
    }
286
287
    function data_spaces_around_quotes() 
288
    {
289
        $nbsp = "\xC2\xA0";
290
        $pi   = "\xCE\xA0";
291
292
        return array(
293
         array(
294
          "stop. $nbsp\"A quote after 2 spaces.\"",
295
          "stop. $nbsp&#8220;A quote after 2 spaces.&#8221;",
296
         ),
297
         array(
298
          "stop.$nbsp$nbsp\"A quote after 2 spaces.\"",
299
          "stop.$nbsp$nbsp&#8220;A quote after 2 spaces.&#8221;",
300
         ),
301
         array(
302
          "stop. $nbsp'A quote after 2 spaces.'",
303
          "stop. $nbsp&#8216;A quote after 2 spaces.&#8217;",
304
         ),
305
         array(
306
          "stop.$nbsp$nbsp'A quote after 2 spaces.'",
307
          "stop.$nbsp$nbsp&#8216;A quote after 2 spaces.&#8217;",
308
         ),
309
         array(
310
          "stop. &nbsp;\"A quote after 2 spaces.\"",
311
          "stop. &nbsp;&#8220;A quote after 2 spaces.&#8221;",
312
         ),
313
         array(
314
          "stop.&nbsp;&nbsp;\"A quote after 2 spaces.\"",
315
          "stop.&nbsp;&nbsp;&#8220;A quote after 2 spaces.&#8221;",
316
         ),
317
         array(
318
          "stop. &nbsp;'A quote after 2 spaces.'",
319
          "stop. &nbsp;&#8216;A quote after 2 spaces.&#8217;",
320
         ),
321
         array(
322
          "stop.&nbsp;&nbsp;'A quote after 2 spaces.'",
323
          "stop.&nbsp;&nbsp;&#8216;A quote after 2 spaces.&#8217;",
324
         ),
325
         array(
326
          "Contraction: $pi's",
327
          "Contraction: $pi&#8217;s",
328
         ),
329
        );
330
    }
331
332
    /**
333
     * Apostrophe before a number always becomes &#8217 (apos);
334
     *
335
     * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
336
     *
337
     * @ticket       22692
338
     * @dataProvider data_apos_before_digits
339
     */
340
    function test_apos_before_digits( $input, $output ) 
341
    {
342
        return $this->assertEquals($output, wptexturize($input));
343
    }
344
345 View Code Duplication
    function data_apos_before_digits() 
346
    {
347
        return array(
348
         array(
349
          "word '99 word",
350
          "word &#8217;99 word",
351
         ),
352
         array(
353
          "word'99 word",
354
          "word&#8217;99 word",
355
         ),
356
         array(
357
          "word '99word",
358
          "word &#8217;99word",
359
         ),
360
         array(
361
          "word'99word",
362
          "word&#8217;99word",
363
         ),
364
         array(
365
          "word '99&#8217;s word", // Appears as a separate but logically superfluous pattern in 3.8.
366
          "word &#8217;99&#8217;s word",
367
         ),
368
         array(
369
          "according to our source, '33 students scored less than 50' on the test.", // Apostrophes and primes have priority over quotes
370
          "according to our source, &#8217;33 students scored less than 50&#8242; on the test.",
371
         ),
372
        );
373
    }
374
375
    /**
376
     * Apostrophe after a space or ([{<" becomes &#8216; (opening_single_quote)
377
     *
378
     * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
379
     *
380
     * @ticket       22692
381
     * @dataProvider data_opening_single_quote
382
     */
383
    function test_opening_single_quote( $input, $output ) 
384
    {
385
        return $this->assertEquals($output, wptexturize($input));
386
    }
387
388
    function data_opening_single_quote() 
389
    {
390
        return array(
391
         array(
392
          "word 'word word",
393
          "word &#8216;word word",
394
         ),
395
         array(
396
          "word ('word word",
397
          "word (&#8216;word word",
398
         ),
399
         array(
400
          "word ['word word",
401
          "word [&#8216;word word",
402
         ),
403
         array(
404
          "word <'word word", // Invalid HTML
405
          "word <'word word",
406
         ),
407
         array(
408
          "word &lt;'word word", // Valid HTML input makes curly quotes.
409
          "word &lt;&#8216;word word",
410
         ),
411
         array(
412
          "word {'word word",
413
          "word {&#8216;word word",
414
         ),
415
         array(
416
          "word \"'word word",
417
          "word &#8220;&#8216;word word", // Two opening quotes
418
         ),
419
         array(
420
          "'word word",
421
          "&#8216;word word",
422
         ),
423
         array(
424
          "word('word word",
425
          "word(&#8216;word word",
426
         ),
427
         array(
428
          "word['word word",
429
          "word[&#8216;word word",
430
         ),
431
         array(
432
          "word<'word word",
433
          "word<'word word",
434
         ),
435
         array(
436
          "word&lt;'word word",
437
          "word&lt;&#8216;word word",
438
         ),
439
         array(
440
          "word{'word word",
441
          "word{&#8216;word word",
442
         ),
443
         array(
444
          "word\"'word word",
445
          "word&#8221;&#8216;word word", // Closing quote, then opening quote
446
         ),
447
         array(
448
          "word ' word word",
449
          "word &#8216; word word",
450
         ),
451
         array(
452
          "word (' word word",
453
          "word (&#8216; word word",
454
         ),
455
         array(
456
          "word [' word word",
457
          "word [&#8216; word word",
458
         ),
459
         array(
460
          "word <' word word",
461
          "word <' word word",
462
         ),
463
         array(
464
          "word &lt;' word word",
465
          "word &lt;&#8216; word word",
466
         ),
467
         array(
468
          "word {' word word",
469
          "word {&#8216; word word",
470
         ),
471
         array(
472
          "word \"' word word",
473
          "word &#8220;&#8216; word word", // Two opening quotes
474
         ),
475
         array(
476
          "' word word",
477
          "&#8216; word word",
478
         ),
479
         array(
480
          "word(' word word",
481
          "word(&#8216; word word",
482
         ),
483
         array(
484
          "word[' word word",
485
          "word[&#8216; word word",
486
         ),
487
         array(
488
          "word<' word word",
489
          "word<' word word",
490
         ),
491
         array(
492
          "word&lt;' word word",
493
          "word&lt;&#8216; word word",
494
         ),
495
         array(
496
          "word{' word word",
497
          "word{&#8216; word word",
498
         ),
499
         array(
500
          "word\"' word word",
501
          "word&#8221;&#8216; word word", // Closing quote, then opening quote
502
         ),
503
        );
504
    }
505
506
    /**
507
     * Double quote after a number becomes &#8243; (double_prime)
508
     *
509
     * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
510
     *
511
     * @ticket       22692
512
     * @dataProvider data_double_prime
513
     */
514
    function test_double_prime( $input, $output ) 
515
    {
516
        return $this->assertEquals($output, wptexturize($input));
517
    }
518
519 View Code Duplication
    function data_double_prime() 
520
    {
521
        return array(
522
         array(
523
          'word 99" word',
524
          'word 99&#8243; word',
525
         ),
526
         array(
527
          'word 99"word',
528
          'word 99&#8243;word',
529
         ),
530
         array(
531
          'word99" word',
532
          'word99&#8243; word',
533
         ),
534
         array(
535
          'word99"word',
536
          'word99&#8243;word',
537
         ),
538
        );
539
    }
540
541
    /**
542
     * Apostrophe after a number becomes &#8242; (prime)
543
     *
544
     * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
545
     *
546
     * @ticket       22692
547
     * @dataProvider data_single_prime
548
     */
549
    function test_single_prime( $input, $output ) 
550
    {
551
        return $this->assertEquals($output, wptexturize($input));
552
    }
553
554 View Code Duplication
    function data_single_prime() 
555
    {
556
        return array(
557
         array(
558
          "word 99' word",
559
          "word 99&#8242; word",
560
         ),
561
         array(
562
          "word 99'word", // Not a prime anymore. Apostrophes get priority.
563
          "word 99&#8217;word",
564
         ),
565
         array(
566
          "word99' word",
567
          "word99&#8242; word",
568
         ),
569
         array(
570
          "word99'word", // Not a prime anymore.
571
          "word99&#8217;word",
572
         ),
573
        );
574
    }
575
576
    /**
577
     * Apostrophe "in a word" becomes &#8217; (apos)
578
     *
579
     * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
580
     *
581
     * @ticket       22692
582
     * @dataProvider data_contractions
583
     */
584
    function test_contractions( $input, $output ) 
585
    {
586
        return $this->assertEquals($output, wptexturize($input));
587
    }
588
589 View Code Duplication
    function data_contractions() 
590
    {
591
        return array(
592
         array(
593
          "word word's word",
594
          "word word&#8217;s word",
595
         ),
596
         array(
597
          "word'[ word", // Apostrophes are never followed by opening punctuation.
598
          "word'[ word",
599
         ),
600
         array(
601
          "word'( word",
602
          "word'( word",
603
         ),
604
         array(
605
          "word'{ word",
606
          "word'{ word",
607
         ),
608
         array(
609
          "word'&lt; word",
610
          "word'&lt; word",
611
         ),
612
         array(
613
          "word'< word", // Invalid HTML input does trigger the apos pattern.
614
          "word&#8217;< word",
615
         ),
616
        );
617
    }
618
619
    /**
620
     * Double quote after a space or ([-{< becomes &#8220; (opening_quote) if not followed by spaces
621
     *
622
     * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
623
     *
624
     * @ticket       22692
625
     * @dataProvider data_opening_quote
626
     */
627
    function test_opening_quote( $input, $output ) 
628
    {
629
        return $this->assertEquals($output, wptexturize($input));
630
    }
631
632 View Code Duplication
    function data_opening_quote() 
633
    {
634
        return array(
635
         array(
636
          'word "word word',
637
          'word &#8220;word word',
638
         ),
639
         array(
640
          'word ("word word',
641
          'word (&#8220;word word',
642
         ),
643
         array(
644
          'word ["word word',
645
          'word [&#8220;word word',
646
         ),
647
         array(
648
          'word <"word word', // Invalid HTML
649
          'word <"word word',
650
         ),
651
         array(
652
          'word &lt;"word word',
653
          'word &lt;&#8220;word word',
654
         ),
655
         array(
656
          'word {"word word',
657
          'word {&#8220;word word',
658
         ),
659
         array(
660
          'word -"word word',
661
          'word -&#8220;word word',
662
         ),
663
         array(
664
          'word-"word word',
665
          'word-&#8220;word word',
666
         ),
667
         array(
668
          '"word word',
669
          '&#8220;word word',
670
         ),
671
         array(
672
          'word("word word',
673
          'word(&#8220;word word',
674
         ),
675
         array(
676
          'word["word word',
677
          'word[&#8220;word word',
678
         ),
679
         array(
680
          'word<"word word',
681
          'word<"word word',
682
         ),
683
         array(
684
          'word&lt;"word word',
685
          'word&lt;&#8220;word word',
686
         ),
687
         array(
688
          'word{"word word',
689
          'word{&#8220;word word',
690
         ),
691
         array(
692
          'word "99 word',
693
          'word &#8220;99 word',
694
         ),
695
        );
696
    }
697
698
    /**
699
     * Double quote becomes &#8221; (closing_quote) unless it is already converted to double_prime or opening_quote.
700
     *
701
     * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
702
     *
703
     * @ticket       22692
704
     * @dataProvider data_closing_quote
705
     */
706
    function test_closing_quote( $input, $output ) 
707
    {
708
        return $this->assertEquals($output, wptexturize($input));
709
    }
710
711 View Code Duplication
    function data_closing_quote() 
712
    {
713
        return array(
714
         array(
715
          'word word" word',
716
          'word word&#8221; word',
717
         ),
718
         array(
719
          'word word") word',
720
          'word word&#8221;) word',
721
         ),
722
         array(
723
          'word word"] word',
724
          'word word&#8221;] word',
725
         ),
726
         array(
727
          'word word"} word',
728
          'word word&#8221;} word',
729
         ),
730
         array(
731
          'word word"> word', // Invalid HTML input?
732
          'word word&#8221;> word',
733
         ),
734
         array(
735
          'word word"&gt; word', // Valid HTML should work
736
          'word word&#8221;&gt; word',
737
         ),
738
         array(
739
          'word word"',
740
          'word word&#8221;',
741
         ),
742
         array(
743
          'word word"word',
744
          'word word&#8221;word',
745
         ),
746
         array(
747
          'word"word"word',
748
          'word&#8221;word&#8221;word',
749
         ),
750
         array(
751
          'test sentence".',
752
          'test sentence&#8221;.',
753
         ),
754
         array(
755
          'test sentence",',
756
          'test sentence&#8221;,',
757
         ),
758
         array(
759
          'test sentence":',
760
          'test sentence&#8221;:',
761
         ),
762
         array(
763
          'test sentence";',
764
          'test sentence&#8221;;',
765
         ),
766
         array(
767
          'test sentence"!',
768
          'test sentence&#8221;!',
769
         ),
770
         array(
771
          'test sentence"?',
772
          'test sentence&#8221;?',
773
         ),
774
         array(
775
          'test sentence."',
776
          'test sentence.&#8221;',
777
         ),
778
         array(
779
          'test sentence". word',
780
          'test sentence&#8221;. word',
781
         ),
782
         array(
783
          'test sentence." word',
784
          'test sentence.&#8221; word',
785
         ),
786
        );
787
    }
788
789
    /**
790
     * Test that single quotes followed by a space or .,-)}]> become &#8217; (closing_single_quote)
791
     *
792
     * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
793
     *
794
     * @ticket       22692
795
     * @dataProvider data_closing_single_quote
796
     */
797
    function test_closing_single_quote( $input, $output ) 
798
    {
799
        return $this->assertEquals($output, wptexturize($input));
800
    }
801
802 View Code Duplication
    function data_closing_single_quote() 
803
    {
804
        return array(
805
         array(
806
          "word word' word",
807
          "word word&#8217; word",
808
         ),
809
         array(
810
          "word word'. word",
811
          "word word&#8217;. word",
812
         ),
813
         array(
814
          "word word'.word",
815
          "word word&#8217;.word",
816
         ),
817
         array(
818
          "word word', she said",
819
          "word word&#8217;, she said",
820
         ),
821
         array(
822
          "word word': word",
823
          "word word&#8217;: word",
824
         ),
825
         array(
826
          "word word'; word",
827
          "word word&#8217;; word",
828
         ),
829
         array(
830
          "word word'! word",
831
          "word word&#8217;! word",
832
         ),
833
         array(
834
          "word word'? word",
835
          "word word&#8217;? word",
836
         ),
837
         array(
838
          "word word'- word",
839
          "word word&#8217;- word",
840
         ),
841
         array(
842
          "word word') word",
843
          "word word&#8217;) word",
844
         ),
845
         array(
846
          "word word'} word",
847
          "word word&#8217;} word",
848
         ),
849
         array(
850
          "word word'] word",
851
          "word word&#8217;] word",
852
         ),
853
         array(
854
          "word word'&gt; word",
855
          "word word&#8217;&gt; word",
856
         ),
857
         array(
858
          "word word'",
859
          "word word&#8217;",
860
         ),
861
         array(
862
          "test sentence'.",
863
          "test sentence&#8217;.",
864
         ),
865
         array(
866
          "test sentence.'",
867
          "test sentence.&#8217;",
868
         ),
869
         array(
870
          "test sentence'. word",
871
          "test sentence&#8217;. word",
872
         ),
873
         array(
874
          "test sentence.' word",
875
          "test sentence.&#8217; word",
876
         ),
877
        );
878
    }
879
880
    /**
881
     * Tests multiplication.
882
     *
883
     * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
884
     *
885
     * @ticket       22692
886
     * @dataProvider data_multiplication
887
     */
888
    function test_multiplication( $input, $output ) 
889
    {
890
        return $this->assertEquals($output, wptexturize($input));
891
    }
892
893
    function data_multiplication() 
894
    {
895
        return array(
896
         array(
897
          "9x9",
898
          "9&#215;9",
899
         ),
900
         array(
901
          "12x34",
902
          "12&#215;34",
903
         ),
904
         array(
905
          "-123x1=-123",
906
          "-123&#215;1=-123",
907
         ),
908
         // @ticket 30445
909
         array(
910
          "-123x-1",
911
          "-123x-1",
912
         ),
913
         array(
914
          "0.675x1=0.675",
915
          "0.675&#215;1=0.675",
916
         ),
917
         array(
918
          "9 x 9",
919
          "9 x 9",
920
         ),
921
         array(
922
          "0x70",
923
          "0x70",
924
         ),
925
         array(
926
          "3x2x1x0",
927
          "3x2x1x0",
928
         ),
929
        );
930
    }
931
932
    /**
933
     * Test ampersands. & always becomes &#038; unless it is followed by # or ;
934
     *
935
     * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
936
     *
937
     * @ticket       22692
938
     * @dataProvider data_ampersand
939
     */
940
    function test_ampersand( $input, $output ) 
941
    {
942
        return $this->assertEquals($output, wptexturize($input));
943
    }
944
945 View Code Duplication
    function data_ampersand() 
946
    {
947
        return array(
948
         array(
949
          "word & word",
950
          "word &#038; word",
951
         ),
952
         array(
953
          "word&word",
954
          "word&#038;word",
955
         ),
956
         array(
957
          "word &nbsp; word",
958
          "word &nbsp; word",
959
         ),
960
         array(
961
          "word &#038; word",
962
          "word &#038; word",
963
         ),
964
         array(
965
          "word &#xabc; word",
966
          "word &#xabc; word",
967
         ),
968
         array(
969
          "word &#X394; word",
970
          "word &#X394; word",
971
         ),
972
         array(
973
          "word &# word",
974
          "word &#038;# word",
975
         ),
976
         array(
977
          "word &44; word",
978
          "word &44; word",
979
         ),
980
         array(
981
          "word &&amp; word",
982
          "word &#038;&amp; word",
983
         ),
984
         array(
985
          "word &!amp; word",
986
          "word &#038;!amp; word",
987
         ),
988
         array(
989
          "word &#",
990
          "word &#038;#",
991
         ),
992
         array(
993
          "word &",
994
          "word &#038;",
995
         ),
996
        );
997
    }
998
999
    /**
1000
     * Test "cockney" phrases, which begin with an apostrophe instead of an opening single quote.
1001
     *
1002
     * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
1003
     *
1004
     * @ticket       22692
1005
     * @dataProvider data_cockney
1006
     */
1007
    function test_cockney( $input, $output ) 
1008
    {
1009
        return $this->assertEquals($output, wptexturize($input));
1010
    }
1011
1012 View Code Duplication
    function data_cockney() 
1013
    {
1014
        return array(
1015
         array(
1016
          "word 'tain't word",
1017
          "word &#8217;tain&#8217;t word",
1018
         ),
1019
         array(
1020
          "word 'twere word",
1021
          "word &#8217;twere word",
1022
         ),
1023
         array(
1024
          "word 'twas word",
1025
          "word &#8217;twas word",
1026
         ),
1027
         array(
1028
          "word 'tis word",
1029
          "word &#8217;tis word",
1030
         ),
1031
         array(
1032
          "word 'twill word",
1033
          "word &#8217;twill word",
1034
         ),
1035
         array(
1036
          "word 'til word",
1037
          "word &#8217;til word",
1038
         ),
1039
         array(
1040
          "word 'bout word",
1041
          "word &#8217;bout word",
1042
         ),
1043
         array(
1044
          "word 'nuff word",
1045
          "word &#8217;nuff word",
1046
         ),
1047
         array(
1048
          "word 'round word",
1049
          "word &#8217;round word",
1050
         ),
1051
         array(
1052
          "word 'cause word",
1053
          "word &#8217;cause word",
1054
         ),
1055
         array(
1056
          "word 'em word",
1057
          "word &#8217;em word",
1058
         ),
1059
        );
1060
    }
1061
1062
    /**
1063
     * Test smart dashes.
1064
     *
1065
     * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
1066
     *
1067
     * @ticket       22692
1068
     * @dataProvider data_smart_dashes
1069
     */
1070
    function test_smart_dashes( $input, $output ) 
1071
    {
1072
        return $this->assertEquals($output, wptexturize($input));
1073
    }
1074
1075
    function data_smart_dashes() 
1076
    {
1077
        return array(
1078
         array(
1079
          "word --- word",
1080
          "word &#8212; word",
1081
         ),
1082
         array(
1083
          "word---word",
1084
          "word&#8212;word",
1085
         ),
1086
         array(
1087
          "word -- word",
1088
          "word &#8212; word",
1089
         ),
1090
         array(
1091
          "word--word",
1092
          "word&#8211;word",
1093
         ),
1094
         array(
1095
          "word - word",
1096
          "word &#8211; word",
1097
         ),
1098
         array(
1099
          "word-word",
1100
          "word-word",
1101
         ),
1102
         array(
1103
          "word xn&#8211; word",
1104
          "word xn&#8211; word",
1105
         ),
1106
         array(
1107
          "wordxn&#8211;word",
1108
          "wordxn&#8211;word",
1109
         ),
1110
         array(
1111
          "wordxn--word",
1112
          "wordxn--word",
1113
         ),
1114
        );
1115
    }
1116
1117
    /**
1118
     * Test miscellaneous static replacements.
1119
     *
1120
     * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
1121
     *
1122
     * @ticket       22692
1123
     * @dataProvider data_misc_static_replacements
1124
     */
1125
    function test_misc_static_replacements( $input, $output ) 
1126
    {
1127
        return $this->assertEquals($output, wptexturize($input));
1128
    }
1129
1130
    function data_misc_static_replacements() 
1131
    {
1132
        return array(
1133
         array(
1134
          "word ... word",
1135
          "word &#8230; word",
1136
         ),
1137
         array(
1138
          "word...word",
1139
          "word&#8230;word",
1140
         ),
1141
         array(
1142
          "word `` word",
1143
          "word &#8220; word",
1144
         ),
1145
         array(
1146
          "word``word",
1147
          "word&#8220;word",
1148
         ),
1149
         array(
1150
          "word '' word",
1151
          "word &#8221; word",
1152
         ),
1153
         array(
1154
          "word''word",
1155
          "word&#8221;word",
1156
         ),
1157
         array(
1158
          "word (tm) word",
1159
          "word &#8482; word",
1160
         ),
1161
         array(
1162
          "word (tm)word",
1163
          "word &#8482;word",
1164
         ),
1165
         array(
1166
          "word(tm) word",
1167
          "word(tm) word",
1168
         ),
1169
         array(
1170
          "word(tm)word",
1171
          "word(tm)word",
1172
         ),
1173
        );
1174
    }
1175
1176
    /**
1177
     * Numbers inside of matching quotes get curly quotes instead of apostrophes and primes.
1178
     *
1179
     * @ticket       8775
1180
     * @dataProvider data_quoted_numbers
1181
     */
1182
    function test_quoted_numbers( $input, $output ) 
1183
    {
1184
        return $this->assertEquals($output, wptexturize($input));
1185
    }
1186
1187 View Code Duplication
    function data_quoted_numbers() 
1188
    {
1189
        return array(
1190
         array(
1191
          'word "42.00" word',
1192
          'word &#8220;42.00&#8221; word',
1193
         ),
1194
         array(
1195
          'word "42.00"word',
1196
          'word &#8220;42.00&#8221;word',
1197
         ),
1198
         array(
1199
          "word '42.00' word",
1200
          "word &#8216;42.00&#8217; word",
1201
         ),
1202
         array(
1203
          "word '42.00'word",
1204
          "word &#8216;42.00&#8217;word",
1205
         ),
1206
         array(
1207
          'word "42" word',
1208
          'word &#8220;42&#8221; word',
1209
         ),
1210
         array(
1211
          'word "42,00" word',
1212
          'word &#8220;42,00&#8221; word',
1213
         ),
1214
         array(
1215
          'word "4,242.00" word',
1216
          'word &#8220;4,242.00&#8221; word',
1217
         ),
1218
         array(
1219
          "word '99's word",
1220
          "word &#8217;99&#8217;s word",
1221
         ),
1222
         array(
1223
          "word '99'samsonite",
1224
          "word &#8217;99&#8217;samsonite",
1225
         ),
1226
        );
1227
    }
1228
1229
    /**
1230
     * Quotations should be allowed to have dashes around them.
1231
     *
1232
     * @ticket       20342
1233
     * @dataProvider data_quotes_and_dashes
1234
     */
1235
    function test_quotes_and_dashes( $input, $output ) 
1236
    {
1237
        return $this->assertEquals($output, wptexturize($input));
1238
    }
1239
1240 View Code Duplication
    function data_quotes_and_dashes() 
1241
    {
1242
        return array(
1243
         array(
1244
          'word---"quote"',
1245
          'word&#8212;&#8220;quote&#8221;',
1246
         ),
1247
         array(
1248
          'word--"quote"',
1249
          'word&#8211;&#8220;quote&#8221;',
1250
         ),
1251
         array(
1252
          'word-"quote"',
1253
          'word-&#8220;quote&#8221;',
1254
         ),
1255
         array(
1256
          "word---'quote'",
1257
          "word&#8212;&#8216;quote&#8217;",
1258
         ),
1259
         array(
1260
          "word--'quote'",
1261
          "word&#8211;&#8216;quote&#8217;",
1262
         ),
1263
         array(
1264
          "word-'quote'",
1265
          "word-&#8216;quote&#8217;",
1266
         ),
1267
         array(
1268
          '"quote"---word',
1269
          '&#8220;quote&#8221;&#8212;word',
1270
         ),
1271
         array(
1272
          '"quote"--word',
1273
          '&#8220;quote&#8221;&#8211;word',
1274
         ),
1275
         array(
1276
          '"quote"-word',
1277
          '&#8220;quote&#8221;-word',
1278
         ),
1279
         array(
1280
          "'quote'---word",
1281
          "&#8216;quote&#8217;&#8212;word",
1282
         ),
1283
         array(
1284
          "'quote'--word",
1285
          "&#8216;quote&#8217;&#8211;word",
1286
         ),
1287
         array(
1288
          "'quote'-word",
1289
          "&#8216;quote&#8217;-word",
1290
         ),
1291
        );
1292
    }
1293
1294
    /**
1295
     * Test HTML and shortcode avoidance.
1296
     *
1297
     * @ticket       12690
1298
     * @dataProvider data_tag_avoidance
1299
     */
1300
    function test_tag_avoidance( $input, $output ) 
1301
    {
1302
        return $this->assertEquals($output, wptexturize($input));
1303
    }
1304
1305
    function data_tag_avoidance() 
1306
    {
1307
        return array(
1308
         array(
1309
          '[ ... ]',
1310
          '[ &#8230; ]',
1311
         ),
1312
         array(
1313
          '[ is it wise to <a title="allow user content ] here? hmm"> maybe </a> ]',
1314
          '[ is it wise to <a title="allow user content ] here? hmm"> maybe </a> ]',
1315
         ),
1316
         array(
1317
          '[is it wise to <a title="allow user content ] here? hmm"> maybe </a> ]',
1318
          '[is it wise to <a title="allow user content ] here? hmm"> maybe </a> ]',
1319
         ),
1320
         array(
1321
          '[caption - is it wise to <a title="allow user content ] here? hmm"> maybe </a> ]',
1322
          '[caption &#8211; is it wise to <a title="allow user content ] here? hmm"> maybe </a> ]',
1323
         ),
1324
         array(
1325
          '[ photos by <a href="http://example.com/?a[]=1&a[]=2"> this guy & that guy </a> ]',
1326
          '[ photos by <a href="http://example.com/?a[]=1&#038;a[]=2"> this guy &#038; that guy </a> ]',
1327
         ),
1328
         array(
1329
          '[photos by <a href="http://example.com/?a[]=1&a[]=2"> this guy & that guy </a>]',
1330
          '[photos by <a href="http://example.com/?a[]=1&#038;a[]=2"> this guy &#038; that guy </a>]',
1331
         ),
1332
         array(
1333
          '& <script>&&</script>',
1334
          '&#038; <script>&&</script>'
1335
         ),
1336
         array(
1337
          '[gallery ...]',
1338
          '[gallery ...]',
1339
         ),
1340
         array(
1341
          '[[gallery ...]', // This tag is still valid.
1342
          '[[gallery ...]',
1343
         ),
1344
         array(
1345
          '[gallery ...]]', // This tag is also valid.
1346
          '[gallery ...]]',
1347
         ),
1348
         array(
1349
          '[/gallery ...]', // This would actually be ignored by the shortcode system.  The decision to not texturize it is intentional, if not correct.
1350
          '[/gallery ...]',
1351
         ),
1352
         array(
1353
          '[[gallery]]...[[/gallery]]', // Shortcode parsing will ignore the inner ]...[ part and treat this as a single escaped shortcode.
1354
          '[[gallery]]&#8230;[[/gallery]]',
1355
         ),
1356
         array(
1357
          '[[[gallery]]]...[[[/gallery]]]', // Again, shortcode parsing matches, but only the [[gallery] and [/gallery]] parts.
1358
          '[[[gallery]]]&#8230;[[[/gallery]]]',
1359
         ),
1360
         array(
1361
          '[gallery ...',
1362
          '[gallery &#8230;',
1363
         ),
1364
         array(
1365
          '[gallery <br ... /> ...]', // This tag is still valid. Shortcode 'attributes' are not considered in the initial parsing of shortcodes, and HTML is allowed.
1366
          '[gallery <br ... /> ...]',
1367
         ),
1368
         array(
1369
          '<br [gallery ...] ... />',
1370
          '<br [gallery ...] ... />',
1371
         ),
1372
         array(
1373
          '<br [gallery ...] ... /',
1374
          '<br [gallery ...] ... /',
1375
         ),
1376
         array(
1377
          '<br ... />',
1378
          '<br ... />',
1379
         ),
1380
         array(
1381
          '<br ... />...<br ... />',
1382
          '<br ... />&#8230;<br ... />',
1383
         ),
1384
         array(
1385
          '[gallery ...]...[gallery ...]',
1386
          '[gallery ...]&#8230;[gallery ...]',
1387
         ),
1388
         array(
1389
          '[[gallery ...]]',
1390
          '[[gallery ...]]',
1391
         ),
1392
         array(
1393
          '[[gallery ...]',
1394
          '[[gallery ...]',
1395
         ),
1396
         array(
1397
          '[gallery ...]]',
1398
          '[gallery ...]]',
1399
         ),
1400
         array(
1401
          '[/gallery ...]]',
1402
          '[/gallery ...]]',
1403
         ),
1404
         array(
1405
          '[[gallery <br ... /> ...]]', // This gets parsed as an escaped shortcode with embedded HTML.  Brains may explode.
1406
          '[[gallery <br ... /> ...]]',
1407
         ),
1408
         array(
1409
          '<br [[gallery ...]] ... />',
1410
          '<br [[gallery ...]] ... />',
1411
         ),
1412
         array(
1413
          '<br [[gallery ...]] ... /',
1414
          '<br [[gallery ...]] ... /',
1415
         ),
1416
         array(
1417
          '[[gallery ...]]...[[gallery ...]]',
1418
          '[[gallery ...]]&#8230;[[gallery ...]]',
1419
         ),
1420
         array(
1421
          '[[gallery ...]...[/gallery]]',
1422
          '[[gallery ...]&#8230;[/gallery]]',
1423
         ),
1424
         array(
1425
          '<!-- ... -->',
1426
          '<!-- ... -->',
1427
         ),
1428
         array(
1429
          '<!--...-->',
1430
          '<!--...-->',
1431
         ),
1432
         array(
1433
          '<!-- ... -- > ...',
1434
          '<!-- ... -- > ...',
1435
         ),
1436
         array(
1437
          '<!-- ...', // An unclosed comment is still a comment.
1438
          '<!-- ...',
1439
         ),
1440
         array(
1441
          'a<!-->b', // Browsers seem to allow this.
1442
          'a<!-->b',
1443
         ),
1444
         array(
1445
          'a<!--->b',
1446
          'a<!--->b',
1447
         ),
1448
         array(
1449
          'a<!---->b',
1450
          'a<!---->b',
1451
         ),
1452
         array(
1453
          'a<!----->b',
1454
          'a<!----->b',
1455
         ),
1456
         array(
1457
          'a<!-- c --->b',
1458
          'a<!-- c --->b',
1459
         ),
1460
         array(
1461
          'a<!-- c -- d -->b',
1462
          'a<!-- c -- d -->b',
1463
         ),
1464
         array(
1465
          'a<!-- <!-- c --> -->b<!-- close -->',
1466
          'a<!-- <!-- c --> &#8211;>b<!-- close -->',
1467
         ),
1468
         array(
1469
          '<!-- <br /> [gallery] ... -->',
1470
          '<!-- <br /> [gallery] ... -->',
1471
         ),
1472
         array(
1473
          '...<!-- ... -->...',
1474
          '&#8230;<!-- ... -->&#8230;',
1475
         ),
1476
         array(
1477
          '[gallery ...]...<!-- ... -->...<br ... />',
1478
          '[gallery ...]&#8230;<!-- ... -->&#8230;<br ... />',
1479
         ),
1480
         array(
1481
          '<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>',
1482
          '<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>',
1483
         ),
1484
         array(
1485
          'word <img src="http://example.com/wp-content/uploads/2014/06/image-300x216.gif" /> word', // Ensure we are not corrupting image URLs.
1486
          'word <img src="http://example.com/wp-content/uploads/2014/06/image-300x216.gif" /> word',
1487
         ),
1488
         array(
1489
          '[ do texturize "[quote]" here ]',
1490
          '[ do texturize &#8220;[quote]&#8221; here ]',
1491
         ),
1492
         array(
1493
          '[ regex catches this <a href="[quote]">here</a> ]',
1494
          '[ regex catches this <a href="[quote]">here</a> ]',
1495
         ),
1496
         array(
1497
          '[ but also catches the <b>styled "[quote]" here</b> ]',
1498
          '[ but also catches the <b>styled &#8220;[quote]&#8221; here</b> ]',
1499
         ),
1500
         array(
1501
          '[Let\'s get crazy<input>[caption code="<a href=\'?a[]=100\'>hello</a>"]</input>world]', // caption shortcode is invalid here because it contains [] chars.
1502
          '[Let&#8217;s get crazy<input>[caption code=&#8221;<a href=\'?a[]=100\'>hello</a>&#8220;]</input>world]',
1503
         ),
1504
         array(
1505
          '<> ... <>',
1506
          '<> &#8230; <>',
1507
         ),
1508
         array(
1509
          '<> ... <> ... >',
1510
          '<> &#8230; <> &#8230; >',
1511
         ),
1512
         array(
1513
          '<> ... < ... > ... <>',
1514
          '<> &#8230; < ... > &#8230; <>',
1515
         ),
1516
        );
1517
    }
1518
1519
    /**
1520
     * Year abbreviations consist of exactly two digits.
1521
     *
1522
     * @ticket       26850
1523
     * @dataProvider data_year_abbr
1524
     */
1525
    function test_year_abbr( $input, $output ) 
1526
    {
1527
        return $this->assertEquals($output, wptexturize($input));
1528
    }
1529
1530 View Code Duplication
    function data_year_abbr() 
1531
    {
1532
        return array(
1533
         array(
1534
          "word '99 word",
1535
          "word &#8217;99 word",
1536
         ),
1537
         array(
1538
          "word '99. word",
1539
          "word &#8217;99. word",
1540
         ),
1541
         array(
1542
          "word '99, word",
1543
          "word &#8217;99, word",
1544
         ),
1545
         array(
1546
          "word '99; word",
1547
          "word &#8217;99; word",
1548
         ),
1549
         array(
1550
          "word '99' word", // For this pattern, prime doesn't make sense.  Should get apos and a closing quote.
1551
          "word &#8217;99&#8217; word",
1552
         ),
1553
         array(
1554
          "word '99'. word",
1555
          "word &#8217;99&#8217;. word",
1556
         ),
1557
         array(
1558
          "word '99', word",
1559
          "word &#8217;99&#8217;, word",
1560
         ),
1561
         array(
1562
          "word '99.' word",
1563
          "word &#8217;99.&#8217; word",
1564
         ),
1565
         array(
1566
          "word '99",
1567
          "word &#8217;99",
1568
         ),
1569
         array(
1570
          "'99 word",
1571
          "&#8217;99 word",
1572
         ),
1573
         array(
1574
          "word '999 word", // Does not match the apos pattern, should be opening quote.
1575
          "word &#8216;999 word",
1576
         ),
1577
         array(
1578
          "word '99% word",
1579
          "word &#8216;99% word",
1580
         ),
1581
         array(
1582
          "word '9 word",
1583
          "word &#8216;9 word",
1584
         ),
1585
         array(
1586
          "word '99.9 word",
1587
          "word &#8216;99.9 word",
1588
         ),
1589
         array(
1590
          "word '999",
1591
          "word &#8216;999",
1592
         ),
1593
         array(
1594
          "word '9",
1595
          "word &#8216;9",
1596
         ),
1597
         array(
1598
          "in '4 years, 3 months,' Obama cut the deficit",
1599
          "in &#8216;4 years, 3 months,&#8217; Obama cut the deficit",
1600
         ),
1601
         array(
1602
          "testing's '4' through 'quotes'",
1603
          "testing&#8217;s &#8216;4&#8217; through &#8216;quotes&#8217;",
1604
         ),
1605
        );
1606
    }
1607
1608
    /**
1609
     * Make sure translation actually works.
1610
     *
1611
     * Also make sure apostrophes and closing quotes aren't being confused by default.
1612
     *
1613
     * @ticket       27426
1614
     * @dataProvider data_translate
1615
     */
1616 View Code Duplication
    function test_translate( $input, $output ) 
1617
    {
1618
        add_filter('gettext_with_context', array( $this, 'filter_translate' ), 10, 4);
1619
1620
        $result = wptexturize($input, true);
1621
1622
        remove_filter('gettext_with_context', array( $this, 'filter_translate' ), 10, 4);
1623
        wptexturize('reset', true);
1624
1625
        return $this->assertEquals($output, $result);
1626
    }
1627
1628 View Code Duplication
    function filter_translate( $translations, $text, $context, $domain ) 
1629
    {
1630
        switch ($text) {
0 ignored issues
show
introduced by
No space before closing parenthesis is prohibited
Loading history...
1631
        case '&#8211;' : 
1632
            return '!endash!';
1633
        case '&#8212;' : 
1634
            return '!emdash!';
1635
        case '&#8216;' : 
1636
            return '!openq1!';
1637
        case '&#8217;' :
1638
            if ('apostrophe' == $context ) {
1639
                return '!apos!';
1640
            } else {
1641
                return '!closeq1!';
1642
            }
1643
        case '&#8220;' : 
1644
            return '!openq2!';
1645
        case '&#8221;' : 
1646
            return '!closeq2!';
1647
        case '&#8242;' : 
1648
            return '!prime1!';
1649
        case '&#8243;' : 
1650
            return '!prime2!';
1651
        case '&#8217;tain&#8217;t,&#8217;twere,&#8217;twas,&#8217;tis,&#8217;twill,&#8217;til,&#8217;bout,&#8217;nuff,&#8217;round,&#8217;cause,&#8217;em' : 
1652
            return '!apos!tain!apos!t,!apos!twere,!apos!twas,!apos!tis,!apos!twill,!apos!til,!apos!bout,!apos!nuff,!apos!round,!apos!cause,!apos!em';
1653
        default : 
1654
            return $translations;
1655
        }
1656
    }
1657
1658
    function data_translate() 
1659
    {
1660
        return array(
1661
         array(
1662
          "word '99 word",
1663
          "word !apos!99 word",
1664
         ),
1665
         array(
1666
          "word'99 word",
1667
          "word!apos!99 word",
1668
         ),
1669
         array(
1670
          "word 'test sentence' word",
1671
          "word !openq1!test sentence!closeq1! word",
1672
         ),
1673
         array(
1674
          "'test sentence'",
1675
          "!openq1!test sentence!closeq1!",
1676
         ),
1677
         array(
1678
          'word "test sentence" word',
1679
          'word !openq2!test sentence!closeq2! word',
1680
         ),
1681
         array(
1682
          '"test sentence"',
1683
          '!openq2!test sentence!closeq2!',
1684
         ),
1685
         array(
1686
          "word 'word word",
1687
          "word !openq1!word word",
1688
         ),
1689
         array(
1690
          "word ('word word",
1691
          "word (!openq1!word word",
1692
         ),
1693
         array(
1694
          "word ['word word",
1695
          "word [!openq1!word word",
1696
         ),
1697
         array(
1698
          'word 99" word',
1699
          'word 99!prime2! word',
1700
         ),
1701
         array(
1702
          'word 99"word',
1703
          'word 99!prime2!word',
1704
         ),
1705
         array(
1706
          'word99" word',
1707
          'word99!prime2! word',
1708
         ),
1709
         array(
1710
          'word99"word',
1711
          'word99!prime2!word',
1712
         ),
1713
         array(
1714
          "word 99' word",
1715
          "word 99!prime1! word",
1716
         ),
1717
         array(
1718
          "word99' word",
1719
          "word99!prime1! word",
1720
         ),
1721
         array(
1722
          "word word's word",
1723
          "word word!apos!s word",
1724
         ),
1725
         array(
1726
          "word word'. word",
1727
          "word word!closeq1!. word",
1728
         ),
1729
         array(
1730
          "word ]'. word",
1731
          "word ]!closeq1!. word",
1732
         ),
1733
         array(
1734
          'word "word word',
1735
          'word !openq2!word word',
1736
         ),
1737
         array(
1738
          'word ("word word',
1739
          'word (!openq2!word word',
1740
         ),
1741
         array(
1742
          'word ["word word',
1743
          'word [!openq2!word word',
1744
         ),
1745
         array(
1746
          'word word" word',
1747
          'word word!closeq2! word',
1748
         ),
1749
         array(
1750
          'word word") word',
1751
          'word word!closeq2!) word',
1752
         ),
1753
         array(
1754
          'word word"] word',
1755
          'word word!closeq2!] word',
1756
         ),
1757
         array(
1758
          'word word"',
1759
          'word word!closeq2!',
1760
         ),
1761
         array(
1762
          'word word"word',
1763
          'word word!closeq2!word',
1764
         ),
1765
         array(
1766
          'test sentence".',
1767
          'test sentence!closeq2!.',
1768
         ),
1769
         array(
1770
          'test sentence."',
1771
          'test sentence.!closeq2!',
1772
         ),
1773
         array(
1774
          'test sentence." word',
1775
          'test sentence.!closeq2! word',
1776
         ),
1777
         array(
1778
          "word word' word",
1779
          "word word!closeq1! word",
1780
         ),
1781
         array(
1782
          "word word'. word",
1783
          "word word!closeq1!. word",
1784
         ),
1785
         array(
1786
          "word word'.word",
1787
          "word word!closeq1!.word",
1788
         ),
1789
         array(
1790
          "word word'",
1791
          "word word!closeq1!",
1792
         ),
1793
         array(
1794
          "test sentence'.",
1795
          "test sentence!closeq1!.",
1796
         ),
1797
         array(
1798
          "test sentence.'",
1799
          "test sentence.!closeq1!",
1800
         ),
1801
         array(
1802
          "test sentence'. word",
1803
          "test sentence!closeq1!. word",
1804
         ),
1805
         array(
1806
          "test sentence.' word",
1807
          "test sentence.!closeq1! word",
1808
         ),
1809
         array(
1810
          "word 'tain't word",
1811
          "word !apos!tain!apos!t word",
1812
         ),
1813
         array(
1814
          "word 'twere word",
1815
          "word !apos!twere word",
1816
         ),
1817
         array(
1818
          'word "42.00" word',
1819
          'word !openq2!42.00!closeq2! word',
1820
         ),
1821
         array(
1822
          "word '42.00' word",
1823
          "word !openq1!42.00!closeq1! word",
1824
         ),
1825
         array(
1826
          "word word'. word",
1827
          "word word!closeq1!. word",
1828
         ),
1829
         array(
1830
          "word word'.word",
1831
          "word word!closeq1!.word",
1832
         ),
1833
         array(
1834
          "word word', she said",
1835
          "word word!closeq1!, she said",
1836
         ),
1837
        );
1838
    }
1839
1840
    /**
1841
     * Extra sanity checks for _wptexturize_pushpop_element()
1842
     *
1843
     * @ticket       28483
1844
     * @dataProvider data_element_stack
1845
     */
1846
    function test_element_stack( $input, $output ) 
1847
    {
1848
        return $this->assertEquals($output, wptexturize($input));
1849
    }
1850
1851 View Code Duplication
    function data_element_stack() 
1852
    {
1853
        return array(
1854
         array(
1855
          '<span>hello</code>---</span>',
1856
          '<span>hello</code>&#8212;</span>',
1857
         ),
1858
         array(
1859
          '</code>hello<span>---</span>',
1860
          '</code>hello<span>&#8212;</span>',
1861
         ),
1862
         array(
1863
          '<code>hello</code>---</span>',
1864
          '<code>hello</code>&#8212;</span>',
1865
         ),
1866
         array(
1867
          '<span>hello</span>---<code>',
1868
          '<span>hello</span>&#8212;<code>',
1869
         ),
1870
         array(
1871
          '<span>hello<code>---</span>',
1872
          '<span>hello<code>---</span>',
1873
         ),
1874
         array(
1875
          '<code>hello<span>---</span>',
1876
          '<code>hello<span>---</span>',
1877
         ),
1878
         array(
1879
          '<code>hello</span>---</span>',
1880
          '<code>hello</span>---</span>',
1881
         ),
1882
         array(
1883
          '<span><code>hello</code>---</span>',
1884
          '<span><code>hello</code>&#8212;</span>',
1885
         ),
1886
         array(
1887
          '<code>hello</code>world<span>---</span>',
1888
          '<code>hello</code>world<span>&#8212;</span>',
1889
         ),
1890
        );
1891
    }
1892
1893
    /**
1894
     * Test disabling shortcode texturization.
1895
     *
1896
     * @ticket       29557
1897
     * @dataProvider data_unregistered_shortcodes
1898
     */
1899
    function test_unregistered_shortcodes( $input, $output ) 
1900
    {
1901
        add_filter('no_texturize_shortcodes', array( $this, 'filter_shortcodes' ), 10, 1);
1902
    
1903
        $output = $this->assertEquals($output, wptexturize($input));
1904
    
1905
        remove_filter('no_texturize_shortcodes', array( $this, 'filter_shortcodes' ), 10, 1);
1906
        return $output;
1907
    }
1908
    
1909
    function filter_shortcodes( $disabled ) 
1910
    {
1911
        $disabled[] = 'audio';
1912
        return $disabled;
1913
    }
1914
1915 View Code Duplication
    function data_unregistered_shortcodes() 
1916
    {
1917
        return array(
1918
         array(
1919
          '[a]a--b[audio]---[/audio]a--b[/a]',
1920
          '[a]a&#8211;b[audio]---[/audio]a&#8211;b[/a]',
1921
         ),
1922
         array(
1923
          '[code ...]...[/code]', // code is not a registered shortcode.
1924
          '[code &#8230;]&#8230;[/code]',
1925
         ),
1926
         array(
1927
          '[hello ...]...[/hello]', // hello is not a registered shortcode.
1928
          '[hello &#8230;]&#8230;[/hello]',
1929
         ),
1930
         array(
1931
          '[...]...[/...]', // These are potentially usable shortcodes.
1932
          '[&#8230;]&#8230;[/&#8230;]',
1933
         ),
1934
         array(
1935
          '[gal>ery ...]',
1936
          '[gal>ery &#8230;]',
1937
         ),
1938
         array(
1939
          '[randomthing param="test"]',
1940
          '[randomthing param=&#8221;test&#8221;]',
1941
         ),
1942
         array(
1943
          '[[audio]...[/audio]...', // These are potentially usable shortcodes.  Unfortunately, the meaning of [[audio] is ambiguous unless we run the entire shortcode regexp.
1944
          '[[audio]&#8230;[/audio]&#8230;',
1945
         ),
1946
         array(
1947
          '[audio]...[/audio]]...', // These are potentially usable shortcodes.  Unfortunately, the meaning of [/audio]] is ambiguous unless we run the entire shortcode regexp.
1948
          '[audio]...[/audio]]...', // This test would not pass in 3.9 because the extra brace was always ignored by texturize.
1949
         ),
1950
         array(
1951
          '<span>hello[/audio]---</span>',
1952
          '<span>hello[/audio]&#8212;</span>',
1953
         ),
1954
         array(
1955
          '[/audio]hello<span>---</span>',
1956
          '[/audio]hello<span>&#8212;</span>',
1957
         ),
1958
         array(
1959
          '[audio]hello[/audio]---</span>',
1960
          '[audio]hello[/audio]&#8212;</span>',
1961
         ),
1962
         array(
1963
          '<span>hello</span>---[audio]',
1964
          '<span>hello</span>&#8212;[audio]',
1965
         ),
1966
         array(
1967
          '<span>hello[audio]---</span>',
1968
          '<span>hello[audio]---</span>',
1969
         ),
1970
         array(
1971
          '[audio]hello<span>---</span>',
1972
          '[audio]hello<span>---</span>',
1973
         ),
1974
         array(
1975
          '[audio]hello</span>---</span>',
1976
          '[audio]hello</span>---</span>',
1977
         ),
1978
        );
1979
    }
1980
1981
    /**
1982
     * Ensure primes logic is not too greedy at the end of a quotation.
1983
     *
1984
     * @ticket       29256
1985
     * @dataProvider data_primes_vs_quotes
1986
     */
1987
    function test_primes_vs_quotes( $input, $output ) 
1988
    {
1989
        return $this->assertEquals($output, wptexturize($input));
1990
    }
1991
1992
    function data_primes_vs_quotes() 
1993
    {
1994
        return array(
1995
         array(
1996
          "George's porch is 99' long.",
1997
          "George&#8217;s porch is 99&#8242; long.",
1998
         ),
1999
         array(
2000
          'The best year "was that time in 2012" when everyone partied, he said.',
2001
          'The best year &#8220;was that time in 2012&#8221; when everyone partied, he said.',
2002
         ),
2003
         array(
2004
          "I need 4 x 20' = 80' of trim.", // Works only with a space before the = char.
2005
          "I need 4 x 20&#8242; = 80&#8242; of trim.",
2006
         ),
2007
         array(
2008
          '"Lorem ipsum dolor sit amet 1234"',
2009
          '&#8220;Lorem ipsum dolor sit amet 1234&#8221;',
2010
         ),
2011
         array(
2012
          "'Etiam eu egestas dui 1234'",
2013
          "&#8216;Etiam eu egestas dui 1234&#8217;",
2014
         ),
2015
         array(
2016
          'according to our source, "33% of all students scored less than 50" on the test.',
2017
          'according to our source, &#8220;33% of all students scored less than 50&#8221; on the test.',
2018
         ),
2019
         array(
2020
          "The doctor said, 'An average height is between 5' and 6' in study group 7'.  He then produced a 6' chart of averages.  A man of 7', incredibly, is very possible.",
2021
          "The doctor said, &#8216;An average height is between 5&#8242; and 6&#8242; in study group 7&#8217;.  He then produced a 6&#8242; chart of averages.  A man of 7&#8242;, incredibly, is very possible.",
2022
         ),
2023
         array(
2024
          'Pirates have voted on "The Expendables 3" with their clicks -- and it turns out the Sylvester Stallone-starrer hasn\'t been astoundingly popular among digital thieves, relatively speaking.
2025
2026
As of Sunday, 5.12 million people worldwide had pirated "Expendables 3" since a high-quality copy hit torrent-sharing sites July 23, according to piracy-tracking firm Excipio.
2027
2028
That likely contributed to the action movie\'s dismal box-office debut this weekend. But over the same July 23-Aug. 18 time period, the movie was No. 4 in downloads, after "Captain America: The Winter Soldier" (7.31 million), "Divergent" (6.29 million) and "The Amazing Spider-Man 2" (5.88 million). Moreover, that\'s despite "Expendables 3" becoming available more than three weeks prior to the film\'s U.S. theatrical debut.
2029
2030
String with a number followed by a single quote \'Expendables 3\' vestibulum in arcu mi.',
2031
2032
          'Pirates have voted on &#8220;The Expendables 3&#8221; with their clicks &#8212; and it turns out the Sylvester Stallone-starrer hasn&#8217;t been astoundingly popular among digital thieves, relatively speaking.
2033
2034
As of Sunday, 5.12 million people worldwide had pirated &#8220;Expendables 3&#8221; since a high-quality copy hit torrent-sharing sites July 23, according to piracy-tracking firm Excipio.
2035
2036
That likely contributed to the action movie&#8217;s dismal box-office debut this weekend. But over the same July 23-Aug. 18 time period, the movie was No. 4 in downloads, after &#8220;Captain America: The Winter Soldier&#8221; (7.31 million), &#8220;Divergent&#8221; (6.29 million) and &#8220;The Amazing Spider-Man 2&#8221; (5.88 million). Moreover, that&#8217;s despite &#8220;Expendables 3&#8221; becoming available more than three weeks prior to the film&#8217;s U.S. theatrical debut.
2037
2038
String with a number followed by a single quote &#8216;Expendables 3&#8217; vestibulum in arcu mi.',
2039
         ),
2040
        );
2041
    }
2042
2043
    /**
2044
     * Make sure translation actually works.
2045
     *
2046
     * Also make sure opening and closing quotes are allowed to be identical.
2047
     *
2048
     * @ticket       29256
2049
     * @dataProvider data_primes_quotes_translation
2050
     */
2051 View Code Duplication
    function test_primes_quotes_translation( $input, $output ) 
2052
    {
2053
        add_filter('gettext_with_context', array( $this, 'filter_translate2' ), 10, 4);
2054
2055
        $result = wptexturize($input, true);
2056
2057
        remove_filter('gettext_with_context', array( $this, 'filter_translate2' ), 10, 4);
2058
        wptexturize('reset', true);
2059
2060
        return $this->assertEquals($output, $result);
2061
    }
2062
2063 View Code Duplication
    function filter_translate2( $translations, $text, $context, $domain ) 
2064
    {
2065
        switch ($text) {
0 ignored issues
show
introduced by
No space before closing parenthesis is prohibited
Loading history...
2066
        case '&#8211;' : 
2067
            return '!endash!';
2068
        case '&#8212;' : 
2069
            return '!emdash!';
2070
        case '&#8216;' : 
2071
            return '!q1!';
2072
        case '&#8217;' :
2073
            if ('apostrophe' == $context ) {
2074
                return '!apos!';
2075
            } else {
2076
                return '!q1!';
2077
            }
2078
        case '&#8220;' : 
2079
            return '!q2!';
2080
        case '&#8221;' : 
2081
            return '!q2!';
2082
        case '&#8242;' : 
2083
            return '!prime1!';
2084
        case '&#8243;' : 
2085
            return '!prime2!';
2086
        default : 
2087
            return $translations;
2088
        }
2089
    }
2090
2091
    function data_primes_quotes_translation() 
2092
    {
2093
        return array(
2094
         array(
2095
          "George's porch is 99' long.",
2096
          "George!apos!s porch is 99!prime1! long.",
2097
         ),
2098
         array(
2099
          'The best year "was that time in 2012" when everyone partied, he said.',
2100
          'The best year !q2!was that time in 2012!q2! when everyone partied, he said.',
2101
         ),
2102
         array(
2103
          "I need 4 x 20' = 80' of trim.", // Works only with a space before the = char.
2104
          "I need 4 x 20!prime1! = 80!prime1! of trim.",
2105
         ),
2106
         array(
2107
          '"Lorem ipsum dolor sit amet 1234"',
2108
          '!q2!Lorem ipsum dolor sit amet 1234!q2!',
2109
         ),
2110
         array(
2111
          "'Etiam eu egestas dui 1234'",
2112
          "!q1!Etiam eu egestas dui 1234!q1!",
2113
         ),
2114
         array(
2115
          'according to our source, "33% of all students scored less than 50" on the test.',
2116
          'according to our source, !q2!33% of all students scored less than 50!q2! on the test.',
2117
         ),
2118
         array(
2119
          "The doctor said, 'An average height is between 5' and 6' in study group 7'.  He then produced a 6' chart of averages.  A man of 7', incredibly, is very possible.",
2120
          "The doctor said, !q1!An average height is between 5!prime1! and 6!prime1! in study group 7!q1!.  He then produced a 6!prime1! chart of averages.  A man of 7!prime1!, incredibly, is very possible.",
2121
         ),
2122
         array(
2123
          'Pirates have voted on "The Expendables 3" with their clicks -- and it turns out the Sylvester Stallone-starrer hasn\'t been astoundingly popular among digital thieves, relatively speaking.
2124
2125
As of Sunday, 5.12 million people worldwide had pirated "Expendables 3" since a high-quality copy hit torrent-sharing sites July 23, according to piracy-tracking firm Excipio.
2126
2127
That likely contributed to the action movie\'s dismal box-office debut this weekend. But over the same July 23-Aug. 18 time period, the movie was No. 4 in downloads, after "Captain America: The Winter Soldier" (7.31 million), "Divergent" (6.29 million) and "The Amazing Spider-Man 2" (5.88 million). Moreover, that\'s despite "Expendables 3" becoming available more than three weeks prior to the film\'s U.S. theatrical debut.
2128
2129
String with a number followed by a single quote \'Expendables 3\' vestibulum in arcu mi.',
2130
2131
          'Pirates have voted on !q2!The Expendables 3!q2! with their clicks !emdash! and it turns out the Sylvester Stallone-starrer hasn!apos!t been astoundingly popular among digital thieves, relatively speaking.
2132
2133
As of Sunday, 5.12 million people worldwide had pirated !q2!Expendables 3!q2! since a high-quality copy hit torrent-sharing sites July 23, according to piracy-tracking firm Excipio.
2134
2135
That likely contributed to the action movie!apos!s dismal box-office debut this weekend. But over the same July 23-Aug. 18 time period, the movie was No. 4 in downloads, after !q2!Captain America: The Winter Soldier!q2! (7.31 million), !q2!Divergent!q2! (6.29 million) and !q2!The Amazing Spider-Man 2!q2! (5.88 million). Moreover, that!apos!s despite !q2!Expendables 3!q2! becoming available more than three weeks prior to the film!apos!s U.S. theatrical debut.
2136
2137
String with a number followed by a single quote !q1!Expendables 3!q1! vestibulum in arcu mi.',
2138
         ),
2139
        );
2140
    }
2141
2142
    /**
2143
     * Automated performance testing of the main regex.
2144
     *
2145
     * @dataProvider data_whole_posts
2146
     */
2147
    function test_pcre_performance( $input ) 
2148
    {
2149
        global $shortcode_tags;
2150
2151
        // With Shortcodes Disabled
2152
        $regex = _get_wptexturize_split_regex();
2153
        $result = benchmark_pcre_backtracking($regex, $input, 'split');
2154
        $this->assertLessThan(200, $result);
2155
2156
        // With Shortcodes Enabled
2157
        $shortcode_regex = _get_wptexturize_shortcode_regex(array_keys($shortcode_tags));
2158
        $regex = _get_wptexturize_split_regex($shortcode_regex);
2159
        $result = benchmark_pcre_backtracking($regex, $input, 'split');
2160
        return $this->assertLessThan(200, $result);
2161
    }
2162
2163
    /**
2164
     * Ensure that a trailing less-than symbol doesn't cause a PHP warning.
2165
     *
2166
     * @ticket 35864
2167
     */
2168
    function test_trailing_less_than() 
2169
    {
2170
        $this->assertEquals('F&#8211;oo<', wptexturize('F--oo<', true));
2171
    }
2172
2173
    function data_whole_posts() 
2174
    {
2175
        include_once DIR_TESTDATA . '/formatting/whole-posts.php';
2176
        return data_whole_posts();
2177
    }
2178
}