Repository navigation
Expand file tree
/
Copy pathwpTexturize.php
More file actions
2309 lines (2194 loc) · 61.7 KB
/
Copy pathwpTexturize.php
File metadata and controls
2309 lines (2194 loc) · 61.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @group formatting
*
* @covers ::wptexturize
*/
class Tests_Formatting_wpTexturize extends WP_UnitTestCase {
/**
* Tests smart dash conversion.
*/
public function test_dashes(): void {
$this->assertSame( 'Hey — boo?', wptexturize( 'Hey -- boo?' ) );
$this->assertSame( '<a href="http://xx--xx">Hey — boo?</a>', wptexturize( '<a href="http://xx--xx">Hey -- boo?</a>' ) );
}
/**
* Tests texturization is disabled inside certain HTML elements.
*/
public function test_disable(): void {
$this->assertSame( '<pre>---&</pre>', wptexturize( '<pre>---&</pre>' ) );
$this->assertSame( '<pre><code></code>--&</pre>', wptexturize( '<pre><code></code>--&</pre>' ) );
$this->assertSame( '<code>---&</code>', wptexturize( '<code>---&</code>' ) );
$this->assertSame( '<kbd>---&</kbd>', wptexturize( '<kbd>---&</kbd>' ) );
$this->assertSame( '<style>---&</style>', wptexturize( '<style>---&</style>' ) );
$this->assertSame( '<script>---&</script>', wptexturize( '<script>---&</script>' ) );
$this->assertSame( '<tt>---&</tt>', wptexturize( '<tt>---&</tt>' ) );
$this->assertSame( '<code>href="baba"</code> “baba”', wptexturize( '<code>href="baba"</code> "baba"' ) );
$enabled_tags_inside_code = '<code>curl -s <a href="http://x/">baba</a> | grep sfive | cut -d "\"" -f 10 > topmp3.txt</code>';
$this->assertSame( $enabled_tags_inside_code, wptexturize( $enabled_tags_inside_code ) );
$double_nest = '<pre>"baba"<code>"baba"<pre></pre></code>"baba"</pre>';
$this->assertSame( $double_nest, wptexturize( $double_nest ) );
$invalid_nest = '<pre></code>"baba"</pre>';
$this->assertSame( $invalid_nest, wptexturize( $invalid_nest ) );
}
/**
* Tests bracketed quote conversion.
*
* @ticket 1418
*/
public function test_bracketed_quotes_1418(): void {
$this->assertSame( '(“test”)', wptexturize( '("test")' ) );
$this->assertSame( '(‘test’)', wptexturize( "('test')" ) );
$this->assertSame( '(’twas)', wptexturize( "('twas)" ) );
}
/**
* Tests bracketed quote conversion with a specific example.
*
* @ticket 3810
*/
public function test_bracketed_quotes_3810(): void {
$this->assertSame( 'A dog (“Hubertus”) was sent out.', wptexturize( 'A dog ("Hubertus") was sent out.' ) );
}
/**
* Tests basic quote conversion (apostrophes, single quotes, double quotes).
*
* @ticket 4539
*/
public function test_basic_quotes(): void {
$this->assertSame( 'test’s', wptexturize( 'test\'s' ) );
$this->assertSame( '‘quoted’', wptexturize( '\'quoted\'' ) );
$this->assertSame( '“quoted”', wptexturize( '"quoted"' ) );
$this->assertSame( 'space before ‘quoted’ space after', wptexturize( 'space before \'quoted\' space after' ) );
$this->assertSame( 'space before “quoted” space after', wptexturize( 'space before "quoted" space after' ) );
$this->assertSame( '(‘quoted’)', wptexturize( '(\'quoted\')' ) );
$this->assertSame( '{“quoted”}', wptexturize( '{"quoted"}' ) );
$this->assertSame( '‘qu(ot)ed’', wptexturize( '\'qu(ot)ed\'' ) );
$this->assertSame( '“qu{ot}ed”', wptexturize( '"qu{ot}ed"' ) );
$this->assertSame( ' ‘test’s quoted’ ', wptexturize( ' \'test\'s quoted\' ' ) );
$this->assertSame( ' “test’s quoted” ', wptexturize( ' "test\'s quoted" ' ) );
}
/**
* Tests full sentences with unmatched single quotes.
*
* @ticket 4539
* @ticket 15241
*/
public function test_full_sentences_with_unmatched_single_quotes(): void {
$this->assertSame(
'That means every moment you’re working on something without it being in the public it’s actually dying.',
wptexturize( "That means every moment you're working on something without it being in the public it's actually dying." )
);
}
/**
* Tests quote conversion with various surrounding contexts.
*
* @ticket 4539
*/
public function test_quotes(): void {
$this->assertSame( '“Quoted String”', wptexturize( '"Quoted String"' ) );
// $this->assertSame( 'Here is “<a href="http://example.com">a test with a link</a>”', wptexturize( 'Here is "<a href="http://example.com">a test with a link</a>"' ) );
// $this->assertSame( 'Here is “<a href="http://example.com">a test with a link and a period</a>”.', wptexturize( 'Here is "<a href="http://example.com">a test with a link and a period</a>".' ) );
$this->assertSame( 'Here is “<a href="http://example.com">a test with a link</a>” and a space.', wptexturize( 'Here is "<a href="http://example.com">a test with a link</a>" and a space.' ) );
$this->assertSame( 'Here is “<a href="http://example.com">a test with a link</a> and some text quoted”', wptexturize( 'Here is "<a href="http://example.com">a test with a link</a> and some text quoted"' ) );
// $this->assertSame( 'Here is “<a href="http://example.com">a test with a link</a>”, and a comma.', wptexturize( 'Here is "<a href="http://example.com">a test with a link</a>", and a comma.' ) );
// $this->assertSame( 'Here is “<a href="http://example.com">a test with a link</a>”; and a semi-colon.', wptexturize( 'Here is "<a href="http://example.com">a test with a link</a>"; and a semi-colon.' ) );
// $this->assertSame( 'Here is “<a href="http://example.com">a test with a link</a>”- and a dash.', wptexturize( 'Here is "<a href="http://example.com">a test with a link</a>"- and a dash.' ) );
// $this->assertSame( 'Here is “<a href="http://example.com">a test with a link</a>”… and ellipses.', wptexturize( 'Here is "<a href="http://example.com">a test with a link</a>"... and ellipses.' ) );
// $this->assertSame( 'Here is “a test <a href="http://example.com">with a link</a>”.', wptexturize( 'Here is "a test <a href="http://example.com">with a link</a>".' ) );
// $this->assertSame( 'Here is “<a href="http://example.com">a test with a link</a>”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.' ) );
$this->assertSame( 'A test with a finishing number, “like 23”.', wptexturize( 'A test with a finishing number, "like 23".' ) );
$this->assertSame( 'A test with a number, “like 62”, is nice to have.', wptexturize( 'A test with a number, "like 62", is nice to have.' ) );
}
/**
* Tests quotes before an "s" (possessives and contractions).
*
* @ticket 4539
*/
public function test_quotes_before_s(): void {
$this->assertSame( 'test’s', wptexturize( "test's" ) );
$this->assertSame( '‘test’s', wptexturize( "'test's" ) );
$this->assertSame( '‘test’s’', wptexturize( "'test's'" ) );
$this->assertSame( '‘string’', wptexturize( "'string'" ) );
$this->assertSame( '‘string’s’', wptexturize( "'string's'" ) );
}
/**
* Tests quotes before numbers (year abbreviations, etc.).
*
* @ticket 4539
*/
public function test_quotes_before_numbers(): void {
$this->assertSame( 'Class of ’99', wptexturize( "Class of '99" ) );
$this->assertSame( 'Class of ’99’s', wptexturize( "Class of '99's" ) );
$this->assertSame( '‘Class of ’99’', wptexturize( "'Class of '99'" ) );
$this->assertSame( '‘Class of ’99’ ', wptexturize( "'Class of '99' " ) );
$this->assertSame( '‘Class of ’99’.', wptexturize( "'Class of '99'." ) );
$this->assertSame( '‘Class of ’99’, she said', wptexturize( "'Class of '99', she said" ) );
$this->assertSame( '‘Class of ’99’:', wptexturize( "'Class of '99':" ) );
$this->assertSame( '‘Class of ’99’;', wptexturize( "'Class of '99';" ) );
$this->assertSame( '‘Class of ’99’!', wptexturize( "'Class of '99'!" ) );
$this->assertSame( '‘Class of ’99’?', wptexturize( "'Class of '99'?" ) );
$this->assertSame( '‘Class of ’99’s’', wptexturize( "'Class of '99's'" ) );
$this->assertSame( '‘Class of ’99’s’', wptexturize( "'Class of '99’s'" ) );
$this->assertSame( '“Class of 99”', wptexturize( '"Class of 99"' ) );
$this->assertSame( '“Class of ’99”', wptexturize( "\"Class of '99\"" ) );
$this->assertSame( '{“Class of ’99”}', wptexturize( "{\"Class of '99\"}" ) );
$this->assertSame( ' “Class of ’99” ', wptexturize( " \"Class of '99\" " ) );
$this->assertSame( ' “Class of ’99”.', wptexturize( " \"Class of '99\"." ) );
$this->assertSame( ' “Class of ’99”, she said', wptexturize( " \"Class of '99\", she said" ) );
$this->assertSame( ' “Class of ’99”:', wptexturize( " \"Class of '99\":" ) );
$this->assertSame( ' “Class of ’99”;', wptexturize( " \"Class of '99\";" ) );
$this->assertSame( ' “Class of ’99”!', wptexturize( " \"Class of '99\"!" ) );
$this->assertSame( ' “Class of ’99”?', wptexturize( " \"Class of '99\"?" ) );
// Not a quotation, may be between two other quotations.
$this->assertSame( '}”Class of ’99″{', wptexturize( "}\"Class of '99\"{" ) );
}
/**
* Tests quotes after numbers.
*/
public function test_quotes_after_numbers(): void {
$this->assertSame( 'Class of ’99', wptexturize( "Class of '99" ) );
}
/**
* Tests quotes next to HTML tags.
*
* @ticket 4539
* @ticket 15241
*/
public function test_other_html(): void {
$this->assertSame( '‘<strong>', wptexturize( "'<strong>" ) );
// $this->assertSame( '‘<strong>Quoted Text</strong>’,', wptexturize( "'<strong>Quoted Text</strong>'," ) );
// $this->assertSame( '“<strong>Quoted Text</strong>”,', wptexturize( '"<strong>Quoted Text</strong>",' ) );
}
/**
* Tests multiplication sign (x between digits) conversion.
*/
public function test_x(): void {
$this->assertSame( '14×24', wptexturize( '14x24' ) );
}
/**
* Tests prime (minutes/feet) and double-prime (seconds/inches) conversion.
*/
public function test_minutes_seconds(): void {
$this->assertSame( '9′', wptexturize( '9\'' ) );
$this->assertSame( '9″', wptexturize( '9"' ) );
$this->assertSame( 'a 9′ b', wptexturize( 'a 9\' b' ) );
$this->assertSame( 'a 9″ b', wptexturize( 'a 9" b' ) );
$this->assertSame( '“a 9′ b”', wptexturize( '"a 9\' b"' ) );
$this->assertSame( '‘a 9″ b’', wptexturize( "'a 9\" b'" ) );
}
/**
* Tests quotes around numbers.
*
* @ticket 8775
*/
public function test_wptexturize_quotes_around_numbers(): void {
$this->assertSame( '“12345”', wptexturize( '"12345"' ) );
$this->assertSame( '‘12345’', wptexturize( '\'12345\'' ) );
$this->assertSame( '“a 9′ plus a ‘9’, maybe a 9′ ‘9’”', wptexturize( '"a 9\' plus a \'9\', maybe a 9\' \'9\'"' ) );
$this->assertSame( '<p>’99<br />‘123’<br />’tis<br />‘s’</p>', wptexturize( '<p>\'99<br />\'123\'<br />\'tis<br />\'s\'</p>' ) );
}
/**
* Tests HTML comments are not texturized.
*
* @ticket 8912
*/
public function test_wptexturize_html_comments(): void {
$this->assertSame( '<!--[if !IE]>--><!--<![endif]-->', wptexturize( '<!--[if !IE]>--><!--<![endif]-->' ) );
$this->assertSame( '<!--[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]-->' ) );
$this->assertSame( '<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>', wptexturize( '<ul><li>Hello.</li><!--<li>Goodbye.</li>--></ul>' ) );
}
/**
* Tests quote cuddling with HTML entities.
*
* @ticket 4539
* @ticket 15241
*/
public function test_entity_quote_cuddling(): void {
$this->assertSame( ' “Testing”', wptexturize( ' "Testing"' ) );
// $this->assertSame( '&“Testing”', wptexturize( '&"Testing"' ) );
}
/**
* Tests apostrophes before primes in version numbers.
*
* @ticket 22823
*/
public function test_apostrophes_before_primes(): void {
$this->assertSame( 'WordPress 3.5’s release date', wptexturize( "WordPress 3.5's release date" ) );
}
/**
* Tests spaces around hyphens and dashes.
*
* @ticket 23185
*/
public function test_spaces_around_hyphens(): void {
$nbsp = "\xC2\xA0";
$this->assertSame( ' – ', wptexturize( ' - ' ) );
$this->assertSame( ' – ', wptexturize( ' - ' ) );
$this->assertSame( ' – ', wptexturize( ' - ' ) );
$this->assertSame( ' – ', wptexturize( ' - ' ) );
$this->assertSame( "$nbsp–$nbsp", wptexturize( "$nbsp-$nbsp" ) );
$this->assertSame( " –$nbsp", wptexturize( " -$nbsp" ) );
$this->assertSame( "$nbsp– ", wptexturize( "$nbsp- " ) );
$this->assertSame( ' — ', wptexturize( ' -- ' ) );
$this->assertSame( ' — ', wptexturize( ' -- ' ) );
$this->assertSame( ' — ', wptexturize( ' -- ' ) );
$this->assertSame( ' — ', wptexturize( ' -- ' ) );
$this->assertSame( "$nbsp—$nbsp", wptexturize( "$nbsp--$nbsp" ) );
$this->assertSame( " —$nbsp", wptexturize( " --$nbsp" ) );
$this->assertSame( "$nbsp— ", wptexturize( "$nbsp-- " ) );
}
/**
* Tests hyphens and dashes at the start or end of strings.
*
* @ticket 31030
*/
public function test_hyphens_at_start_and_end(): void {
$this->assertSame( '– ', wptexturize( '- ' ) );
$this->assertSame( '– –', wptexturize( '- -' ) );
$this->assertSame( ' –', wptexturize( ' -' ) );
$this->assertSame( '— ', wptexturize( '-- ' ) );
$this->assertSame( '— —', wptexturize( '-- --' ) );
$this->assertSame( ' —', wptexturize( ' --' ) );
}
/**
* Test spaces around quotes.
*
* These should never happen, even if the desired output changes some day.
*
* @ticket 22692
*/
public function test_spaces_around_quotes_never(): void {
$nbsp = "\xC2\xA0";
$problem_input = "$nbsp\"A";
$problem_output = "$nbsp”A";
$this->assertNotSame( $problem_output, wptexturize( $problem_input ) );
}
/**
* Test spaces around quotes.
*
* These are desirable outputs for the current design.
*
* @ticket 22692
* @dataProvider data_spaces_around_quotes
*/
public function test_spaces_around_quotes( string $input, string $output ): void {
$this->assertSame( $output, wptexturize( $input ) );
}
/**
* Data provider for {@see self::test_spaces_around_quotes()}.
*
* @return list<array{0: string, 1: string}>
*/
public static function data_spaces_around_quotes(): array {
$nbsp = "\xC2\xA0";
$pi = "\xCE\xA0";
return array(
array(
"stop. $nbsp\"A quote after 2 spaces.\"",
"stop. $nbsp“A quote after 2 spaces.”",
),
array(
"stop.$nbsp$nbsp\"A quote after 2 spaces.\"",
"stop.$nbsp$nbsp“A quote after 2 spaces.”",
),
array(
"stop. $nbsp'A quote after 2 spaces.'",
"stop. $nbsp‘A quote after 2 spaces.’",
),
array(
"stop.$nbsp$nbsp'A quote after 2 spaces.'",
"stop.$nbsp$nbsp‘A quote after 2 spaces.’",
),
array(
'stop. "A quote after 2 spaces."',
'stop. “A quote after 2 spaces.”',
),
array(
'stop. "A quote after 2 spaces."',
'stop. “A quote after 2 spaces.”',
),
array(
"stop. 'A quote after 2 spaces.'",
'stop. ‘A quote after 2 spaces.’',
),
array(
"stop. 'A quote after 2 spaces.'",
'stop. ‘A quote after 2 spaces.’',
),
array(
"Contraction: $pi's",
"Contraction: $pi’s",
),
);
}
/**
* Apostrophe before a number always becomes ’ (apos);
*
* Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
*
* @ticket 22692
* @dataProvider data_apos_before_digits
*/
public function test_apos_before_digits( string $input, string $output ): void {
$this->assertSame( $output, wptexturize( $input ) );
}
/**
* Data provider for {@see self::test_apos_before_digits()}.
*
* @return list<array{0: string, 1: string}>
*/
public static function data_apos_before_digits(): array {
return array(
array(
"word '99 word",
'word ’99 word',
),
array(
"word'99 word",
'word’99 word',
),
array(
"word '99word",
'word ’99word',
),
array(
"word'99word",
'word’99word',
),
array(
"word '99’s word", // Appears as a separate but logically superfluous pattern in 3.8.
'word ’99’s word',
),
array(
"according to our source, '33 students scored less than 50' on the test.", // Apostrophes and primes have priority over quotes.
'according to our source, ’33 students scored less than 50′ on the test.',
),
);
}
/**
* Apostrophe after a space or ([{<" becomes ‘ (opening_single_quote)
*
* Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
*
* @ticket 22692
* @dataProvider data_opening_single_quote
*/
public function test_opening_single_quote( string $input, string $output ): void {
$this->assertSame( $output, wptexturize( $input ) );
}
/**
* Data provider for {@see self::test_opening_single_quote()}.
*
* @return list<array{0: string, 1: string}>
*/
public static function data_opening_single_quote(): array {
return array(
array(
"word 'word word",
'word ‘word word',
),
array(
"word ('word word",
'word (‘word word',
),
array(
"word ['word word",
'word [‘word word',
),
array(
"word <'word word", // Invalid HTML.
"word <'word word",
),
array(
"word <'word word", // Valid HTML input makes curly quotes.
'word <‘word word',
),
array(
"word {'word word",
'word {‘word word',
),
array(
"word \"'word word",
'word “‘word word', // Two opening quotes.
),
array(
"'word word",
'‘word word',
),
array(
"word('word word",
'word(‘word word',
),
array(
"word['word word",
'word[‘word word',
),
array(
"word<'word word",
"word<'word word",
),
array(
"word<'word word",
'word<‘word word',
),
array(
"word{'word word",
'word{‘word word',
),
array(
"word\"'word word",
'word”‘word word', // Closing quote, then opening quote.
),
array(
"word ' word word",
'word ‘ word word',
),
array(
"word (' word word",
'word (‘ word word',
),
array(
"word [' word word",
'word [‘ word word',
),
array(
"word <' word word",
"word <' word word",
),
array(
"word <' word word",
'word <‘ word word',
),
array(
"word {' word word",
'word {‘ word word',
),
array(
"word \"' word word",
'word “‘ word word', // Two opening quotes.
),
array(
"' word word",
'‘ word word',
),
array(
"word(' word word",
'word(‘ word word',
),
array(
"word[' word word",
'word[‘ word word',
),
array(
"word<' word word",
"word<' word word",
),
array(
"word<' word word",
'word<‘ word word',
),
array(
"word{' word word",
'word{‘ word word',
),
array(
"word\"' word word",
'word”‘ word word', // Closing quote, then opening quote.
),
);
}
/**
* Double quote after a number becomes ″ (double_prime)
*
* Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
*
* @ticket 22692
* @dataProvider data_double_prime
*/
public function test_double_prime( string $input, string $output ): void {
$this->assertSame( $output, wptexturize( $input ) );
}
/**
* Data provider for {@see self::test_double_prime()}.
*
* @return list<array{0: string, 1: string}>
*/
public static function data_double_prime(): array {
return array(
array(
'word 99" word',
'word 99″ word',
),
array(
'word 99"word',
'word 99″word',
),
array(
'word99" word',
'word99″ word',
),
array(
'word99"word',
'word99″word',
),
);
}
/**
* Apostrophe after a number becomes ′ (prime)
*
* Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
*
* @ticket 22692
* @dataProvider data_single_prime
*/
public function test_single_prime( string $input, string $output ): void {
$this->assertSame( $output, wptexturize( $input ) );
}
/**
* Data provider for {@see self::test_single_prime()}.
*
* @return list<array{0: string, 1: string}>
*/
public static function data_single_prime(): array {
return array(
array(
"word 99' word",
'word 99′ word',
),
array(
"word 99'word", // Not a prime anymore. Apostrophes get priority.
'word 99’word',
),
array(
"word99' word",
'word99′ word',
),
array(
"word99'word", // Not a prime anymore.
'word99’word',
),
);
}
/**
* Apostrophe "in a word" becomes ’ (apos)
*
* Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
*
* @ticket 22692
* @dataProvider data_contractions
*/
public function test_contractions( string $input, string $output ): void {
$this->assertSame( $output, wptexturize( $input ) );
}
/**
* Data provider for {@see self::test_contractions()}.
*
* @return list<array{0: string, 1: string}>
*/
public static function data_contractions(): array {
return array(
array(
"word word's word",
'word word’s word',
),
array(
"word'[ word", // Apostrophes are never followed by opening punctuation.
"word'[ word",
),
array(
"word'( word",
"word'( word",
),
array(
"word'{ word",
"word'{ word",
),
array(
"word'< word",
"word'< word",
),
array(
"word'< word", // Invalid HTML input does trigger the apos pattern.
'word’< word',
),
);
}
/**
* Double quote after a space or ([-{< becomes “ (opening_quote) if not followed by spaces
*
* Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
*
* @ticket 22692
* @dataProvider data_opening_quote
*/
public function test_opening_quote( string $input, string $output ): void {
$this->assertSame( $output, wptexturize( $input ) );
}
/**
* Data provider for {@see self::test_opening_quote()}.
*
* @return list<array{0: string, 1: string}>
*/
public static function data_opening_quote(): array {
return array(
array(
'word "word word',
'word “word word',
),
array(
'word ("word word',
'word (“word word',
),
array(
'word ["word word',
'word [“word word',
),
array(
'word <"word word', // Invalid HTML.
'word <"word word',
),
array(
'word <"word word',
'word <“word word',
),
array(
'word {"word word',
'word {“word word',
),
array(
'word -"word word',
'word -“word word',
),
array(
'word-"word word',
'word-“word word',
),
array(
'"word word',
'“word word',
),
array(
'word("word word',
'word(“word word',
),
array(
'word["word word',
'word[“word word',
),
array(
'word<"word word',
'word<"word word',
),
array(
'word<"word word',
'word<“word word',
),
array(
'word{"word word',
'word{“word word',
),
array(
'word "99 word',
'word “99 word',
),
);
}
/**
* Double quote becomes ” (closing_quote) unless it is already converted to double_prime or opening_quote.
*
* Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
*
* @ticket 22692
* @dataProvider data_closing_quote
*/
public function test_closing_quote( string $input, string $output ): void {
$this->assertSame( $output, wptexturize( $input ) );
}
/**
* Data provider for {@see self::test_closing_quote()}.
*
* @return list<array{0: string, 1: string}>
*/
public static function data_closing_quote(): array {
return array(
array(
'word word" word',
'word word” word',
),
array(
'word word") word',
'word word”) word',
),
array(
'word word"] word',
'word word”] word',
),
array(
'word word"} word',
'word word”} word',
),
array(
'word word"> word', // Invalid HTML input?
'word word”> word',
),
array(
'word word"> word', // Valid HTML should work.
'word word”> word',
),
array(
'word word"',
'word word”',
),
array(
'word word"word',
'word word”word',
),
array(
'word"word"word',
'word”word”word',
),
array(
'test sentence".',
'test sentence”.',
),
array(
'test sentence",',
'test sentence”,',
),
array(
'test sentence":',
'test sentence”:',
),
array(
'test sentence";',
'test sentence”;',
),
array(
'test sentence"!',
'test sentence”!',
),
array(
'test sentence"?',
'test sentence”?',
),
array(
'test sentence."',
'test sentence.”',
),
array(
'test sentence". word',
'test sentence”. word',
),
array(
'test sentence." word',
'test sentence.” word',
),
);
}
/**
* Test that single quotes followed by a space or .,-)}]> become ’ (closing_single_quote)
*
* Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
*
* @ticket 22692
* @dataProvider data_closing_single_quote
*/
public function test_closing_single_quote( string $input, string $output ): void {
$this->assertSame( $output, wptexturize( $input ) );
}
/**
* Data provider for {@see self::test_closing_single_quote()}.
*
* @return list<array{0: string, 1: string}>
*/
public static function data_closing_single_quote(): array {
return array(
array(
"word word' word",
'word word’ word',
),
array(
"word word'. word",
'word word’. word',
),
array(
"word word'.word",
'word word’.word',
),
array(
"word word', she said",
'word word’, she said',
),
array(
"word word': word",
'word word’: word',
),
array(
"word word'; word",
'word word’; word',
),
array(
"word word'! word",
'word word’! word',
),
array(
"word word'? word",
'word word’? word',
),
array(
"word word'- word",
'word word’- word',
),
array(
"word word') word",
'word word’) word',
),
array(
"word word'} word",
'word word’} word',
),
array(
"word word'] word",
'word word’] word',
),
array(
"word word'> word",
'word word’> word',
),
array(
"word word'",
'word word’',
),
array(
"test sentence'.",
'test sentence’.',
),
array(
"test sentence.'",
'test sentence.’',
),
array(
"test sentence'. word",
'test sentence’. word',
),
array(
"test sentence.' word",
'test sentence.’ word',
),
);
}
/**
* Tests multiplication.
*
* Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
*
* @ticket 22692
* @ticket 30445
* @dataProvider data_multiplication
*/
public function test_multiplication( string $input, string $output ): void {
$this->assertSame( $output, wptexturize( $input ) );
}
/**
* Data provider for {@see self::test_multiplication()}.
*
* @return list<array{0: string, 1: string}>
*/
public static function data_multiplication(): array {
return array(
array(
'9x9',
'9×9',
),
array(
'12x34',
'12×34',
),
array(
'-123x1=-123',
'-123×1=-123',
),
// @ticket 30445
array(
'-123x-1',
'-123x-1',
),
array(
'0.675x1=0.675',
'0.675×1=0.675',
),
array(
'9 x 9',
'9 x 9',
),
array(
'0x70',
'0x70',
),
array(
'3x2x1x0',
'3x2x1x0',
),
);
}
/**
* Test ampersands. & always becomes & unless it is followed by # or ;
*
* Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail.
*
* @ticket 22692
* @dataProvider data_ampersand